summaryrefslogtreecommitdiff
path: root/lib/multi.c
Commit message (Collapse)AuthorAgeFilesLines
* Curl_easy: remove req.maxfd - never used!bagder/remove-maxfdDaniel Stenberg2019-02-281-2/+0
| | | | | Introduced in 8b6314ccfb, but not used anymore in current code. Unclear since when.
* multi: call multi_done on connect timeoutsDaniel Stenberg2019-02-241-1/+2
| | | | | | | | | | Failing to do so would make the CURLINFO_TOTAL_TIME timeout to not get updated correctly and could end up getting reported to the application completely wrong (way too small). Reported-by: accountantM on github Fixes #3602 Closes #3605
* singlesocket: fix the 'sincebefore' placementDaniel Stenberg2019-02-201-2/+2
| | | | | | | | | | | | The variable wasn't properly reset within the loop and thus could remain set for sockets that hadn't been set before and miss notifying the app. This is a follow-up to 4c35574 (shipped in curl 7.64.0) Reported-by: buzo-ffm on github Detected-by: Jan Alexander Steffens Fixes #3585 Closes #3589
* multi: Dereference of null pointerDaniel Stenberg2019-02-131-14/+10
| | | | | | | | Mostly a false positive, but this makes the code easier to read anyway. Detected by scan-build. Closes #3563
* http2: multi_connchanged() moved from multi.c, only used for h2Daniel Stenberg2019-02-121-11/+0
| | | | Closes #3557
* multi: remove verbose "Expire in" ... messagesDaniel Stenberg2019-02-121-3/+0
| | | | | | Reported-by: James Brown Bug: https://curl.haxx.se/mail/archive-2019-02/0013.html Closes #3558
* multi: (void)-prefix when ignoring return valuesDaniel Stenberg2019-02-111-4/+7
| | | | | ... and added braces to two function calls which fixes warnings if they are replace by empty macros at build-time.
* cleanup: make local functions staticDaniel Stenberg2019-02-101-8/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | urlapi: turn three local-only functions into statics conncache: make conncache_find_first_connection static multi: make detach_connnection static connect: make getaddressinfo static curl_ntlm_core: make hmac_md5 static http2: make two functions static http: make http_setup_conn static connect: make tcpnodelay static tests: make UNITTEST a thing to mark functions with, so they can be static for normal builds and non-static for unit test builds ... and mark Curl_shuffle_addr accordingly. url: make up_free static setopt: make vsetopt static curl_endian: make write32_le static rtsp: make rtsp_connisdead static warnless: remove unused functions memdebug: remove one unused function, made another static
* multi: set the EXPIRE_*TIMEOUT timers at TIMER_STARTSINGLE timeDaniel Stenberg2019-02-011-0/+6
| | | | | | | | | To make sure Curl_timeleft() also thinks the timeout has been reached when one of the EXPIRE_*TIMEOUTs expires. Bug: https://curl.haxx.se/mail/lib-2019-01/0073.html Reported-by: Zhao Yisha Closes #3501
* multi: remove "Dead assignment"Daniel Stenberg2019-01-151-2/+0
| | | | | | Found by scan-build. Follow-up to 4c35574bb785ce. Closes #3471
* urldata: rename easy_conn to just connDaniel Stenberg2019-01-111-155/+151
| | | | | | | | | | | | | | | We use "conn" everywhere to be a pointer to the connection. Introduces two functions that "attaches" and "detaches" the connection to and from the transfer. Going forward, we should favour using "data->conn" (since a transfer always only has a single connection or none at all) to "conn->data" (since a connection can have none, one or many transfers associated with it and updating conn->data to be correct is error prone and a frequent reason for internal issues). Closes #3442
* multi: multiplexing improvementsDaniel Stenberg2019-01-101-103/+132
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #3436 Closes #3448 Problem 1 After LOTS of scratching my head, I eventually realized that even when doing 10 uploads in parallel, sometimes the socket callback to the application that tells it what to wait for on the socket, looked like it would reflect the status of just the single transfer that just changed state. Digging into the code revealed that this was indeed the truth. When multiple transfers are using the same connection, the application did not correctly get the *combined* flags for all transfers which then could make it switch to READ (only) when in fact most transfers wanted to get told when the socket was WRITEABLE. Problem 1b A separate but related regression had also been introduced by me when I cleared connection/transfer association better a while ago, as now the logic couldn't find the connection and see if that was marked as used by more transfers and then it would also prematurely remove the socket from the socket hash table even in times other transfers were still using it! Fix 1 Make sure that each socket stored in the socket hash has a "combined" action field of what to ask the application to wait for, that is potentially the ORed action of multiple parallel transfers. And remove that socket hash entry only if there are no transfers left using it. Problem 2 The socket hash entry stored an association to a single transfer using that socket - and when curl_multi_socket_action() was called to tell libcurl about activities on that specific socket only that transfer was "handled". This was WRONG, as a single socket/connection can be used by numerous parallel transfers and not necessarily a single one. Fix 2 We now store a list of handles in the socket hashtable entry and when libcurl is told there's traffic for a particular socket, it now iterates over all known transfers using that single socket.
* curl_multi_remove_handle() don't block terminating c-ares requestsBrad Spencer2019-01-071-5/+2
| | | | | | | | | Added Curl_resolver_kill() for all three resolver modes, which only blocks when necessary, along with test 1592 to confirm curl_multi_remove_handle() doesn't block unless it must. Closes #3428 Fixes #3371
* printf: introduce CURL_FORMAT_TIMEDIFF_TRikard Falkeborn2019-01-041-7/+10
|
* disconnect: separate connections and easy handles betterDaniel Stenberg2018-12-221-3/+1
| | | | | | | | | | | | Do not assume/store assocation between a given easy handle and the connection if it can be avoided. Long-term, the 'conn->data' pointer should probably be removed as it is a little too error-prone. Still used very widely though. Reported-by: masbug on github Fixes #3391 Closes #3400
* multi: convert two timeout variables to timediff_tDaniel Stenberg2018-12-111-2/+2
| | | | | | | | The time_t type is unsigned on some systems and these variables are used to hold return values from functions that return timediff_t already. timediff_t is always a signed type. Closes #3363
* Upon HTTP_1_1_REQUIRED, retry the request with HTTP/1.1Johannes Schindelin2018-12-081-0/+20
| | | | | | | | | | | | | | | | | | | This is a companion patch to cbea2fd2c (NTLM: force the connection to HTTP/1.1, 2018-12-06): with NTLM, we can switch to HTTP/1.1 preemptively. However, with other (Negotiate) authentication it is not clear to this developer whether there is a way to make it work with HTTP/2, so let's try HTTP/2 first and fall back in case we encounter the error HTTP_1_1_REQUIRED. Note: we will still keep the NTLM workaround, as it avoids an extra round trip. Daniel Stenberg helped a lot with this patch, in particular by suggesting to introduce the Curl_h2_http_1_1_error() function. Closes #3349 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
* curl_easy_perform: fix timeout handlingDaniel Stenberg2018-11-251-2/+18
| | | | | | | | | | | | | curl_multi_wait() was erroneously used from within curl_easy_perform(). It could lead to it believing there was no socket to wait for and then instead sleep for a while instead of monitoring the socket and then miss acting on that activity as swiftly as it should (causing an up to 1000 ms delay). Reported-by: Antoni Villalonga Fixes #3305 Closes #3306 Closes #3308
* snprintf: renamed and we now only use msnprintf()Daniel Stenberg2018-11-231-7/+7
| | | | | | | | | | | The function does not return the same value as snprintf() normally does, so readers may be mislead into thinking the code works differently than it actually does. A different function name makes this easier to detect. Reported-by: Tomas Hoger Assisted-by: Daniel Gustafsson Fixes #3296 Closes #3297
* ares: remove fd from multi fd set when ares is about to close the fdRomain Fliedel2018-11-201-4/+4
| | | | | | | | | | | | | | | | | | | When using c-ares for asyn dns, the dns socket fd was silently closed by c-ares without curl being aware. curl would then 'realize' the fd has been removed at next call of Curl_resolver_getsock, and only then notify the CURLMOPT_SOCKETFUNCTION to remove fd from its poll set with CURL_POLL_REMOVE. At this point the fd is already closed. By using ares socket state callback (ARES_OPT_SOCK_STATE_CB), this patch allows curl to be notified that the fd is not longer needed for neither for write nor read. At this point by calling Curl_multi_closed we are able to notify multi with CURL_POLL_REMOVE before the fd is actually closed by ares. In asyn-ares.c Curl_resolver_duphandle we can't use ares_dup anymore since it does not allow passing a different sock_state_cb_data Closes #3238
* multi: Fix error handling in the SENDPROTOCONNECT stateMichael Kaufmann2018-10-271-1/+1
| | | | | | | If Curl_protocol_connect() returns an error code, handle the error instead of switching to the next state. Closes #3170
* multi: avoid double-freeDaniel Stenberg2018-10-191-9/+4
| | | | | | | | | | | Curl_follow() no longer frees the string. Make sure it happens in the caller function, like we normally handle allocations. This bug was introduced with the use of the URL API internally, it has never been in a release version Reported-by: Dario Weißer Closes #3149
* multi: make the closure handle "inherit" CURLOPT_NOSIGNALDaniel Stenberg2018-10-191-0/+2
| | | | | | | | Otherwise, closing that handle can still cause surprises! Reported-by: Martin Ankerl Fixes #3138 Closes #3147
* Curl_follow: Always free the passed new URLMichael Kaufmann2018-10-131-0/+1
| | | | Closes #3124
* multi: fix memory leak in content encoding related error pathDaniel Stenberg2018-09-291-3/+7
| | | | | | | | ... a missing multi_done() call. Credit to OSS-Fuzz Bug: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=10728 Closes #3063
* multi: fix location URL memleak in error pathDaniel Stenberg2018-09-281-1/+4
| | | | | Follow-up to #3044 - fix a leak OSS-Fuzz detected Closes #3057
* url: use the URL API internally as wellDaniel Stenberg2018-09-221-7/+2
| | | | | | ... to make it a truly unified URL parser. Closes #3017
* curl_multi_wait: call getsock before figuring out timeoutDaniel Stenberg2018-09-181-7/+7
| | | | | | | .... since getsock may update the expiry timer. Fixes #2996 Closes #3000
* setopt: add CURLOPT_DOH_URLDaniel Stenberg2018-09-061-12/+18
| | | | Closes #2668
* multiplex: enable by defaultDaniel Stenberg2018-09-051-0/+1
| | | | Starting 7.62.0, multiplexing is enabled by default in multi handles.
* pipelining: deprecatedDaniel Stenberg2018-09-051-1/+1
| | | | | | | | | | | | Transparently. The related curl_multi_setopt() options all still returns OK when pipelining is selected. To re-enable the support, the single line change in lib/multi.c needs to be reverted. See docs/DEPRECATE.md Closes #2705
* upload: allocate upload buffer on-demandDaniel Stenberg2018-08-181-0/+3
| | | | | | | Saves 16KB on the easy handle for operations that don't need that buffer. Part 1 of #2888
* urldata: remove unused pipe_broke struct fieldDaniel Stenberg2018-08-161-25/+3
| | | | | | | This struct field is never set TRUE in any existing code path. This change removes the field completely. Closes #2871
* retry: return error if rewind was necessary but didn't happenDaniel Jelinski2018-07-311-0/+2
| | | | | Fixes #2801 Closes #2812
* multi: always do the COMPLETED procedure/stateDaniel Stenberg2018-07-111-23/+30
| | | | | | | | | | | It was previously erroneously skipped in some situations. libtest/libntlmconnect.c wrongly depended on wrong behavior (that it would get a zero timeout) when no handles are "running" in a multi handle. That behavior is no longer present with this fix. Now libcurl will always return a -1 timeout when all handles are completed. Closes #2733
* conn: remove the boolean 'inuse' fieldDaniel Stenberg2018-07-111-21/+27
| | | | ... as the usage needs to be counted.
* multi: fix crash due to dangling entry in connect-pending listJavier Blazquez2018-06-231-0/+5
| | | | | Fixes #2677 Closes #2679
* multi: fix memory leak when stopped during name resolveDaniel Stenberg2018-06-161-11/+23
| | | | | | | | | | | | When the application just started the transfer and then stops it while the name resolve in the background thread hasn't completed, we need to wait for the resolve to complete and then cleanup data accordingly. Enabled test 1553 again and added test 1590 to also check when the host name resolves successfully. Detected by OSS-fuzz. Closes #1968
* cppcheck: fix warningsMarian Klymov2018-06-111-4/+3
| | | | | | | | | | | | | - Get rid of variable that was generating false positive warning (unitialized) - Fix issues in tests - Reduce scope of several variables all over etc Closes #2631
* spelling fixesViktor Szakats2018-06-031-1/+1
| | | | | | Detected using the `codespell` tool (version 1.13.0). Also secure and fix an URL.
* multi: remove a DEBUGF()Daniel Stenberg2018-06-011-2/+0
| | | | | | | | ... it might call infof() with a NULL first argument that isn't harmful but makes it not do anything. The infof() line is not very useful anymore, it has served it purpose. Good riddance! Fixes #2627
* strictness: correct {infof, failf} format specifiersRikard Falkeborn2018-05-311-2/+2
| | | | Closes #2623
* psl: use latest psl and refresh it periodicallyPatrick Monnerat2018-05-281-0/+21
| | | | | | | | | | | The latest psl is cached in the multi or share handle. It is refreshed before use after 72 hours. New share lock CURL_LOCK_DATA_PSL controls the psl cache sharing. If the latest psl is not available, the builtin psl is used. Reported-by: Yaakov Selkowitz Fixes #2553 Closes #2601
* checksrc: force indentation of lines after an elseDaniel Gustafsson2018-04-271-2/+1
| | | | | | | | This extends the INDENTATION case to also handle 'else' statements and require proper indentation on the following line. Also fixes the offending cases found in the codebase. Closes #2532
* http2: handle GOAWAY properlyDaniel Stenberg2018-04-201-1/+3
| | | | | | | | | | When receiving REFUSED_STREAM, mark the connection for close and retry streams accordingly on another/fresh connection. Reported-by: Terry Wu Fixes #2416 Fixes #1618 Closes #2510
* add_handle/easy_perform: clear errorbuffer on start if setDaniel Stenberg2018-03-171-0/+2
| | | | | | | | | | To offer applications a more defined behavior, we clear the buffer as early as possible. Assisted-by: Jay Satiro Fixes #2190 Closes #2377
* multi: improved pending transfers handling => improved performanceDaniel Stenberg2018-03-161-25/+21
| | | | | | | | | | | | | | | | When a transfer is requested to get done and it is put in the pending queue when limited by number of connections, total or per-host, libcurl would previously very aggressively retry *ALL* pending transfers to get them transferring. That was very time consuming. By reducing the aggressiveness in how pending are being retried, we waste MUCH less time on putting transfers back into pending again. Some test cases got a factor 30(!) speed improvement with this change. Reported-by: Cyril B Fixes #2369 Closes #2383
* pause: when changing pause state, update socket stateDaniel Stenberg2018-03-161-0/+6
| | | | | | | | | | | | Especially unpausing a transfer might have to move the socket back to the "currently used sockets" hash to get monitored. Otherwise it would never get any more data and get stuck. Easily triggered with pausing using the multi_socket API. Reported-by: Philip Prindeville Bug: https://curl.haxx.se/mail/lib-2018-03/0048.html Fixes #2393 Closes #2391
* rate-limit: use three second window to better handle high speedsDaniel Stenberg2018-03-161-13/+18
| | | | | | | | | | | | | | | Due to very frequent updates of the rate limit "window", it could attempt to rate limit within the same milliseconds and that then made the calculations wrong, leading to it not behaving correctly on very fast transfers. This new logic updates the rate limit "window" to be no shorter than the last three seconds and only updating the timestamps for this when switching between the states TOOFAST/PERFORM. Reported-by: 刘佩东 Fixes #2386 Closes #2388
* http2: mark the connection for close on GOAWAYDaniel Stenberg2018-03-121-6/+3
| | | | | | | | | ... don't consider it an error! Assisted-by: Jay Satiro Reported-by: Łukasz Domeradzki Fixes #2365 Closes #2375