nixpkgs/pkgs/tools/networking/curl/connect-timeout.patch
Eelco Dolstra 6aae26a1d8 * Curl 7.18.1.
svn path=/nixpkgs/branches/stdenv-updates/; revision=11691
2008-04-23 09:30:09 +00:00

157 lines
4.5 KiB
Diff

diff -rc curl-7.18.1-orig/lib/connect.c curl-7.18.1/lib/connect.c
*** curl-7.18.1-orig/lib/connect.c 2008-02-07 23:25:04.000000000 +0100
--- curl-7.18.1/lib/connect.c 2008-04-23 11:25:30.000000000 +0200
***************
*** 99,105 ****
singleipconnect(struct connectdata *conn,
const Curl_addrinfo *ai, /* start connecting to this */
long timeout_ms,
! bool *connected);
/*
* Curl_timeleft() returns the amount of milliseconds left allowed for the
--- 99,106 ----
singleipconnect(struct connectdata *conn,
const Curl_addrinfo *ai, /* start connecting to this */
long timeout_ms,
! bool *connected,
! bool *timed_out);
/*
* Curl_timeleft() returns the amount of milliseconds left allowed for the
***************
*** 552,557 ****
--- 553,559 ----
{
curl_socket_t sockfd;
Curl_addrinfo *ai;
+ bool timed_out;
/* first close the failed socket */
sclose(conn->sock[sockindex]);
***************
*** 565,571 ****
ai = conn->ip_addr->ai_next;
while(ai) {
! sockfd = singleipconnect(conn, ai, 0L, connected);
if(sockfd != CURL_SOCKET_BAD) {
/* store the new socket descriptor */
conn->sock[sockindex] = sockfd;
--- 567,573 ----
ai = conn->ip_addr->ai_next;
while(ai) {
! sockfd = singleipconnect(conn, ai, 0L, connected, &timed_out);
if(sockfd != CURL_SOCKET_BAD) {
/* store the new socket descriptor */
conn->sock[sockindex] = sockfd;
***************
*** 720,726 ****
singleipconnect(struct connectdata *conn,
const Curl_addrinfo *ai,
long timeout_ms,
! bool *connected)
{
char addr_buf[128];
int rc;
--- 722,729 ----
singleipconnect(struct connectdata *conn,
const Curl_addrinfo *ai,
long timeout_ms,
! bool *connected,
! bool *timed_out)
{
char addr_buf[128];
int rc;
***************
*** 740,745 ****
--- 743,750 ----
struct curl_sockaddr *addr=(struct curl_sockaddr*)&addr_storage;
const void *iptoprint;
+ *timed_out = FALSE;
+
addr->family=ai->ai_family;
addr->socktype=conn->socktype;
addr->protocol=ai->ai_protocol;
***************
*** 841,848 ****
infof(data, "connected\n");
return sockfd;
}
! else if(WAITCONN_TIMEOUT == rc)
infof(data, "Timeout\n");
else {
data->state.os_errno = error;
infof(data, "%s\n", Curl_strerror(conn, error));
--- 846,855 ----
infof(data, "connected\n");
return sockfd;
}
! else if(WAITCONN_TIMEOUT == rc) {
! *timed_out = TRUE;
infof(data, "Timeout\n");
+ }
else {
data->state.os_errno = error;
infof(data, "%s\n", Curl_strerror(conn, error));
***************
*** 872,879 ****
int num_addr;
Curl_addrinfo *ai;
Curl_addrinfo *curr_addr;
- struct timeval after;
struct timeval before = Curl_tvnow();
/*************************************************************
--- 879,886 ----
int num_addr;
Curl_addrinfo *ai;
Curl_addrinfo *curr_addr;
+ bool timed_out;
struct timeval before = Curl_tvnow();
/*************************************************************
***************
*** 915,933 ****
curr_addr = curr_addr->ai_next, aliasindex++) {
/* start connecting to the IP curr_addr points to */
! sockfd = singleipconnect(conn, curr_addr, timeout_per_addr, connected);
if(sockfd != CURL_SOCKET_BAD)
break;
! /* get a new timeout for next attempt */
! after = Curl_tvnow();
! timeout_ms -= Curl_tvdiff(after, before);
! if(timeout_ms < 0) {
failf(data, "connect() timed out!");
return CURLE_OPERATION_TIMEDOUT;
}
- before = after;
} /* end of connect-to-each-address loop */
if(sockfd == CURL_SOCKET_BAD) {
--- 922,938 ----
curr_addr = curr_addr->ai_next, aliasindex++) {
/* start connecting to the IP curr_addr points to */
! sockfd = singleipconnect(conn, curr_addr, timeout_per_addr, connected, &timed_out);
if(sockfd != CURL_SOCKET_BAD)
break;
! /* if this is the last address and it timed out, propagate the
! timeout to the caller */
! if(!curr_addr->ai_next && timed_out) {
failf(data, "connect() timed out!");
return CURLE_OPERATION_TIMEDOUT;
}
} /* end of connect-to-each-address loop */
if(sockfd == CURL_SOCKET_BAD) {