diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/connect.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/lib/connect.c b/lib/connect.c index 92298d3fe..2330e6418 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -620,23 +620,6 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */ failf(data, "no address available"); return CURLE_COULDNT_CONNECT; } - /* create an IPv4 TCP socket */ - sockfd = socket(AF_INET, SOCK_STREAM, 0); - if(-1 == sockfd) { - failf(data, "couldn't create socket"); - return CURLE_COULDNT_CONNECT; /* big time error */ - } - - if(conn->data->set.device) { - /* user selected to bind the outgoing socket to a specified "device" - before doing connect */ - CURLcode res = bindlocal(conn, sockfd); - if(res) - return res; - } - - /* Convert socket to non-blocking type */ - Curl_nonblock(sockfd, TRUE); /* This is the loop that attempts to connect to all IP-addresses we know for the given host. One by one. */ @@ -645,6 +628,24 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */ aliasindex++) { struct sockaddr_in serv_addr; + /* create an IPv4 TCP socket */ + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if(-1 == sockfd) { + failf(data, "couldn't create socket"); + return CURLE_COULDNT_CONNECT; /* big time error */ + } + + if(conn->data->set.device) { + /* user selected to bind the outgoing socket to a specified "device" + before doing connect */ + CURLcode res = bindlocal(conn, sockfd); + if(res) + return res; + } + + /* Convert socket to non-blocking type */ + Curl_nonblock(sockfd, TRUE); + /* do this nasty work to do the connect */ memset((char *) &serv_addr, '\0', sizeof(serv_addr)); memcpy((char *)&(serv_addr.sin_addr), @@ -706,6 +707,7 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */ if(0 != rc) { /* get a new timeout for next attempt */ + sclose(sockfd); after = Curl_tvnow(); timeout_ms -= Curl_tvdiff(after, before); if(timeout_ms < 0) { @@ -717,9 +719,9 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */ } break; } + if(0 != rc) { /* no good connect was made */ - sclose(sockfd); *sockconn = -1; failf(data, "Connect failed"); return CURLE_COULDNT_CONNECT; |