From 0510cce8c090920f063b85a36669d8e74cff8d52 Mon Sep 17 00:00:00 2001 From: Jay Satiro Date: Sat, 11 Apr 2020 23:19:55 -0400 Subject: socks: Fix blocking timeout logic - 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/socks.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/socks.c') diff --git a/lib/socks.c b/lib/socks.c index 5dd83631c..dfd944ef3 100644 --- a/lib/socks.c +++ b/lib/socks.c @@ -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; } -- cgit v1.2.3