diff options
author | Razvan Cojocaru <rcojocaru@bitdefender.com> | 2015-08-21 10:29:05 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2015-08-24 12:34:17 +0200 |
commit | 62f306ff34f569020ce54451da7c841d162710ac (patch) | |
tree | 573f8b2cb9fdc34e6d06d35ac0fb8c90f1b4b6d9 /lib/getinfo.c | |
parent | 36f6f6f4f2331dbd276a8455ecdafc16aceecb80 (diff) | |
download | curl-62f306ff34f569020ce54451da7c841d162710ac.tar.gz |
getinfo: added CURLINFO_ACTIVESOCKET
This patch addresses known bug #76, where on 64-bit Windows SOCKET is 64
bits wide, but long is only 32, making CURLINFO_LASTSOCKET unreliable.
Signed-off-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
Diffstat (limited to 'lib/getinfo.c')
-rw-r--r-- | lib/getinfo.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/getinfo.c b/lib/getinfo.c index 910f520ed..90ea45424 100644 --- a/lib/getinfo.c +++ b/lib/getinfo.c @@ -334,6 +334,31 @@ static CURLcode getinfo_slist(struct SessionHandle *data, CURLINFO info, return CURLE_OK; } +static CURLcode getinfo_socket(struct SessionHandle *data, CURLINFO info, + curl_socket_t *param_socketp) +{ + curl_socket_t sockfd; + + switch(info) { + case CURLINFO_ACTIVESOCKET: + sockfd = Curl_getconnectinfo(data, NULL); + + /* note: this is not a good conversion for systems with 64 bit sockets and + 32 bit longs */ + if(sockfd != CURL_SOCKET_BAD) + *param_socketp = sockfd; + else + /* this interface is documented to return -1 in case of badness, which + may not be the same as the CURL_SOCKET_BAD value */ + *param_socketp = -1; + break; + default: + return CURLE_BAD_FUNCTION_ARGUMENT; + } + + return CURLE_OK; +} + CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...) { va_list arg; @@ -341,6 +366,7 @@ CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...) double *param_doublep = NULL; char **param_charp = NULL; struct curl_slist **param_slistp = NULL; + curl_socket_t *param_socketp = NULL; int type; /* default return code is to error out! */ CURLcode result = CURLE_BAD_FUNCTION_ARGUMENT; @@ -372,6 +398,11 @@ CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...) if(param_slistp) result = getinfo_slist(data, info, param_slistp); break; + case CURLINFO_SOCKET: + param_socketp = va_arg(arg, curl_socket_t *); + if(param_socketp) + result = getinfo_socket(data, info, param_socketp); + break; default: break; } |