diff options
author | Daniel Stenberg <daniel@haxx.se> | 2003-10-15 11:42:57 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2003-10-15 11:42:57 +0000 |
commit | a9af971c595fbc8b452b0cb5b51d080a314d30ac (patch) | |
tree | 365c532ce1596c08bfebc1abc2c037c2dc1aff18 | |
parent | 171229e12267449dcd300354902c4aa47e2ee835 (diff) |
Avoid doing getsockopt() on Windows to verify connects. It seems that this
hogs Windows machines when libcurl is being used multi-threaded (with > ~50
threads). Andrew Fuller helped us verify and test this.
According to a MSDN web page on connect(), it returns 0 when the connect
is done and thus we don't need the getsockopt() call anyway on Windows.
-rw-r--r-- | lib/connect.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/lib/connect.c b/lib/connect.c index 69d0dd308..bf27ba29b 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -353,18 +353,27 @@ static CURLcode bindlocal(struct connectdata *conn, return CURLE_HTTP_PORT_FAILED; } - -static -int socketerror(int sockfd) +/* + * verifyconnect() returns TRUE if the connect really has happened. + */ +static bool verifyconnect(int sockfd) { +#if defined(SO_ERROR) && !defined(WIN32) int err = 0; socklen_t errSize = sizeof(err); -#ifdef SO_ERROR if( -1 == getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (void *)&err, &errSize)) err = Curl_ourerrno(); + + if ((0 == err) || (EISCONN == err)) + /* we are connected, awesome! */ + return TRUE; + + /* This wasn't a successful connect */ + return FALSE; +#else + return TRUE; #endif - return err; } /* @@ -415,14 +424,13 @@ CURLcode Curl_is_connected(struct connectdata *conn, rc = waitconnect(sockfd, 0); if(0 == rc) { - int err = socketerror(sockfd); - if ((0 == err) || (EISCONN == err)) { + if (verifyconnect(sockfd)) { /* we are connected, awesome! */ *connected = TRUE; return CURLE_OK; } /* nope, not connected for real */ - failf(data, "Connection failed, socket error: %d", err); + failf(data, "Connection failed"); return CURLE_COULDNT_CONNECT; } else if(1 != rc) { @@ -568,10 +576,7 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */ if(0 == rc) { /* we might be connected, if the socket says it is OK! Ask it! */ - int err; - - err = socketerror(sockfd); - if ((0 == err) || (EISCONN == err)) { + if(verifyconnect(sockfd)) { /* we are connected, awesome! */ *connected = TRUE; /* this is truly a connect */ break; @@ -695,8 +700,7 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */ } if(0 == rc) { - int err = socketerror(sockfd); - if ((0 == err) || (EISCONN == err)) { + if (verifyconnect(sockfd)) { /* we are connected, awesome! */ *connected = TRUE; /* this is a true connect */ break; |