Skip to content

CURLINFO_ACTIVESOCKET doc is misleading #5299

Description

@jay

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions