]> granicus.if.org Git - curl/commitdiff
Yang Tse pointed out a few remaining quirks from my timeout refactoring from
authorDaniel Stenberg <daniel@haxx.se>
Mon, 11 Feb 2008 22:03:31 +0000 (22:03 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 11 Feb 2008 22:03:31 +0000 (22:03 +0000)
Feb 7 that didn't abort properly on timeouts. These are actually old
problems but now they should be fixed.

CHANGES
lib/qssl.c
lib/socks.c
lib/tftp.c

diff --git a/CHANGES b/CHANGES
index 3ac56fce755134ec325981d42234315fe47d1f83..c95b515d5cd60e198459286b102c34255a53f7ad 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,11 @@
 
                                   Changelog
 
+Daniel S (11 Feb 2008)
+- Yang Tse pointed out a few remaining quirks from my timeout refactoring from
+  Feb 7 that didn't abort properly on timeouts. These are actually old
+  problems but now they should be fixed.
+
 Yang Tse (10 Feb 2008)
 - Bug report #1888932 (http://curl.haxx.se/bug/view.cgi?id=1888932) points out
   and provides test program that demonstrates that libcurl might not set error
index e65a0e2f6745a014a8332618c2582f188d18b8bb..d89f01730443c7f6b315bc4fb8139aef5b1eb1a2 100644 (file)
@@ -175,8 +175,13 @@ static CURLcode Curl_qsossl_handshake(struct connectdata * conn, int sockindex)
   /* figure out how long time we should wait at maximum */
   timeout_ms = Curl_timeleft(conn, NULL, TRUE);
 
-  /* SSL_Handshake() timeout resolution is second, so round up. */
+  if(timeout_ms < 0) {
+    /* time-out, bail out, go home */
+    failf(data, "Connection time-out");
+    return CURLE_OPERATION_TIMEDOUT;
+  }
 
+  /* SSL_Handshake() timeout resolution is second, so round up. */
   h->timeout = (timeout_ms + 1000 - 1) / 1000;
 
   /* Set-up protocol. */
@@ -429,7 +434,7 @@ ssize_t Curl_qsossl_recv(struct connectdata * conn, int num, char * buf,
     case SSL_ERROR_IO:
       switch (errno) {
       case EWOULDBLOCK:
-       *wouldblock = TRUE;
+        *wouldblock = TRUE;
         return -1;
         }
 
index b78a04a455cd992f0294a66a0aa116ebb26646d4..06a513e805df66e34a513233dcd6dfc225210e34 100644 (file)
@@ -140,6 +140,12 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
   /* get timeout */
   timeout = Curl_timeleft(conn, NULL, TRUE);
 
+  if(timeout < 0) {
+    /* time-out, bail out, go home */
+    failf(data, "Connection time-out");
+    return CURLE_OPERATION_TIMEDOUT;
+  }
+
   Curl_nonblock(sock, FALSE);
 
   /*
@@ -394,6 +400,12 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
   /* get timeout */
   timeout = Curl_timeleft(conn, NULL, TRUE);
 
+  if(timeout < 0) {
+    /* time-out, bail out, go home */
+    failf(data, "Connection time-out");
+    return CURLE_OPERATION_TIMEDOUT;
+  }
+
   Curl_nonblock(sock, TRUE);
 
   /* wait until socket gets connected */
index 8b3656cdf7c1dc7c7bae785b56ab83108f3f6e6f..ffd668c19c30df27fe44e418ce92356966c9e11d 100644 (file)
@@ -189,16 +189,24 @@ const struct Curl_handler Curl_handler_tftp = {
  *
  *
  **********************************************************/
-static void tftp_set_timeouts(tftp_state_data_t *state)
+static CURLcode tftp_set_timeouts(tftp_state_data_t *state)
 {
   time_t maxtime, timeout;
   long timeout_ms;
 
   time(&state->start_time);
 
+  /* Compute drop-dead time */
+  timeout_ms = Curl_timeleft(state->conn, NULL, TRUE);
+
+  if(timeout_ms < 0) {
+    /* time-out, bail out, go home */
+    failf(state->conn->data, "Connection time-out");
+    return CURLE_OPERATION_TIMEDOUT;
+  }
+
   if(state->state == TFTP_STATE_START) {
-    /* Compute drop-dead time */
-    timeout_ms = Curl_timeleft(state->conn, NULL, TRUE);
+
     maxtime = (time_t)(timeout_ms + 500) / 1000;
     state->max_time = state->start_time+maxtime;
 
@@ -219,8 +227,6 @@ static void tftp_set_timeouts(tftp_state_data_t *state)
 
   }
   else {
-    /* Compute drop-dead time */
-    timeout_ms = Curl_timeleft(state->conn, NULL, TRUE);
     if(timeout_ms > 0)
       maxtime = (time_t)(timeout_ms + 500) / 1000;
     else
@@ -250,6 +256,8 @@ static void tftp_set_timeouts(tftp_state_data_t *state)
        "set timeouts for state %d; Total %d, retry %d maxtry %d\n",
         state->state, (state->max_time-state->start_time),
         state->retry_time, state->retry_max);
+
+  return CURLE_OK;
 }
 
 /**********************************************************
@@ -343,13 +351,17 @@ static CURLcode tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
   case TFTP_EVENT_ACK: /* Connected for transmit */
     infof(data, "%s\n", "Connected for transmit");
     state->state = TFTP_STATE_TX;
-    tftp_set_timeouts(state);
+    res = tftp_set_timeouts(state);
+    if(res)
+      break;
     return tftp_tx(state, event);
 
   case TFTP_EVENT_DATA: /* connected for receive */
     infof(data, "%s\n", "Connected for receive");
     state->state = TFTP_STATE_RX;
-    tftp_set_timeouts(state);
+    res = tftp_set_timeouts(state);
+    if(res)
+      break;
     return tftp_rx(state, event);
 
   case TFTP_EVENT_ERROR: