summaryrefslogtreecommitdiff
path: root/lib/multi.c
Commit message (Collapse)AuthorAgeFilesLines
* hash: lazy-alloc the table in Curl_hash_add()bagder/hash-lazyallocDaniel Stenberg2021-12-101-12/+7
| | | | | | This makes Curl_hash_init() infallible which saves error paths. Closes #8132
* multi: cleanup the socket hash when destroying itbagder/sockhash-destroyDaniel Stenberg2021-12-101-6/+27
| | | | | | | | | Since each socket hash entry may themselves have a hash table in them, the destroying of the socket hash needs to make sure all the subhashes are also correctly destroyed to avoid leaking memory. Fixes #8129 Closes #8131
* multi: handle errors returned from socket/timer callbacksDaniel Stenberg2021-12-061-54/+119
| | | | | | | | | | | | The callbacks were partially documented to support this. Now the behavior is documented and returning error from either of these callbacks will effectively kill all currently ongoing transfers. Added test 530 to verify Reported-by: Marcelo Juchem Fixes #8083 Closes #8089
* multi: shut down CONNECT in Curl_detach_connnectionDaniel Stenberg2021-11-111-0/+1
| | | | | | | | | | ... to prevent a lingering pointer that would lead to a double-free. Added test 1939 to verify. Reported-by: Stephen M. Coakley Fixes #7982 Closes #7986
* lib: fixing comment spelling typos in lib filesEddie Lumpkin2021-10-221-1/+1
| | | | | Closes #7894 Signed-off-by: ewlumpkin <ewlumpkin@gmail.com>
* CURLOPT_PREREQFUNCTION: add new callbackMax Dymond2021-09-271-0/+22
| | | | | | | | | | | | | | Triggered before a request is made but after a connection is set up Changes: - callback: Update docs and callback for pre-request callback - Add documentation for CURLOPT_PREREQDATA and CURLOPT_PREREQFUNCTION, - Add redirect test and callback failure test - Note that the function may be called multiple times on a redirection - Disable new 2086 test due to Windows weirdness Closes #7477
* cleanup: constify unmodified static structsRikard Falkeborn2021-09-231-1/+1
| | | | | | | Constify a number of static structs that are never modified. Make them const to show this. Closes #7759
* curl_multi_fdset: make FD_SET() not operate on sockets out of rangeDaniel Stenberg2021-09-151-2/+8
| | | | | | | | | | The VALID_SOCK() macro was made to only check for FD_SETSIZE if curl was built to use select(), even though the curl_multi_fdset() function always and unconditionally uses FD_SET and needs the check. Reported-by: 0xee on github Fixes #7718 Closes #7719
* multi: fix compiler warning with `CURL_DISABLE_WAKEUP`Marcel Raad2021-09-021-0/+3
| | | | | | `use_wakeup` is unused in this case. Closes https://github.com/curl/curl/pull/7661
* multi: fix crash in curl_multi_wait / curl_multi_pollUser Sg2021-07-161-2/+2
| | | | | | | | | | | | Appears to have been caused by 51c0ebc (precedes 7.77.0) which added a VALID_SOCK check to one of the loops through the sockets but not the other. Reported-by: sylgal@users.noreply.github.com Authored-by: sylgal@users.noreply.github.com Fixes https://github.com/curl/curl/issues/7379 Closes https://github.com/curl/curl/pull/7389
* infof: remove newline from format strings, always append itDaniel Stenberg2021-07-071-11/+11
| | | | | | | | | | | | | | | | - the data needs to be "line-based" anyway since it's also passed to the debug callback/application - it makes infof() work like failf() and consistency is good - there's an assert that triggers on newlines in the format string - Also removes a few instances of "..." - Removes the code that would append "..." to the end of the data *iff* it was truncated in infof() Closes #7357
* multi: alter transfer timeout orderingRichard Whitehouse2021-06-241-40/+75
| | | | | | | | | | | | | | | | | - Check whether a connection has succeded before checking whether it's timed out. This means if we've connected quickly, but subsequently been descheduled, we allow the connection to succeed. Note, if we timeout, but between checking the timeout, and connecting to the server the connection succeeds, we will allow it to go ahead. This is viewed as an acceptable trade off. - Add additional failf logging around failed connection attempts to propogate the cause up to the caller. Co-Authored-by: Martin Howarth Closes #7178
* multi: do not switch off connect_only flag when closingDaniel Stenberg2021-06-241-1/+0
| | | | | | | | ... as it made protocol specific disconnect commands wrongly get used. Bug: https://curl.se/mail/lib-2021-06/0024.html Reported-by: Aleksander Mazur Closes #7288
* multi: add scan-build-6 work-around in curl_multi_fdsetDaniel Stenberg2021-06-131-1/+6
| | | | | | | | | scan-build-6 otherwise warns, saying: warning: The left operand of '>=' is a garbage value otherwise, which is false. Later scan-builds don't claim this on the same code. Closes #7248
* openssl: associate/detach the transfer from connectionHarry Sintonen2021-05-241-1/+4
| | | | | | CVE-2021-22901 Bug: https://curl.se/docs/CVE-2021-22901.html
* conn: add 'attach' to protocol handler, make libssh2 use itDaniel Stenberg2021-05-171-0/+2
| | | | | | | | | | | The libssh2 backend has SSH session associated with the connection but the callback context is the easy handle, so when a connection gets attached to a transfer, the protocol handler now allows for a custom function to get used to set things up correctly. Reported-by: Michael O'Farrell Fixes #6898 Closes #7078
* http: deal with partial CONNECT sendsDaniel Stenberg2021-05-081-5/+3
| | | | | | | | | | | Also added 'CURL_SMALLSENDS' to make Curl_write() send short packets, which helped verifying this even more. Add test 363 to verify. Reported-by: ustcqidi on github Fixes #6950 Closes #7024
* tidy-up: make conditional checks more consistentDaniel Stenberg2021-04-221-2/+2
| | | | | | ... remove '== NULL' and '!= 0' Closes #6912
* multi: fix slow write/upload performance on WindowsMarc Hoersken2021-04-211-6/+13
| | | | | | | | | | | | | | | | | | Reset FD_WRITE by sending zero bytes which is permissible and will be treated by implementations as successful send. Without this we won't be notified in case a socket is still writable if we already received such a notification and did not send any data afterwards on the socket. This would lead to waiting forever on a writable socket being writable again. Assisted-by: Tommy Odom Reviewed-by: Jay Satiro Reviewed-by: Marcel Raad Tested-by: tmkk on github Bug: #6146 Closes #6245
* multi: reduce Win32 API calls to improve performanceMarc Hoersken2021-04-211-75/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | 1. Consolidate pre-checks into a single Curl_poll call: This is an attempt to restructure the code in Curl_multi_wait in such a way that less syscalls are made by removing individual calls to Curl_socket_check via SOCKET_READABLE/SOCKET_WRITABLE. 2. Avoid resetting the WinSock event multiple times: We finally call WSAResetEvent anyway, so specifying it as an optional parameter to WSAEnumNetworkEvents is redundant. 3. Wakeup directly in case no sockets are being monitoring: Fix the WinSock based implementation to skip extra waiting by not sleeping in case no sockets are to be waited on and just the WinSock event is being monitored for wakeup functionality. Assisted-by: Tommy Odom Reviewed-by: Jay Satiro Reviewed-by: Marcel Raad Bug: #6146 Closes #6245
* Revert "Revert 'multi: implement wait using winsock events'"Marc Hoersken2021-04-211-3/+149
| | | | | | | | | | | | | | This reverts commit 2260e0ebe6d45529495231b3e37a0c58fb92a6a2, also restoring previous follow up changes which were reverted. Authored-by: rcombs on github Authored-by: Marc Hörsken Reviewed-by: Jay Satiro Reviewed-by: Marcel Raad Restores #5634 Reverts #6281 Part of #6245
* multi: don't close connection HTTP_1_1_REQUIREDDaniel Stenberg2021-04-211-1/+1
| | | | | | The ConnectionExists() function will note that the new transfer wants less then h2 and that it can't multiplex it and therefor opt to open a new connection instead.
* http2: move the stream error field to the per-transfer storageDaniel Stenberg2021-04-211-1/+1
| | | | | | | | Storing a stream error in the per-connection struct was an error that lead to race conditions as subsequent stream handling could overwrite the error code before it was used for the stream with the actual problem. Closes #6910
* send_speed: simplify the checks for if a speed limit is setDaniel Stenberg2021-03-271-4/+4
| | | | | ... as we know the value cannot be set to negative: enforced by setopt()
* urldata: merge "struct DynamicStatic" into "struct UrlState"Daniel Stenberg2021-03-261-1/+1
| | | | | | | | Both were used for the same purposes and there was no logical separation between them. Combined, this also saves 16 bytes in less holes in my test build. Closes #6798
* multi: close the connection when h2=>h1 downgradingDaniel Stenberg2021-03-251-0/+1
| | | | | | | | | | Otherwise libcurl is likely to reuse the connection again in the next attempt since the connection reuse logic doesn't take downgrades into account. Reported-by: Anthony Ramine Fixes #6788 Closes #6793
* multi: update pending list when removing handleejanchivdorj2021-03-101-0/+13
| | | | | | | when removing a handle, most of the lists are updated but pending list is not updated. Updating now. Closes #6713
* urldata: make 'actions[]' use unsigned char instead of intDaniel Stenberg2021-02-241-8/+8
| | | | | | | ... as it only needs a few bits per index anyway. Reviewed-by: Daniel Gustafsson Closes #6648
* multi: do once-per-transfer inits in before_perform in DID stateDaniel Stenberg2021-02-221-4/+4
| | | | | | | | | | | | | ... since the state machine might go to RATELIMITING and then back to PERFORMING doing once-per-transfer inits in that function is wrong and it caused problems with receiving chunked HTTP and it set the PRETRANSFER time much too often... Regression from b68dc34af341805aeb7b3715 (shipped in 7.75.0) Reported-by: Amaury Denoyelle Fixes #6640 Closes #6641
* multi: rename the multi transfer statesDaniel Stenberg2021-02-161-115/+111
| | | | | | | | | | While working on documenting the states it dawned on me that step one is to use more descriptive names on the states. This also changes prefix on the states to make them shorter in the source. State names NOT ending with *ing are transitional ones. Closes #6612
* lib: remove 'conn->data' completelyDaniel Stenberg2021-02-161-30/+6
| | | | | | | | The Curl_easy pointer struct entry in connectdata is now gone. Just before commit 215db086e0 landed on January 8, 2021 there were 919 references to conn->data. Closes #6608
* urldata: don't touch data->set.httpversion at run-timeDaniel Stenberg2021-02-121-1/+1
| | | | | | | | | Rename it to 'httpwant' and make a cloned field in the state struct as well for run-time updates. Also: refuse non-supported HTTP versions. Verified with test 129. Closes #6585
* vtls: initial implementation of rustls backendJacob Hoffman-Andrews2021-02-091-1/+1
| | | | | | | | | | | | | | | | | This adds a new TLS backend, rustls. It uses the C-to-rustls bindings from https://github.com/abetterinternet/crustls. Rustls is at https://github.com/ctz/rustls/. There is still a fair bit to be done, like sending CloseNotify on connection shutdown, respecting CAPATH, and properly indicating features like "supports TLS 1.3 ciphersuites." But it works well enough to make requests and receive responses. Blog post for context: https://www.abetterinternet.org/post/memory-safe-curl/ Closes #6350
* hostip/proxy: remove conn->data useDaniel Stenberg2021-01-261-2/+2
| | | | Closes #6513
* hostip: remove conn->data from resolver functionsDaniel Stenberg2021-01-221-6/+6
| | | | | | | This also moves the 'async' struct from the connectdata struct into the Curl_easy struct, which seems like a better home for it. Closes #6497
* lib: save a bit of space with some structure packingErik Olsson2021-01-201-1/+1
| | | | | | | | | | | | | | | - Reorder some internal struct members so that less padding is used. This is an attempt at saving a bit of space by packing some structs (using pahole to find the holes) where it might make sense to do so without losing readability. I.e., I tried to avoid separating fields that seem grouped together (like the cwd... fields in struct ftp_conn for instance). Also abstained from touching fields behind conditional macros as that quickly can get complicated. Closes https://github.com/curl/curl/pull/6483
* urldata: make magic be the first struct fieldDaniel Stenberg2021-01-201-3/+3
| | | | | | | | | | | | | By making the `magic` identifier the same size and at the same place within the structs (easy, multi, share), libcurl will be able to more reliably detect and safely error out if an application passes in the wrong handle to APIs. Easier to detect and less likely to cause crashes if done. Such mixups can't be detected at compile-time due to them being typedefed void pointers - unless `CURL_STRICTER` is defined. Closes #6484
* transfer: remove conn->data useDaniel Stenberg2021-01-191-3/+3
| | | | Closes #6486
* lib: more conn->data cleanupsDaniel Stenberg2021-01-191-3/+3
| | | | Closes #6479
* lib: pass in 'struct Curl_easy *' to most functionsDaniel Stenberg2021-01-171-52/+49
| | | | | | | | | | | | | | | | | | | | | ... in most cases instead of 'struct connectdata *' but in some cases in addition to. - We mostly operate on transfers and not connections. - We need the transfer handle to log, store data and more. Everything in libcurl is driven by a transfer (the CURL * in the public API). - This work clarifies and separates the transfers from the connections better. - We should avoid "conn->data". Since individual connections can be used by many transfers when multiplexing, making sure that conn->data points to the current and correct transfer at all times is difficult and has been notoriously error-prone over the years. The goal is to ultimately remove the conn->data pointer for this reason. Closes #6425
* multi: set the PRETRANSFER time-stamp when we switch to PERFORMDaniel Stenberg2021-01-141-23/+9
| | | | | | | | | | | ... instead of at end of the DO state. This makes the timer more accurate for the protocols that use the DOING state (such as FTP), and simplifies how the function (now called init_perform) is called. The timer will then include the entire procedure up to PERFORM - including all instructions for getting the transfer started. Closes #6454
* multi: remove Curl_ prefix from static functionsDaniel Stenberg2021-01-141-14/+14
|
* multi_runsingle: bail out early on data->conn == NULLDaniel Stenberg2021-01-111-1/+4
| | | | | | | As that's a significant error condition and scan-build warns for NULL pointer dereferences if we don't. Closes #6433
* multi: skip DONE state if there's no connection left for ftp wildcardDaniel Stenberg2021-01-111-1/+4
| | | | ... to avoid running in that state with data->conn being NULL.
* httpauth: make multi-request auth work with custom portDaniel Stenberg2021-01-021-2/+2
| | | | | | | | | | | | When doing HTTP authentication and a port number set with CURLOPT_PORT, the code would previously have the URL's port number override as if it had been a redirect to an absolute URL. Added test 1568 to verify. Reported-by: UrsusArctos on github Fixes #6397 Closes #6400
* multi: when erroring in TOOFAST state, act as for PERFORMDaniel Stenberg2020-12-171-1/+9
| | | | | | | | | | | | | When failing in TOOFAST, the multi_done() wasn't called so the same cleanup and handling wasn't done like when it fails in PERFORM, which in the case of FTP could mean that the control connection wouldn't be marked as "dead" for the CURLE_ABORTED_BY_CALLBACK case. Which caused ftp_disconnect() to use it to send "QUIT", which could end up waiting for a response a long time before giving up! Reported-by: Tomas Berger Fixes #6333 Closes #6337
* Revert "multi: implement wait using winsock events"Daniel Stenberg2020-12-061-149/+3
| | | | | | | | | | | This reverts commit d2a7d7c185f98df8f3e585e5620cbc0482e45fac. This commit also reverts the subsequent follow-ups to that commit, which were all done within windows #ifdefs that are removed in this change. Marc helped me verify this. Fixes #6146 Closes #6281
* splay: rename Curl_splayremovebyaddr to Curl_splayremoveDaniel Stenberg2020-12-011-6/+4
| | | | | | | ... and remove the old unused proto for the old Curl_splayremove version. Closes #6269
* curl.se: new homeDaniel Stenberg2020-11-041-1/+1
| | | | Closes #6172
* checksrc: warn on empty line before open braceDaniel Stenberg2020-10-151-1/+0
| | | | | | ... and fix a few occurances Closes #6088