diff options
author | Daniel Stenberg <daniel@haxx.se> | 2010-09-17 23:02:33 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2010-09-17 23:02:33 +0200 |
commit | a76f852ca41b9972eff1ddf52d5de8a90cfad521 (patch) | |
tree | ddeb3f92bc86893ccce8ae16b724ddf4687269d9 | |
parent | 3880dd3741204965dde312643a18190a24c66ba9 (diff) |
timeout: use the correct start value as offset
Rodric provide an awesome recipe that proved libcurl didn't timeout at
the requested time - it instead often timed out at [connect time] +
[timeout time] instead of the documented and intended [timeout time]
only. This bug was due to the code using the wrong base offset when
comparing against "now". I could also take the oppurtinity to simplify
the code by properly using of the generic help function for this:
Curl_timeleft.
Reported by: Rodric Glaser
Bug: http://curl.haxx.se/bug/view.cgi?id=3061535
-rw-r--r-- | lib/transfer.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/transfer.c b/lib/transfer.c index feaf93695..754f6e621 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -103,6 +103,7 @@ #include "multiif.h" #include "easyif.h" /* for Curl_convert_to_network prototype */ #include "rtsp.h" +#include "connect.h" #define _MPRINTF_REPLACE /* use our functions only */ #include <curl/mprintf.h> @@ -1063,17 +1064,17 @@ CURLcode Curl_readwrite(struct connectdata *conn, return result; if(k->keepon) { - if(data->set.timeout && - (Curl_tvdiff(k->now, k->start) >= data->set.timeout)) { + if(0 > Curl_timeleft(conn, &k->now, FALSE)) { if(k->size != -1) { failf(data, "Operation timed out after %ld milliseconds with %" FORMAT_OFF_T " out of %" FORMAT_OFF_T " bytes received", - Curl_tvdiff(k->now, k->start), k->bytecount, k->size); + Curl_tvdiff(k->now, data->progress.t_startsingle), k->bytecount, + k->size); } else { failf(data, "Operation timed out after %ld milliseconds with %" FORMAT_OFF_T " bytes received", - Curl_tvdiff(k->now, k->start), k->bytecount); + Curl_tvdiff(k->now, data->progress.t_startsingle), k->bytecount); } return CURLE_OPERATION_TIMEDOUT; } @@ -1346,12 +1347,10 @@ Transfer(struct connectdata *conn) to work with, skip the timeout */ timeout_ms = 0; else { - if(data->set.timeout) { - totmp = (int)(data->set.timeout - Curl_tvdiff(k->now, k->start)); - if(totmp < 0) - return CURLE_OPERATION_TIMEDOUT; - } - else + totmp = Curl_timeleft(conn, &k->now, FALSE); + if(totmp < 0) + return CURLE_OPERATION_TIMEDOUT; + else if(!totmp) totmp = 1000; if (totmp < timeout_ms) |