summary refs log tree commit diff
path: root/pkgs/tools/networking/curl/connect-timeout.patch
blob: 339930e03f6b9ac88834c91cb5017bbd6c6ae8ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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) {