Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CURLINFO_ACTIVESOCKET doc is misleading #5299

Closed
jay opened this issue Apr 26, 2020 · 1 comment
Closed

CURLINFO_ACTIVESOCKET doc is misleading #5299

jay opened this issue Apr 26, 2020 · 1 comment

Comments

@jay
Copy link
Member

jay commented Apr 26, 2020

I did this

While investigating a mailing list question I observed that CURLINFO_ACTIVESOCKET does not actually return the active socket until after the transfer is done. This appears to be due to legacy reasons, since it is a replacement for CURLINFO_LASTSOCKET.

The socket can only be retrieved via ACTIVESOCKET after lastconnect is set, which only happens in multi_done:

curl/lib/multi.c

Lines 661 to 676 in b81e0b0

msnprintf(buffer, sizeof(buffer),
"Connection #%ld to host %s left intact",
conn->connection_id,
conn->bits.socksproxy ? conn->socks_proxy.host.dispname :
conn->bits.httpproxy ? conn->http_proxy.host.dispname :
conn->bits.conn_to_host ? conn->conn_to_host.dispname :
conn->host.dispname);
/* the connection is no longer in use by this transfer */
CONN_UNLOCK(data);
if(Curl_conncache_return_conn(data, conn)) {
/* remember the most recently used connection */
data->state.lastconnect = conn;
infof(data, "%s\n", buffer);
}
else
data->state.lastconnect = NULL;

curl/lib/connect.c

Lines 1373 to 1413 in b81e0b0

/*
* Used to extract socket and connectdata struct for the most recent
* transfer on the given Curl_easy.
*
* The returned socket will be CURL_SOCKET_BAD in case of failure!
*/
curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
struct connectdata **connp)
{
DEBUGASSERT(data);
/* this works for an easy handle:
* - that has been used for curl_easy_perform()
* - that is associated with a multi handle, and whose connection
* was detached with CURLOPT_CONNECT_ONLY
*/
if(data->state.lastconnect && (data->multi_easy || data->multi)) {
struct connectdata *c = data->state.lastconnect;
struct connfind find;
find.tofind = data->state.lastconnect;
find.found = FALSE;
Curl_conncache_foreach(data, data->multi_easy?
&data->multi_easy->conn_cache:
&data->multi->conn_cache, &find, conn_is_conn);
if(!find.found) {
data->state.lastconnect = NULL;
return CURL_SOCKET_BAD;
}
if(connp) {
/* only store this if the caller cares for it */
*connp = c;
c->data = data;
}
return c->sock[FIRSTSOCKET];
}
else
return CURL_SOCKET_BAD;
}

I expected the following

The documentation says "Pass a pointer to a curl_socket_t to receive the active socket used by this curl session." That implies the socket is available before the session is done.

curl/libcurl version

master branch

curl 7.70.0-DEV (i386-pc-win32) libcurl/7.70.0-DEV Schannel WinIDN
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS Debug IDN IPv6 Kerberos Largefile NTLM SPNEGO SSL SSPI UnixSockets

operating system

Windows 7

@bagder
Copy link
Member

bagder commented Apr 26, 2020

We can certainly improve the phrasing. We generally never promise any results reliably from curl_easy_getinfo until post-transfer.

bagder added a commit that referenced this issue Jun 4, 2020
bagder added a commit that referenced this issue Jun 4, 2020
@bagder bagder closed this as completed in a00668d Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants