summaryrefslogtreecommitdiff
path: root/lib/multi.c
Commit message (Collapse)AuthorAgeFilesLines
* 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
* multi: align WinSock mask variables in Curl_multi_waitMarc Hoersken2020-09-171-11/+11
| | | | | | | | | | Also skip pre-checking sockets to set timeout_ms to 0 after the first socket has been detected to be ready. Reviewed-by: rcombs on github Reviewed-by: Daniel Stenberg Follow up to #5886
* multi: reuse WinSock events variable in Curl_multi_waitMarc Hoersken2020-09-171-12/+11
| | | | | | | | | | | Since the struct is quite large (1 long and 10 ints) we declare it once at the beginning of the function instead of multiple times inside loops to avoid stack movements. Reviewed-by: Viktor Szakats Reviewed-by: Daniel Stenberg Closes #5886
* hash: make it 'struct Curl_hash'Daniel Stenberg2020-09-021-7/+7
| | | | | | As internal global names should use captical C. Closes #5906
* llist: make it "struct Curl_llist"Daniel Stenberg2020-09-021-12/+12
| | | | | | As internal global names should use captical C. Closes #5906
* multi: handle connection state winsock eventsMarc Hoersken2020-08-281-6/+6
| | | | | | | | | | | | Learn from the way Cygwin handles and maps the WinSock events to simulate correct and complete poll and select behaviour according to Richard W. Stevens Network Programming book. Reviewed-by: Jay Satiro Reviewed-by: Marcel Raad Follow up to #5634 Closes #5867
* Curl_pgrsTime - return new time to avoid timeout integer overflowDaniel Stenberg2020-08-281-17/+17
| | | | | | | | | | | | | | Setting a timeout to INT_MAX could cause an immediate error to get returned as timeout because of an overflow when different values of 'now' were used. This is primarily fixed by having Curl_pgrsTime() return the "now" when TIMER_STARTSINGLE is set so that the parent function will continue using that time. Reported-by: Ionuț-Francisc Oancea Fixes #5583 Closes #5847
* multi: expand pre-check for socket readinessMarc Hoersken2020-08-251-38/+34
| | | | | | | | | | | | Check readiness of all sockets before waiting on them to avoid locking in case the one-time event FD_WRITE was already consumed by a previous wait operation. More information about WinSock network events: https://docs.microsoft.com/en-us/windows/win32/api/ winsock2/nf-winsock2-wsaeventselect#return-value Closes #5634
* multi: implement wait using winsock eventsrcombs2020-08-251-6/+154
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This avoids using a pair of TCP ports to provide wakeup functionality for every multi instance on Windows, where socketpair() is emulated using a TCP socket on loopback which could in turn lead to socket resource exhaustion. A previous version of this patch failed to account for how in WinSock, FD_WRITE is set only once when writing becomes possible and not again until after a send has failed due to the buffer filling. This contrasts to how FD_READ and FD_OOB continue to be set until the conditions they refer to no longer apply. This meant that if a user wrote some data to a socket, but not enough data to completely fill its send buffer, then waited on that socket to become writable, we'd erroneously stall until their configured timeout rather than returning immediately. This version of the patch addresses that issue by checking each socket we're waiting on to become writable with select() before the wait, and zeroing the timeout if it's already writable. Assisted-by: Marc Hörsken Reviewed-by: Marcel Raad Reviewed-by: Daniel Stenberg Tested-by: Gergely Nagy Tested-by: Rasmus Melchior Jacobsen Tested-by: Tomas Berger Replaces #5397 Reverts #5632 Closes #5634
* Curl_easy: remember last connection by id, not by pointerDaniel Stenberg2020-08-171-4/+5
| | | | | | | | | CVE-2020-8231 Bug: https://curl.haxx.se/docs/CVE-2020-8231.html Reported-by: Marc Aldorasi Closes #5824
* multi: Remove 10-year old out-commented codeEmil Engler2020-08-121-13/+0
| | | | | | The code hasn't been touched since 2010-08-18 Closes #5805
* multi: Condition 'extrawait' is always trueDaniel Stenberg2020-08-011-1/+1
| | | | | | | Reported by Codacy. Reviewed-by: Marcel Raad Closes #5759
* multi_remove_handle: close unused connect-only connectionsMarc Aldorasi2020-08-011-4/+30
| | | | | | | | | Previously any connect-only connections in a multi handle would be kept alive until the multi handle was closed. Since these connections cannot be re-used, they can be marked for closure when the associated easy handle is removed from the multi handle. Closes #5749
* curl_multi_setopt: fix compiler warning "result is always false"Daniel Stenberg2020-07-281-3/+1
| | | | | | | | | On systems with 32 bit long the expression is always false. Avoid the warning. Reported-by: Gisle Vanem Bug: https://github.com/curl/curl/commit/61a08508f6a458fe21bbb18cd2a9bac2f039452b#commitcomment-40941232 Closes #5736
* multi: remove two checks always trueDaniel Stenberg2020-07-141-2/+2
| | | | | Detected by Codacy Closes #5676
* Revert "multi: implement wait using winsock events"Daniel Stenberg2020-06-301-118/+4
| | | | | | | | | | This reverts commit 8bc25c590e530de87595d1bb3577f699eb1309b9. That commit (from #5397) introduced a regression in 7.71.0. Reported-by: tmkk on github Fixes #5631 Closes #5632