curl-library
[PATCH] curl.h: added CURLINFO_LASTSOCKET_SAFE
From: Razvan Cojocaru <rcojocaru_at_bitdefender.com>
Date: Tue, 18 Aug 2015 12:51:35 +0300
Date: Tue, 18 Aug 2015 12:51:35 +0300
From: Razvan Cojocaru <rzvncj_at_gmail.com>
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_at_bitdefender.com>
---
include/curl/curl.h | 4 +++-
lib/getinfo.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/include/curl/curl.h b/include/curl/curl.h
index 64f9261..a455037 100644
--- a/include/curl/curl.h
+++ b/include/curl/curl.h
@@ -2088,6 +2088,7 @@ struct curl_tlssessioninfo {
#define CURLINFO_LONG 0x200000
#define CURLINFO_DOUBLE 0x300000
#define CURLINFO_SLIST 0x400000
+#define CURLINFO_SOCKET 0x500000
#define CURLINFO_MASK 0x0fffff
#define CURLINFO_TYPEMASK 0xf00000
@@ -2136,9 +2137,10 @@ typedef enum {
CURLINFO_LOCAL_IP = CURLINFO_STRING + 41,
CURLINFO_LOCAL_PORT = CURLINFO_LONG + 42,
CURLINFO_TLS_SESSION = CURLINFO_SLIST + 43,
+ CURLINFO_LASTSOCKET_SAFE = CURLINFO_SOCKET + 44,
/* Fill in new entries below here! */
- CURLINFO_LASTONE = 43
+ CURLINFO_LASTONE = 44
} CURLINFO;
/* CURLINFO_RESPONSE_CODE is the new name for the option previously known as
diff --git a/lib/getinfo.c b/lib/getinfo.c
index 910f520..47c1238 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_LASTSOCKET_SAFE:
+ 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;
}
--
1.7.9.5
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-08-18