summaryrefslogtreecommitdiff
path: root/lib/asyn-thread.c
Commit message (Collapse)AuthorAgeFilesLines
* CURLOPT_IPRESOLVE: preventing wrong IP version from being usedLucas Clemente Vella2021-05-201-17/+2
| | | | | | | | | | | | | | | | | | | In some situations, it was possible that a transfer was setup to use an specific IP version, but due do DNS caching or connection reuse, it ended up using a different IP version from requested. This commit changes the effect of CURLOPT_IPRESOLVE from simply restricting address resolution to preventing the wrong connection type being used, when choosing a connection from the pool, and to restricting what addresses could be used when establishing a new connection. It is important that all addresses versions are resolved, even if not used in that transfer in particular, because the result is cached, and could be useful for a different transfer with a different CURLOPT_IPRESOLVE setting. Closes #6853
* tidy-up: make conditional checks more consistentDaniel Stenberg2021-04-221-2/+2
| | | | | | ... remove '== NULL' and '!= 0' Closes #6912
* asyn-ares: use consistent resolve error messageDaniel Stenberg2021-02-181-31/+2
| | | | | | | | | | | ... with the help of Curl_resolver_error() which now is moved from asyn-thead.c and is provided globally for this purpose. Follow-up to 35ca04ce1b77636 Makes test 1188 work for c-ares builds Closes #6626
* lib: drop USE_SOCKETPAIR in favor of CURL_DISABLE_SOCKETPAIRJay Satiro2021-02-091-10/+10
| | | | | | .. since the former is undocumented and they both do the same thing. Closes https://github.com/curl/curl/pull/6517
* asyn-thread: fix build for when getaddrinfo missingJay Satiro2021-01-271-1/+1
| | | | | | | | This is a follow-up to 8315343 which several days ago moved the resolver pointer into the async struct but did not update the code that uses it when getaddrinfo is not present. Closes https://github.com/curl/curl/pull/6536
* hostip/proxy: remove conn->data useDaniel Stenberg2021-01-261-1/+1
| | | | Closes #6513
* hostip: remove conn->data from resolver functionsDaniel Stenberg2021-01-221-69/+66
| | | | | | | 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-2/+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
* lib: pass in 'struct Curl_easy *' to most functionsDaniel Stenberg2021-01-171-2/+2
| | | | | | | | | | | | | | | | | | | | | ... 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
* failf: remove newline from formatting stringsDaniel Stenberg2020-12-251-2/+2
| | | | | | | | | ... as failf adds one itself. Also: add an assert() to failf() that triggers on a newline in the format string! Closes #6365
* asyn: use 'struct thread_data *' instead of 'void *'Daniel Stenberg2020-11-231-12/+12
| | | | | | | | | | To reduce use of types that can't be checked at compile time. Also removes several typecasts. ... and rename the struct field from 'os_specific' to 'tdata'. Closes #6239 Reviewed-by: Jay Satiro
* curl.se: new homeDaniel Stenberg2020-11-041-1/+1
| | | | Closes #6172
* build: disable more code/data when built without proxy supportDaniel Stenberg2020-05-301-1/+4
| | | | | | Added build to travis to verify Closes #5466
* timeouts: change millisecond timeouts to timediff_t from time_tDaniel Stenberg2020-05-301-5/+5
| | | | | | | For millisecond timers we like timediff_t better. Also, time_t can be unsigned so returning a negative value doesn't work then. Closes #5479
* source cleanup: remove all custom typedef structsDaniel Stenberg2020-05-151-9/+9
| | | | | | | | | | | - Stick to a single unified way to use structs - Make checksrc complain on 'typedef struct {' - Allow them in tests, public headers and examples - Let MD4_CTX, MD5_CTX, and SHA256_CTX typedefs remain as they actually typedef different types/structs depending on build conditions. Closes #5338
* checksrc: enhance the ASTERISKSPACE and update code accordinglyDaniel Stenberg2020-05-141-3/+3
| | | | | | | | Fine: "struct hello *world" Not fine: "struct hello* world" (and variations) Closes #5386
* asyn-*: remove support for never-used NULL entry pointersDaniel Stenberg2020-05-031-4/+6
| | | | | | | ... and instead convert those to asserts to make sure they are truly never NULL. Closes #5324
* asyn-thread: fix cppcheck warningJay Satiro2020-05-021-2/+4
| | | | | | | | | | | | | | | - Check for NULL entry parameter before attempting to deref entry in Curl_resolver_is_resolved, like is already done in asyn-ares. This is to silence cppcheck which does not seem to understand that asyn-ares and asyn-thread have separate Curl_resolver_is_resolved and those units are mutually exclusive. Prior to this change it warned of a scenario where asyn-thread's Curl_resolver_is_resolved is called with a NULL entry from asyn-ares, but that couldn't happen. Reported-by: rl1987@users.noreply.github.com Fixes https://github.com/curl/curl/issues/5326
* asyn-thread: remove dead codeJay Satiro2020-02-091-3/+0
|
* global_init: move the IPv6 works status bool to multi handleDaniel Stenberg2020-01-281-1/+1
| | | | | | | | | Previously it was stored in a global state which contributed to curl_global_init's thread unsafety. This boolean is now instead figured out in curl_multi_init() and stored in the multi handle. Less effective, but thread safe. Closes #4851
* fix: Copyright year out of date, should be 2020Daniel Stenberg2020-01-101-1/+1
| | | | Follow-up to 875314ed0bf3b
* hostip: move code to resolve IP address literals to `Curl_resolv`Marcel Raad2020-01-101-35/+0
| | | | | | | | | | | | | | | | The code was duplicated in the various resolver backends. Also, it was called after the call to `Curl_ipvalid`, which matters in case of `CURLRES_IPV4` when called from `connect.c:bindlocal`. This caused test 1048 to fail on classic MinGW. The code ignores `conn->ip_version` as done previously in the individual resolver backends. Move the call to the `resolver_start` callback up to appease test 655, which wants it to be called also for literal addresses. Closes https://github.com/curl/curl/pull/4798
* lib: remove erroneous +x file permission on some c filesXiang Xiao2019-12-271-0/+0
| | | | | | Modified by commit eb9a604 accidentally. Closes https://github.com/curl/curl/pull/4756
* curl_setup: disable IPv6 resolver without `getaddrinfo`Marcel Raad2019-12-031-2/+12
| | | | | | | | | | Also, use `CURLRES_IPV6` only for actual DNS resolution, not for IPv6 address support. This makes it possible to connect to IPv6 literals by setting `ENABLE_IPV6` even without `getaddrinfo` support. It also fixes the CMake build when using the synchronous resolver without `getaddrinfo` support. Closes https://github.com/curl/curl/pull/4662
* asyn-thread: make use of Curl_socketpair() where availableDaniel Stenberg2019-10-101-12/+14
|
* asyn-thread: s/AF_LOCAL/AF_UNIX for SolarisDaniel Stenberg2019-09-121-2/+2
| | | | | | Reported-by: Dagobert Michelsen Fixes #4328 Closes #4333
* asyn-thread: issue CURL_POLL_REMOVE before closing socketEric Wong2019-08-111-5/+20
| | | | | | | | | | | | This avoids EBADF errors from EPOLL_CTL_DEL operations in the ephiperfifo.c example. EBADF is dangerous in multi-threaded applications where I rely on epoll_ctl to operate on the same epoll description from different threads. Follow-up to eb9a604f8d7db8 Bug: https://curl.haxx.se/mail/lib-2019-08/0026.html Closes #4211
* timediff: make it 64 bit (if possible) even with 32 bit time_tDaniel Stenberg2019-08-011-3/+4
| | | | | | | ... to make it hold microseconds too. Fixes #4165 Closes #4168
* cleanup: remove the 'numsocks' argument used in many placesDaniel Stenberg2019-07-301-3/+1
| | | | | | | | | It was used (intended) to pass in the size of the 'socks' array that is also passed to these functions, but was rarely actually checked/used and the array is defined to a fixed size of MAX_SOCKSPEREASYHANDLE entries that should be used instead. Closes #4169
* asyn-thread: removed unused variableDaniel Stenberg2019-07-301-2/+1
| | | | | Follow-up to eb9a604f. Mistake caused by me when I edited the commit before push...
* asyn-thread: create a socketpair to wait onamkatyal2019-07-301-11/+65
| | | | Closes #4157
* HTTP3: initial (experimental) supportDaniel Stenberg2019-07-211-1/+2
| | | | | | | | | USe configure --with-ngtcp2 or --with-quiche Using either option will enable a HTTP3 build. Co-authored-by: Alessandro Ghedini <alessandro@ghedini.me> Closes #3500
* threaded-resolver: shutdown the resolver thread without error messageDaniel Stenberg2019-03-011-30/+38
| | | | | | | | | | | | When a transfer is done, the resolver thread will be brought down. That could accidentally generate an error message in the error buffer even though this is not an error situationand the transfer would still return OK. An application that still reads the error buffer could find a "Could not resolve host: [host name]" message there and get confused. Reported-by: Michael Schmid Fixes #3629 Closes #3630
* curl_multi_remove_handle() don't block terminating c-ares requestsBrad Spencer2019-01-071-2/+23
| | | | | | | | | 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
* snprintf: renamed and we now only use msnprintf()Daniel Stenberg2018-11-231-2/+2
| | | | | | | | | | | 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-3/+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
* asyn-thread: Remove unused macroRikard Falkeborn2018-08-091-2/+0
| | | | | | The macro seems to never have been used. Closes #2852
* easy_perform: use *multi_timeout() to get wait timesDaniel Stenberg2018-06-271-3/+3
| | | | | | | | | ... and trim the threaded Curl_resolver_getsock() to return zero millisecond wait times during the first three milliseconds so that localhost or names in the OS resolver cache gets detected and used faster. Closes #2685
* multi: fix memory leak when stopped during name resolveDaniel Stenberg2018-06-161-2/+4
| | | | | | | | | | | | 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
* threaded resolver: track resolver time and set suitable timeout valuesDaniel Stenberg2018-03-241-28/+39
| | | | | | | | | | In order to make curl_multi_timeout() return suitable "sleep" times even when there's no socket to wait for while the name is being resolved in a helper thread. It will increases the timeouts as time passes. Closes #2419
* time: rename Curl_tvnow to Curl_nowDaniel Stenberg2017-10-251-1/+1
| | | | | | | | | | ... since the 'tv' stood for timeval and this function does not return a timeval struct anymore. Also, cleaned up the Curl_timediff*() functions to avoid typecasts and clean up the descriptive comments. Closes #2011
* timediff: return timediff_t from the time diff functionsDaniel Stenberg2017-10-251-1/+2
| | | | | | | | | | | | | | | ... to cater for systems with unsigned time_t variables. - Renamed the functions to curlx_timediff and Curl_timediff_us. - Added overflow protection for both of them in either direction for both 32 bit and 64 bit time_ts - Reprefixed the curlx_time functions to use Curl_* Reported-by: Peter Piekarski Fixes #2004 Closes #2005
* asyn-thread: Fixed cleanup after OOMDan Fandrich2017-08-291-0/+9
| | | | | | | | | destroy_async_data() assumes that if the flag "done" is not set yet, the thread itself will clean up once the request is complete. But if an error (generally OOM) occurs before the thread even has a chance to start, it will never get a chance to clean up and memory will be leaked. By clearing "done" only just before starting the thread, the correct cleanup sequence will happen in all cases.
* asyn-thread: Improved cleanup after OOM situationsDan Fandrich2017-08-281-3/+7
|
* asyn-thread: Set errno to the proper value ENOMEM in OOM situationDan Fandrich2017-08-281-1/+1
| | | | | This used to be set in some configurations to EAI_MEMORY which is not a valid value for errno and caused Curl_strerror to fail an assertion.
* curl_setup_once: Remove ERRNO/SET_ERRNO macrosJay Satiro2017-07-101-5/+2
| | | | | | | | | | | | Prior to this change (SET_)ERRNO mapped to GetLastError/SetLastError for Win32 and regular errno otherwise. I reviewed the code and found no justifiable reason for conflating errno on WIN32 with GetLastError/SetLastError. All Win32 CRTs support errno, and any Win32 multithreaded CRT supports thread-local errno. Fixes https://github.com/curl/curl/issues/895 Closes https://github.com/curl/curl/pull/1589
* asyn-thread.c: fix unused variable warnings on macOSDaniel Stenberg2017-07-061-13/+14
|
* multi: use a fixed array of timers instead of mallocDaniel Stenberg2017-05-101-2/+2
| | | | | | | | | | ... since the total amount is low this is faster, easier and reduces memory overhead. Also, Curl_expire_done() can now mark an expire timeout as done so that it never times out. Closes #1472
* asyn-thread: fix unused macro warningsMarcel Raad2017-05-071-5/+5
| | | | Don't do anything in this file if CURLRES_THREADED is not defined.
* checksrc: stricter no-space-before-paren enforcementDaniel Stenberg2016-12-131-6/+6
| | | | In order to make the code style more uniform everywhere