]> granicus.if.org Git - curl/commitdiff
- Michael Wallner provided a patch that adds support for CURLOPT_TIMEOUT_MS
authorDaniel Stenberg <daniel@haxx.se>
Mon, 5 Feb 2007 22:51:32 +0000 (22:51 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 5 Feb 2007 22:51:32 +0000 (22:51 +0000)
  and CURLOPT_CONNECTTIMEOUT_MS that, as their names should hint, do the
  timeouts with millisecond resolution instead. The only restriction to that
  is the alarm() (sometimes) used to abort name resolves as that uses full
  seconds. I fixed the FTP response timeout part of the patch.

  Internally we now count and keep the timeouts in milliseconds but it also
  means we multiply set timeouts with 1000. The effect of this is that no
  timeout can be set to more than 2^31 milliseconds (on 32 bit systems), which
  equals 24.86 days.  We probably couldn't before either since the code did
  *1000 on the timeout values on several places already.

17 files changed:
CHANGES
RELEASE-NOTES
docs/libcurl/curl_easy_setopt.3
include/curl/curl.h
lib/connect.c
lib/ftp.c
lib/gtls.c
lib/hostares.c
lib/hostthre.c
lib/http.c
lib/socks.c
lib/ssluse.c
lib/telnet.c
lib/tftp.c
lib/transfer.c
lib/url.c
lib/urldata.h

diff --git a/CHANGES b/CHANGES
index ea6e5e5566cf233177937fe1a2ae140b7d778386..33ae1ab3e8e52cacbf2a1ac5bcdadf14c77cca11 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,19 @@
 
                                   Changelog
 
+Daniel (5 February 2007)
+- Michael Wallner added support for CURLOPT_TIMEOUT_MS and
+  CURLOPT_CONNECTTIMEOUT_MS that, as their names suggest, do the timeouts with
+  millisecond resolution. The only restriction to that is the alarm()
+  (sometimes) used to abort name resolves as that uses full seconds. I fixed
+  the FTP response timeout part of the patch.
+
+  Internally we now count and keep the timeouts in milliseconds but it also
+  means we multiply set timeouts with 1000. The effect of this is that no
+  timeout can be set to more than 2^31 milliseconds (on 32 bit systems), which
+  equals 24.86 days.  We probably couldn't before either since the code did
+  *1000 on the timeout values on several places already.
+
 Daniel (3 February 2007)
 - Yang Tse fixed the cookie expiry date in several test cases that started to
   fail since they used "1 feb 2007"...
index 3c5e860ad98ccd04602754bed04e7644a51504ae..bbe226975b98d1caa5d31f9c7bbadcdf9e0e715b 100644 (file)
@@ -11,7 +11,7 @@ Curl and libcurl 7.16.2
 
 This release includes the following changes:
  
- o
+ o Added CURLOPT_TIMEOUT_MS and CURLOPT_CONNECTTIMEOUT_MS
 
 This release includes the following bugfixes:
 
@@ -33,6 +33,6 @@ New curl mirrors:
 This release would not have looked like this without help, code, reports and
 advice from friends like these:
 
- Yang Tse, Manfred Schwarb
+ Yang Tse, Manfred Schwarb, Michael Wallner
 
         Thanks! (and sorry if I forgot to mention someone)
index 08e7405e225c7f922e284459adb5b03249377504..23d012de9818238319529cb1b0b0bc93a03cd949 100644 (file)
@@ -21,7 +21,7 @@
 .\" * $Id$
 .\" **************************************************************************
 .\"
-.TH curl_easy_setopt 3 "2 Nov 2006" "libcurl 7.16.1" "libcurl Manual"
+.TH curl_easy_setopt 3 "5 Feb 2007" "libcurl 7.16.2" "libcurl Manual"
 .SH NAME
 curl_easy_setopt \- set options for a curl easy handle
 .SH SYNOPSIS
@@ -1078,6 +1078,10 @@ SIGALRM to enable time-outing system calls.
 
 In unix-like systems, this might cause signals to be used unless
 \fICURLOPT_NOSIGNAL\fP is set.
+.IP CURLOPT_TIMEOUT_MS
+Like \fICURLOPT_TIMEOUT\fP but takes number of milliseconds instead. If
+libcurl is built to use the standard system name resolver, that part will
+still use full-second resolution for timeouts. (Added in 7.16.2)
 .IP CURLOPT_LOW_SPEED_LIMIT
 Pass a long as parameter. It contains the transfer speed in bytes per second
 that the transfer should be below during \fICURLOPT_LOW_SPEED_TIME\fP seconds
@@ -1135,6 +1139,10 @@ timeouts). See also the \fICURLOPT_TIMEOUT\fP option.
 
 In unix-like systems, this might cause signals to be used unless
 \fICURLOPT_NOSIGNAL\fP is set.
+.IP CURLOPT_CONNECTTIMEOUT_MS
+Like \fICURLOPT_CONNECTTIMEOUT\fP but takes number of milliseconds instead. If
+libcurl is built to use the standard system name resolver, that part will
+still use full-second resolution for timeouts. (Added in 7.16.2)
 .IP CURLOPT_IPRESOLVE
 Allows an application to select what kind of IP addresses to use when
 resolving host names. This is only interesting when using host names that
index f41067614e651690e135a4016cadb240906a028a..2c79f7daced69e35c948c24ca46ab45fd1509d74 100644 (file)
@@ -1054,6 +1054,10 @@ typedef enum {
   /* Send CCC (Clear Command Channel) after authentication */
   CINIT(FTP_SSL_CCC, LONG, 154),
 
+  /* Same as TIMEOUT and CONNECTTIMEOUT, but with ms resolution */
+  CINIT(TIMEOUT_MS, LONG, 155),
+  CINIT(CONNECTTIMEOUT_MS, LONG, 156),
+
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
 
index 2b38972040645abacc2149ab28074c80e446df97..37db6e2281e0dd726d8bd2a9c1e351eb4db0fbac 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -558,15 +558,15 @@ CURLcode Curl_is_connected(struct connectdata *conn,
   /* subtract the most strict timeout of the ones */
   if(data->set.timeout && data->set.connecttimeout) {
     if (data->set.timeout < data->set.connecttimeout)
-      allow_total = allow = data->set.timeout*1000;
+      allow_total = allow = data->set.timeout;
     else
-      allow = data->set.connecttimeout*1000;
+      allow = data->set.connecttimeout;
   }
   else if(data->set.timeout) {
-    allow_total = allow = data->set.timeout*1000;
+    allow_total = allow = data->set.timeout;
   }
   else if(data->set.connecttimeout) {
-    allow = data->set.connecttimeout*1000;
+    allow = data->set.connecttimeout;
   }
 
   if(has_passed > allow ) {
@@ -826,14 +826,14 @@ CURLcode Curl_connecthost(struct connectdata *conn,  /* context */
     /* get the most strict timeout of the ones converted to milliseconds */
     if(data->set.timeout && data->set.connecttimeout) {
       if (data->set.timeout < data->set.connecttimeout)
-        timeout_ms = data->set.timeout*1000;
+        timeout_ms = data->set.timeout;
       else
-        timeout_ms = data->set.connecttimeout*1000;
+        timeout_ms = data->set.connecttimeout;
     }
     else if(data->set.timeout)
-      timeout_ms = data->set.timeout*1000;
+      timeout_ms = data->set.timeout;
     else
-      timeout_ms = data->set.connecttimeout*1000;
+      timeout_ms = data->set.connecttimeout;
 
     /* subtract the passed time */
     timeout_ms -= has_passed;
index 479eeffe342047bd6c2a428cfc0d3949f7e53283..29004ead3171db321e0fa1a872d07bef9eaa7e3c 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -184,7 +184,7 @@ static CURLcode AllowServerConnect(struct connectdata *conn)
   struct SessionHandle *data = conn->data;
   curl_socket_t sock = conn->sock[SECONDARYSOCKET];
   struct timeval now = Curl_tvnow();
-  long timespent = Curl_tvdiff(Curl_tvnow(), now)/1000;
+  long timespent = Curl_tvdiff(Curl_tvnow(), now);
   long timeout = data->set.connecttimeout?data->set.connecttimeout:
     (data->set.timeout?data->set.timeout: 0);
 
@@ -198,7 +198,7 @@ static CURLcode AllowServerConnect(struct connectdata *conn)
 
   /* We allow the server 60 seconds to connect to us, or a custom timeout.
      Note the typecast here. */
-  timeout_ms = (timeout?(int)timeout:60) * 1000;
+  timeout_ms = (timeout?(int)timeout:60000);
 
   switch (Curl_select(sock, CURL_SOCKET_BAD, timeout_ms)) {
   case -1: /* error */
@@ -444,7 +444,7 @@ CURLcode Curl_GetFTPResponse(ssize_t *nreadp, /* return number of bytes read */
   bool keepon=TRUE;
   ssize_t gotbytes;
   char *ptr;
-  long timeout;              /* timeout in seconds */
+  long timeout;              /* timeout in milliseconds */
   int interval_ms;
   struct SessionHandle *data = conn->data;
   char *line_start;
@@ -473,16 +473,16 @@ CURLcode Curl_GetFTPResponse(ssize_t *nreadp, /* return number of bytes read */
          the response for any given ftp response, not for the time
          from connect to the given ftp response. */
       timeout = data->set.ftp_response_timeout - /* timeout time */
-        Curl_tvdiff(Curl_tvnow(), now)/1000; /* spent time */
+        Curl_tvdiff(Curl_tvnow(), now); /* spent time */
     else if(data->set.timeout)
       /* if timeout is requested, find out how much remaining time we have */
       timeout = data->set.timeout - /* timeout time */
-        Curl_tvdiff(Curl_tvnow(), conn->now)/1000; /* spent time */
+        Curl_tvdiff(Curl_tvnow(), conn->now); /* spent time */
     else
       /* Even without a requested timeout, we only wait response_time
          seconds for the full response to arrive before we bail out */
       timeout = ftpc->response_time -
-        Curl_tvdiff(Curl_tvnow(), now)/1000; /* spent time */
+        Curl_tvdiff(Curl_tvnow(), now); /* spent time */
 
     if(timeout <=0 ) {
       failf(data, "FTP response timeout");
@@ -491,6 +491,8 @@ CURLcode Curl_GetFTPResponse(ssize_t *nreadp, /* return number of bytes read */
 
     if(!ftpc->cache) {
       interval_ms = 1 * 1000;  /* use 1 second timeout intervals */
+      if(timeout < interval_ms)
+        interval_ms = timeout;
 
       switch (Curl_select(sockfd, CURL_SOCKET_BAD, interval_ms)) {
       case -1: /* select() error, stop reading */
@@ -2751,16 +2753,16 @@ static long ftp_state_timeout(struct connectdata *conn)
        time.  Also, use ftp->response because FTP_RESPONSE_TIMEOUT is supposed
        to govern the response for any given ftp response, not for the time
        from connect to the given ftp response. */
-    timeout_ms = data->set.ftp_response_timeout*1000 - /* timeout time */
+    timeout_ms = data->set.ftp_response_timeout - /* timeout time */
       Curl_tvdiff(Curl_tvnow(), ftpc->response); /* spent time */
   else if(data->set.timeout)
     /* if timeout is requested, find out how much remaining time we have */
-    timeout_ms = data->set.timeout*1000 - /* timeout time */
+    timeout_ms = data->set.timeout - /* timeout time */
       Curl_tvdiff(Curl_tvnow(), conn->now); /* spent time */
   else
     /* Without a requested timeout, we only wait 'response_time' seconds for
        the full response to arrive before we bail out */
-    timeout_ms = ftpc->response_time*1000 -
+    timeout_ms = ftpc->response_time -
       Curl_tvdiff(Curl_tvnow(), ftpc->response); /* spent time */
 
   return timeout_ms;
@@ -2904,7 +2906,7 @@ CURLcode Curl_ftp_connect(struct connectdata *conn,
   /* We always support persistant connections on ftp */
   conn->bits.close = FALSE;
 
-  ftpc->response_time = 3600; /* set default response time-out */
+  ftpc->response_time = 3600000; /* set default response time-out */
 
 #ifndef CURL_DISABLE_HTTP
   if (conn->bits.tunnel_proxy && conn->bits.httpproxy) {
@@ -3063,7 +3065,7 @@ CURLcode Curl_ftp_done(struct connectdata *conn, CURLcode status, bool premature
      */
     long old_time = ftpc->response_time;
 
-    ftpc->response_time = 60; /* give it only a minute for now */
+    ftpc->response_time = 60000; /* give it only a minute for now */
 
     result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
 
index 250ecada49003dfe31725d8aafad5b6c86e8ac8c..977263b12324e546a06e5185b8a64029b47a7c79 100644 (file)
@@ -144,12 +144,12 @@ static CURLcode handshake(struct connectdata *conn,
       long has_passed;
 
       if(duringconnect && data->set.connecttimeout)
-        timeout_ms = data->set.connecttimeout*1000;
+        timeout_ms = data->set.connecttimeout;
 
       if(data->set.timeout) {
         /* get the strictest timeout of the ones converted to milliseconds */
-        if((data->set.timeout*1000) < timeout_ms)
-          timeout_ms = data->set.timeout*1000;
+        if(data->set.timeout) < timeout_ms)
+          timeout_ms = data->set.timeout;
       }
 
       /* Evaluate in milliseconds how much time that has passed */
index 1db0f4320c4d783ac5d0e3abf9643b5a8c570531..2738edcdf48889769605f018bafe82c4bbd8daf9 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -183,7 +183,7 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn,
 {
   CURLcode rc=CURLE_OK;
   struct SessionHandle *data = conn->data;
-  long timeout = CURL_TIMEOUT_RESOLVE; /* default name resolve timeout */
+  long timeout;
 
   /* now, see if there's a connect timeout or a regular timeout to
      use instead of the default one */
@@ -191,14 +191,8 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn,
     timeout = conn->data->set.connecttimeout;
   else if(conn->data->set.timeout)
     timeout = conn->data->set.timeout;
-
-  /* We convert the number of seconds into number of milliseconds here: */
-  if(timeout < 2147483)
-    /* maximum amount of seconds that can be multiplied with 1000 and
-       still fit within 31 bits */
-    timeout *= 1000;
   else
-    timeout = 0x7fffffff; /* ridiculous amount of time anyway */
+    timeout = CURL_TIMEOUT_RESOLVE * 1000; /* default name resolve timeout */
 
   /* Wait for the name resolve query to complete. */
   while (1) {
index 12e31ea3423b0614e3b1b867f06a13b36467812c..f88bf15eca29b30d96177bfeb15c2070702ce597 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -600,7 +600,7 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn,
   ticks = GetTickCount();
 
   /* wait for the thread to resolve the name */
-  status = WaitForSingleObject(td->event_resolved, 1000UL*timeout);
+  status = WaitForSingleObject(td->event_resolved, timeout);
 
   /* mark that we are now done waiting */
   ReleaseMutex(td->mutex_waiting);
index c07053bdde94c2eb9ae6b5baf93db2ad86a59d9e..ad42273cdeb2f802abdee09bd08f5951692b6863 100644 (file)
@@ -1121,7 +1121,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
   ssize_t gotbytes;
   char *ptr;
   long timeout =
-    data->set.timeout?data->set.timeout:3600; /* in seconds */
+    data->set.timeout?data->set.timeout:3600000; /* in milliseconds */
   char *line_start;
   char *host_port;
   curl_socket_t tunnelsocket = conn->sock[sockindex];
@@ -1225,15 +1225,16 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
 
       /* if timeout is requested, find out how much remaining time we have */
       long check = timeout - /* timeout time */
-        Curl_tvdiff(Curl_tvnow(), conn->now)/1000; /* spent time */
-      if(check <=) {
+        Curl_tvdiff(Curl_tvnow(), conn->now); /* spent time */
+      if(check <= 0) {
         failf(data, "Proxy CONNECT aborted due to timeout");
         error = SELECT_TIMEOUT; /* already too little time */
         break;
       }
 
-      /* timeout each second and check the timeout */
-      switch (Curl_select(tunnelsocket, CURL_SOCKET_BAD, 1000)) {
+      /* loop every second at least, less if the timeout is near */
+      switch (Curl_select(tunnelsocket, CURL_SOCKET_BAD,
+                          check<1000?check:1000)) {
       case -1: /* select() error, stop reading */
         error = SELECT_ERROR;
         failf(data, "Proxy CONNECT aborted due to select() error");
index 3319e697e06232755ead57b56d7b2cc40d8dd6d7..32d0c4b5419da1bf7d8cecf41113d7113eb69bef 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -120,14 +120,14 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
   /* get timeout */
   if(data->set.timeout && data->set.connecttimeout) {
     if (data->set.timeout < data->set.connecttimeout)
-      timeout = data->set.timeout*1000;
+      timeout = data->set.timeout;
     else
-      timeout = data->set.connecttimeout*1000;
+      timeout = data->set.connecttimeout;
   }
   else if(data->set.timeout)
-    timeout = data->set.timeout*1000;
+    timeout = data->set.timeout;
   else if(data->set.connecttimeout)
-    timeout = data->set.connecttimeout*1000;
+    timeout = data->set.connecttimeout;
   else
     timeout = DEFAULT_CONNECT_TIMEOUT;
 
index 55afb2446a8cd95c09c418b2e42cc491bd3bbf32..4f5b7f94d1b7cbe3b64fa7bfb1fa700ce651b029 100644 (file)
@@ -1459,17 +1459,17 @@ Curl_ossl_connect_step2(struct connectdata *conn,
   if(data->set.timeout && data->set.connecttimeout) {
     /* get the most strict timeout of the ones converted to milliseconds */
     if(data->set.timeout<data->set.connecttimeout)
-      *timeout_ms = data->set.timeout*1000;
+      *timeout_ms = data->set.timeout;
     else
-      *timeout_ms = data->set.connecttimeout*1000;
+      *timeout_ms = data->set.connecttimeout;
   }
   else if(data->set.timeout)
-    *timeout_ms = data->set.timeout*1000;
+    *timeout_ms = data->set.timeout;
   else if(data->set.connecttimeout)
-    *timeout_ms = data->set.connecttimeout*1000;
+    *timeout_ms = data->set.connecttimeout;
   else
     /* no particular time-out has been set */
-    *timeout_ms= DEFAULT_CONNECT_TIMEOUT;
+    *timeout_ms = DEFAULT_CONNECT_TIMEOUT;
 
   /* Evaluate in milliseconds how much time that has passed */
   has_passed = Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle);
index 97d22b788abd1a138a0a5ab17f05e42dbe1f0080..14501c6241bf327fbe95fc4c20512fcb628939ba 100644 (file)
@@ -1387,7 +1387,7 @@ CURLcode Curl_telnet(struct connectdata *conn, bool *done)
     if(data->set.timeout) {
       struct timeval now;           /* current time */
       now = Curl_tvnow();
-      if(Curl_tvdiff(now, conn->created)/1000 >= data->set.timeout) {
+      if(Curl_tvdiff(now, conn->created) >= data->set.timeout) {
         failf(data, "Time-out");
         code = CURLE_OPERATION_TIMEOUTED;
         keepon = FALSE;
index 2a28b0cb9a17113b99cf9b38612d407ae0d60f5a..b1a34a5dfb6ed893506293fac4168c5a75e2ecff 100644 (file)
@@ -195,7 +195,7 @@ void tftp_set_timeouts(tftp_state_data_t *state)
   else {
 
     /* Compute drop-dead time */
-    maxtime = (time_t)(data->set.timeout?data->set.timeout:3600);
+    maxtime = (time_t)(data->set.timeout?data->set.timeout/1000L:3600);
     state->max_time = state->start_time+maxtime;
 
     /* Set per-block timeout to 10% of total */
index bff16b4ffb768110ef21aef8cc78058e9eaad105..91e468b64e17a5ba2411bba0ec1ac6739e796d16 100644 (file)
@@ -1547,13 +1547,13 @@ CURLcode Curl_readwrite(struct connectdata *conn,
     return result;
 
   if (data->set.timeout &&
-      ((Curl_tvdiff(k->now, k->start)/1000) >= data->set.timeout)) {
+      (Curl_tvdiff(k->now, k->start) >= data->set.timeout)) {
     if (k->size != -1) {
-      failf(data, "Operation timed out after %d seconds with %"
+      failf(data, "Operation timed out after %d milliseconds with %"
             FORMAT_OFF_T " out of %" FORMAT_OFF_T " bytes received",
             data->set.timeout, k->bytecount, k->size);
     } else {
-      failf(data, "Operation timed out after %d seconds with %"
+      failf(data, "Operation timed out after %d milliseconds with %"
             FORMAT_OFF_T " bytes received",
             data->set.timeout, k->bytecount);
     }
index 8b49033f36bd40b694483e4c230d702cebd6c2b8..076f50ebdd435ad54f5ddf578b771265faf163dc 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -734,7 +734,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
      * An FTP option that specifies how quickly an FTP response must be
      * obtained before it is considered failure.
      */
-    data->set.ftp_response_timeout = va_arg( param , long );
+    data->set.ftp_response_timeout = va_arg( param , long ) * 1000;
     break;
   case CURLOPT_FTPLISTONLY:
     /*
@@ -1242,12 +1242,21 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
      * The maximum time you allow curl to use for a single transfer
      * operation.
      */
+    data->set.timeout = va_arg(param, long) * 1000L;
+    break;
+
+  case CURLOPT_TIMEOUT_MS:
     data->set.timeout = va_arg(param, long);
     break;
+
   case CURLOPT_CONNECTTIMEOUT:
     /*
      * The maximum time you allow curl to use to connect.
      */
+    data->set.connecttimeout = va_arg(param, long) * 1000L;
+    break;
+
+  case CURLOPT_CONNECTTIMEOUT_MS:
     data->set.connecttimeout = va_arg(param, long);
     break;
 
@@ -3828,9 +3837,14 @@ else {
       /* if timeout is not set, use the connect timeout */
       shortest = data->set.connecttimeout;
 
+    if(shortest < 1000)
+      /* the alarm() function only provide integer second resolution, so if
+         we want to wait less than one second we must bail out already now. */
+      return CURLE_OPERATION_TIMEDOUT;
+
     /* alarm() makes a signal get sent when the timeout fires off, and that
        will abort system calls */
-    prev_alarm = alarm((unsigned int) shortest);
+    prev_alarm = alarm((unsigned int) (shortest ? shortest/1000L : shortest));
     /* We can expect the conn->created time to be "now", as that was just
        recently set in the beginning of this function and nothing slow
        has been done since then until now. */
index 3bb3327ba95cc7fd4d954183eb78c41ed6adefea..acc9d1ba63b8b99ef312878e858d05a99ce7c38e 100644 (file)
@@ -1176,9 +1176,9 @@ struct UserDefined {
 
   void *progress_client; /* pointer to pass to the progress callback */
   void *ioctl_client;   /* pointer to pass to the ioctl callback */
-  long timeout;         /* in seconds, 0 means no timeout */
-  long connecttimeout;  /* in seconds, 0 means no timeout */
-  long ftp_response_timeout; /* in seconds, 0 means no timeout */
+  long timeout;         /* in milliseconds, 0 means no timeout */
+  long connecttimeout;  /* in milliseconds, 0 means no timeout */
+  long ftp_response_timeout; /* in milliseconds, 0 means no timeout */
   curl_off_t infilesize;      /* size of file to upload, -1 means unknown */
   long low_speed_limit; /* bytes/second */
   long low_speed_time;  /* number of seconds */