diff options
author | Daniel Stenberg <daniel@haxx.se> | 2010-09-06 00:02:54 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2010-09-06 00:02:54 +0200 |
commit | c6fa1952a14ba2fa14f4a3483f1f573560ef3133 (patch) | |
tree | 08c88f75e74eb8e8f969234000579e25e76584f2 /lib | |
parent | d47bd396cecd755c5f88d1e0c7b82a81bca8bd83 (diff) | |
download | curl-c6fa1952a14ba2fa14f4a3483f1f573560ef3133.tar.gz |
portabilty: use proper variable type to hold sockets
Curl_getconnectinfo() is changed to return a proper curl_socket_t for
the last socket so that it'll work more portably (and cause less
compiler warnings).
Diffstat (limited to 'lib')
-rw-r--r-- | lib/connect.c | 18 | ||||
-rw-r--r-- | lib/connect.h | 7 | ||||
-rw-r--r-- | lib/easy.c | 12 | ||||
-rw-r--r-- | lib/getinfo.c | 12 | ||||
-rw-r--r-- | lib/url.c | 7 |
5 files changed, 28 insertions, 28 deletions
diff --git a/lib/connect.c b/lib/connect.c index 771129b5a..172ccbbbf 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -1093,12 +1093,12 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */ * Used to extract socket and connectdata struct for the most recent * transfer on the given SessionHandle. * - * The socket 'long' will be -1 in case of failure! + * The returned socket will be CURL_SOCKET_BAD in case of failure! */ -CURLcode Curl_getconnectinfo(struct SessionHandle *data, - long *param_longp, - struct connectdata **connp) +curl_socket_t Curl_getconnectinfo(struct SessionHandle *data, + struct connectdata **connp) { + curl_socket_t sockfd; if((data->state.lastconnect != -1) && (data->state.connc->connects[data->state.lastconnect] != NULL)) { struct connectdata *c = @@ -1106,13 +1106,13 @@ CURLcode Curl_getconnectinfo(struct SessionHandle *data, if(connp) /* only store this if the caller cares for it */ *connp = c; - *param_longp = c->sock[FIRSTSOCKET]; + sockfd = c->sock[FIRSTSOCKET]; /* we have a socket connected, let's determine if the server shut down */ /* determine if ssl */ if(c->ssl[FIRSTSOCKET].use) { /* use the SSL context */ if(!Curl_ssl_check_cxn(c)) - *param_longp = -1; /* FIN received */ + return CURL_SOCKET_BAD; /* FIN received */ } /* Minix 3.1 doesn't support any flags on recv; just assume socket is OK */ #ifdef MSG_PEEK @@ -1121,13 +1121,13 @@ CURLcode Curl_getconnectinfo(struct SessionHandle *data, char buf; if(recv((RECV_TYPE_ARG1)c->sock[FIRSTSOCKET], (RECV_TYPE_ARG2)&buf, (RECV_TYPE_ARG3)1, (RECV_TYPE_ARG4)MSG_PEEK) == 0) { - *param_longp = -1; /* FIN received */ + return CURL_SOCKET_BAD; /* FIN received */ } } #endif } else - *param_longp = -1; + return CURL_SOCKET_BAD; - return CURLE_OK; + return sockfd; } diff --git a/lib/connect.h b/lib/connect.h index 57b1c2f2d..2c6b10a38 100644 --- a/lib/connect.h +++ b/lib/connect.h @@ -47,11 +47,10 @@ long Curl_timeleft(struct connectdata *conn, * Used to extract socket and connectdata struct for the most recent * transfer on the given SessionHandle. * - * The socket 'long' will be -1 in case of failure! + * The returned socket will be CURL_SOCKET_BAD in case of failure! */ -CURLcode Curl_getconnectinfo(struct SessionHandle *data, - long *param_longp, - struct connectdata **connp); +curl_socket_t Curl_getconnectinfo(struct SessionHandle *data, + struct connectdata **connp); #ifdef WIN32 /* When you run a program that uses the Windows Sockets API, you may diff --git a/lib/easy.c b/lib/easy.c index 637d99bb0..bebeeb17f 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -1072,9 +1072,6 @@ static CURLcode easy_connection(struct SessionHandle *data, curl_socket_t *sfd, struct connectdata **connp) { - CURLcode ret; - long sockfd; - if(data == NULL) return CURLE_BAD_FUNCTION_ARGUMENT; @@ -1084,18 +1081,13 @@ static CURLcode easy_connection(struct SessionHandle *data, return CURLE_UNSUPPORTED_PROTOCOL; } - ret = Curl_getconnectinfo(data, &sockfd, connp); - if(ret != CURLE_OK) - return ret; + *sfd = Curl_getconnectinfo(data, connp); - if(sockfd == -1) { + if(*sfd == CURL_SOCKET_BAD) { failf(data, "Failed to get recent socket"); return CURLE_UNSUPPORTED_PROTOCOL; } - *sfd = (curl_socket_t)sockfd; /* we know that this is actually a socket - descriptor so the typecast is fine here */ - return CURLE_OK; } diff --git a/lib/getinfo.c b/lib/getinfo.c index d5517e489..c00e675eb 100644 --- a/lib/getinfo.c +++ b/lib/getinfo.c @@ -83,6 +83,7 @@ CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...) char **param_charp=NULL; struct curl_slist **param_slistp=NULL; int type; + curl_socket_t sockfd; union { struct curl_certinfo * to_certinfo; @@ -219,7 +220,16 @@ CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...) *param_charp = data->state.most_recent_ftp_entrypath; break; case CURLINFO_LASTSOCKET: - (void)Curl_getconnectinfo(data, param_longp, NULL); + 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_longp = (long)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_longp = -1; break; case CURLINFO_REDIRECT_URL: /* Return the URL this request would have been redirected to if that @@ -2698,11 +2698,10 @@ static bool RTSPConnIsDead(struct connectdata *check) } else if (sval & CURL_CSELECT_IN) { /* readable with no error. could be closed or could be alive */ - long connectinfo = 0; - Curl_getconnectinfo(check->data, &connectinfo, &check); - if(connectinfo != -1) { + curl_socket_t connectinfo = + Curl_getconnectinfo(check->data, &check); + if(connectinfo != CURL_SOCKET_BAD) ret_val = FALSE; - } } return ret_val; |