]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
socks: Fix blocking timeout logic
authorJay Satiro <raysatiro@yahoo.com>
Sun, 12 Apr 2020 03:19:55 +0000 (23:19 -0400)
committerJay Satiro <raysatiro@yahoo.com>
Sun, 12 Apr 2020 22:32:16 +0000 (18:32 -0400)
- Document in Curl_timeleft's comment block that returning 0 signals no
  timeout (ie there's infinite time left).

- Fix SOCKS' Curl_blockread_all for the case when no timeout was set.

Prior to this change if the timeout had a value of 0 and that was passed
to SOCKET_READABLE it would return right away instead of blocking. That
was likely because it was not well understood that when Curl_timeleft
returns 0 it is not a timeout of 0 ms but actually means no timeout.

Ref: https://github.com/curl/curl/pull/5214#issuecomment-612512360

Closes https://github.com/curl/curl/pull/5220

lib/connect.c
lib/socks.c

index 54c5f9e4c26bc43318e1dbf86f7317fdf4f2b88e..421f9041596ce3f8f58ba25d533f9df01dcc2233 100644 (file)
@@ -171,7 +171,8 @@ singleipconnect(struct connectdata *conn,
 
 /*
  * Curl_timeleft() returns the amount of milliseconds left allowed for the
- * transfer/connection. If the value is negative, the timeout time has already
+ * transfer/connection. If the value is 0, there's no timeout (ie there's
+ * infinite time left). If the value is negative, the timeout time has already
  * elapsed.
  *
  * The start time is stored in progress.t_startsingle - as set with
index 5dd83631c45c3e6a651c2c5389f14ad60b91329b..dfd944ef341675eb985e6a9e933b8372e9653e73 100644 (file)
@@ -62,15 +62,15 @@ int Curl_blockread_all(struct connectdata *conn, /* connection data */
   int result;
   *n = 0;
   for(;;) {
-    timediff_t timeleft = Curl_timeleft(conn->data, NULL, TRUE);
-    if(timeleft < 0) {
+    timediff_t timeout_ms = Curl_timeleft(conn->data, NULL, TRUE);
+    if(timeout_ms < 0) {
       /* we already got the timeout */
       result = CURLE_OPERATION_TIMEDOUT;
       break;
     }
-    if(timeleft > TIME_T_MAX)
-      timeleft = TIME_T_MAX;
-    if(SOCKET_READABLE(sockfd, (time_t)timeleft) <= 0) {
+    if(!timeout_ms || timeout_ms > TIME_T_MAX)
+      timeout_ms = TIME_T_MAX;
+    if(SOCKET_READABLE(sockfd, (time_t)timeout_ms) <= 0) {
       result = ~CURLE_OK;
       break;
     }