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).
This commit is contained in:
Daniel Stenberg
2010-09-06 00:02:54 +02:00
parent d47bd396ce
commit c6fa1952a1
5 changed files with 28 additions and 28 deletions

View File

@@ -1093,12 +1093,12 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
* Used to extract socket and connectdata struct for the most recent * Used to extract socket and connectdata struct for the most recent
* transfer on the given SessionHandle. * 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, curl_socket_t Curl_getconnectinfo(struct SessionHandle *data,
long *param_longp, struct connectdata **connp)
struct connectdata **connp)
{ {
curl_socket_t sockfd;
if((data->state.lastconnect != -1) && if((data->state.lastconnect != -1) &&
(data->state.connc->connects[data->state.lastconnect] != NULL)) { (data->state.connc->connects[data->state.lastconnect] != NULL)) {
struct connectdata *c = struct connectdata *c =
@@ -1106,13 +1106,13 @@ CURLcode Curl_getconnectinfo(struct SessionHandle *data,
if(connp) if(connp)
/* only store this if the caller cares for it */ /* only store this if the caller cares for it */
*connp = c; *connp = c;
*param_longp = c->sock[FIRSTSOCKET]; sockfd = c->sock[FIRSTSOCKET];
/* we have a socket connected, let's determine if the server shut down */ /* we have a socket connected, let's determine if the server shut down */
/* determine if ssl */ /* determine if ssl */
if(c->ssl[FIRSTSOCKET].use) { if(c->ssl[FIRSTSOCKET].use) {
/* use the SSL context */ /* use the SSL context */
if(!Curl_ssl_check_cxn(c)) 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 */ /* Minix 3.1 doesn't support any flags on recv; just assume socket is OK */
#ifdef MSG_PEEK #ifdef MSG_PEEK
@@ -1121,13 +1121,13 @@ CURLcode Curl_getconnectinfo(struct SessionHandle *data,
char buf; char buf;
if(recv((RECV_TYPE_ARG1)c->sock[FIRSTSOCKET], (RECV_TYPE_ARG2)&buf, if(recv((RECV_TYPE_ARG1)c->sock[FIRSTSOCKET], (RECV_TYPE_ARG2)&buf,
(RECV_TYPE_ARG3)1, (RECV_TYPE_ARG4)MSG_PEEK) == 0) { (RECV_TYPE_ARG3)1, (RECV_TYPE_ARG4)MSG_PEEK) == 0) {
*param_longp = -1; /* FIN received */ return CURL_SOCKET_BAD; /* FIN received */
} }
} }
#endif #endif
} }
else else
*param_longp = -1; return CURL_SOCKET_BAD;
return CURLE_OK; return sockfd;
} }

View File

@@ -47,11 +47,10 @@ long Curl_timeleft(struct connectdata *conn,
* Used to extract socket and connectdata struct for the most recent * Used to extract socket and connectdata struct for the most recent
* transfer on the given SessionHandle. * 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, curl_socket_t Curl_getconnectinfo(struct SessionHandle *data,
long *param_longp, struct connectdata **connp);
struct connectdata **connp);
#ifdef WIN32 #ifdef WIN32
/* When you run a program that uses the Windows Sockets API, you may /* When you run a program that uses the Windows Sockets API, you may

View File

@@ -1072,9 +1072,6 @@ static CURLcode easy_connection(struct SessionHandle *data,
curl_socket_t *sfd, curl_socket_t *sfd,
struct connectdata **connp) struct connectdata **connp)
{ {
CURLcode ret;
long sockfd;
if(data == NULL) if(data == NULL)
return CURLE_BAD_FUNCTION_ARGUMENT; return CURLE_BAD_FUNCTION_ARGUMENT;
@@ -1084,18 +1081,13 @@ static CURLcode easy_connection(struct SessionHandle *data,
return CURLE_UNSUPPORTED_PROTOCOL; return CURLE_UNSUPPORTED_PROTOCOL;
} }
ret = Curl_getconnectinfo(data, &sockfd, connp); *sfd = Curl_getconnectinfo(data, connp);
if(ret != CURLE_OK)
return ret;
if(sockfd == -1) { if(*sfd == CURL_SOCKET_BAD) {
failf(data, "Failed to get recent socket"); failf(data, "Failed to get recent socket");
return CURLE_UNSUPPORTED_PROTOCOL; 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; return CURLE_OK;
} }

View File

@@ -83,6 +83,7 @@ CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
char **param_charp=NULL; char **param_charp=NULL;
struct curl_slist **param_slistp=NULL; struct curl_slist **param_slistp=NULL;
int type; int type;
curl_socket_t sockfd;
union { union {
struct curl_certinfo * to_certinfo; 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; *param_charp = data->state.most_recent_ftp_entrypath;
break; break;
case CURLINFO_LASTSOCKET: 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; break;
case CURLINFO_REDIRECT_URL: case CURLINFO_REDIRECT_URL:
/* Return the URL this request would have been redirected to if that /* Return the URL this request would have been redirected to if that

View File

@@ -2698,11 +2698,10 @@ static bool RTSPConnIsDead(struct connectdata *check)
} }
else if (sval & CURL_CSELECT_IN) { else if (sval & CURL_CSELECT_IN) {
/* readable with no error. could be closed or could be alive */ /* readable with no error. could be closed or could be alive */
long connectinfo = 0; curl_socket_t connectinfo =
Curl_getconnectinfo(check->data, &connectinfo, &check); Curl_getconnectinfo(check->data, &check);
if(connectinfo != -1) { if(connectinfo != CURL_SOCKET_BAD)
ret_val = FALSE; ret_val = FALSE;
}
} }
return ret_val; return ret_val;