diff options
author | deshevoy <deshevoy@yandex-team.ru> | 2022-02-10 16:46:56 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:56 +0300 |
commit | e988f30484abe5fdeedcc7a5d3c226c01a21800c (patch) | |
tree | 0a217b173aabb57b7e51f8a169989b1a3e0309fe /contrib/libs/curl/lib/asyn-thread.c | |
parent | 33ee501c05d3f24036ae89766a858930ae66c548 (diff) | |
download | ydb-e988f30484abe5fdeedcc7a5d3c226c01a21800c.tar.gz |
Restoring authorship annotation for <deshevoy@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/curl/lib/asyn-thread.c')
-rw-r--r-- | contrib/libs/curl/lib/asyn-thread.c | 262 |
1 files changed, 131 insertions, 131 deletions
diff --git a/contrib/libs/curl/lib/asyn-thread.c b/contrib/libs/curl/lib/asyn-thread.c index c49878bb55..5be4d617a0 100644 --- a/contrib/libs/curl/lib/asyn-thread.c +++ b/contrib/libs/curl/lib/asyn-thread.c @@ -23,11 +23,11 @@ #include "curl_setup.h" #include "socketpair.h" -/*********************************************************************** - * Only for threaded name resolves builds - **********************************************************************/ -#ifdef CURLRES_THREADED - +/*********************************************************************** + * Only for threaded name resolves builds + **********************************************************************/ +#ifdef CURLRES_THREADED + #ifdef HAVE_NETINET_IN_H #include <netinet/in.h> #endif @@ -73,16 +73,16 @@ #include "multiif.h" #include "inet_ntop.h" #include "curl_threads.h" -#include "connect.h" +#include "connect.h" #include "socketpair.h" -/* The last 3 #include files should be in this order */ -#include "curl_printf.h" +/* The last 3 #include files should be in this order */ +#include "curl_printf.h" #include "curl_memory.h" #include "memdebug.h" -struct resdata { - struct curltime start; -}; +struct resdata { + struct curltime start; +}; /* Doubly linked list of orphaned thread handles. */ struct thread_list { @@ -158,14 +158,14 @@ void Curl_resolver_global_cleanup(void) * Curl_resolver_init() * Called from curl_easy_init() -> Curl_open() to initialize resolver * URL-state specific environment ('resolver' member of the UrlState - * structure). + * structure). */ -CURLcode Curl_resolver_init(struct Curl_easy *easy, void **resolver) +CURLcode Curl_resolver_init(struct Curl_easy *easy, void **resolver) { - (void)easy; - *resolver = calloc(1, sizeof(struct resdata)); - if(!*resolver) - return CURLE_OUT_OF_MEMORY; + (void)easy; + *resolver = calloc(1, sizeof(struct resdata)); + if(!*resolver) + return CURLE_OUT_OF_MEMORY; return CURLE_OK; } @@ -173,22 +173,22 @@ CURLcode Curl_resolver_init(struct Curl_easy *easy, void **resolver) * Curl_resolver_cleanup() * Called from curl_easy_cleanup() -> Curl_close() to cleanup resolver * URL-state specific environment ('resolver' member of the UrlState - * structure). + * structure). */ void Curl_resolver_cleanup(void *resolver) { - free(resolver); + free(resolver); } /* * Curl_resolver_duphandle() * Called from curl_easy_duphandle() to duplicate resolver URL state-specific - * environment ('resolver' member of the UrlState structure). + * environment ('resolver' member of the UrlState structure). */ -CURLcode Curl_resolver_duphandle(struct Curl_easy *easy, void **to, void *from) +CURLcode Curl_resolver_duphandle(struct Curl_easy *easy, void **to, void *from) { (void)from; - return Curl_resolver_init(easy, to); + return Curl_resolver_init(easy, to); } static void destroy_async_data(struct Curl_async *); @@ -212,8 +212,8 @@ struct thread_sync_data { curl_mutex_t *mtx; int done; - char *hostname; /* hostname to resolve, Curl_async.hostname - duplicate */ + char *hostname; /* hostname to resolve, Curl_async.hostname + duplicate */ int port; #ifdef USE_SOCKETPAIR struct connectdata *conn; @@ -224,7 +224,7 @@ struct thread_sync_data { #ifdef HAVE_GETADDRINFO struct addrinfo hints; #endif - struct thread_data *td; /* for thread-self cleanup */ + struct thread_data *td; /* for thread-self cleanup */ }; struct thread_data { @@ -250,7 +250,7 @@ void destroy_thread_sync_data(struct thread_sync_data *tsd) free(tsd->mtx); } - free(tsd->hostname); + free(tsd->hostname); if(tsd->res) Curl_freeaddrinfo(tsd->res); @@ -264,7 +264,7 @@ void destroy_thread_sync_data(struct thread_sync_data *tsd) sclose(tsd->sock_pair[1]); } #endif - memset(tsd, 0, sizeof(*tsd)); + memset(tsd, 0, sizeof(*tsd)); } /* Initialize resolver thread synchronization data */ @@ -274,17 +274,17 @@ int init_thread_sync_data(struct thread_data *td, int port, const struct addrinfo *hints) { - struct thread_sync_data *tsd = &td->tsd; - + struct thread_sync_data *tsd = &td->tsd; + memset(tsd, 0, sizeof(*tsd)); - tsd->td = td; + tsd->td = td; tsd->port = port; - /* Treat the request as done until the thread actually starts so any early - * cleanup gets done properly. - */ - tsd->done = 1; -#ifdef HAVE_GETADDRINFO + /* Treat the request as done until the thread actually starts so any early + * cleanup gets done properly. + */ + tsd->done = 1; +#ifdef HAVE_GETADDRINFO DEBUGASSERT(hints); tsd->hints = *hints; #else @@ -349,10 +349,10 @@ static int getaddrinfo_complete(struct connectdata *conn) * For builds without ARES, but with ENABLE_IPV6, create a resolver thread * and wait on it. */ -static unsigned int CURL_STDCALL getaddrinfo_thread(void *arg) +static unsigned int CURL_STDCALL getaddrinfo_thread(void *arg) { struct thread_sync_data *tsd = (struct thread_sync_data *)arg; - struct thread_data *td = tsd->td; + struct thread_data *td = tsd->td; struct thread_list *orphan = NULL; char service[12]; int rc; @@ -360,7 +360,7 @@ static unsigned int CURL_STDCALL getaddrinfo_thread(void *arg) char buf[1]; #endif - msnprintf(service, sizeof(service), "%d", tsd->port); + msnprintf(service, sizeof(service), "%d", tsd->port); rc = Curl_getaddrinfo_ex(tsd->hostname, service, &tsd->hints, &tsd->res); @@ -369,19 +369,19 @@ static unsigned int CURL_STDCALL getaddrinfo_thread(void *arg) if(tsd->sock_error == 0) tsd->sock_error = RESOLVER_ENOMEM; } - else { - Curl_addrinfo_set_port(tsd->res, tsd->port); - } + else { + Curl_addrinfo_set_port(tsd->res, tsd->port); + } Curl_mutex_acquire(tsd->mtx); - if(tsd->done) { - /* too late, gotta clean up the mess */ - Curl_mutex_release(tsd->mtx); - destroy_thread_sync_data(tsd); + if(tsd->done) { + /* too late, gotta clean up the mess */ + Curl_mutex_release(tsd->mtx); + destroy_thread_sync_data(tsd); orphan = (struct thread_list *)td->reserved; - free(td); - } - else { + free(td); + } + else { #ifdef USE_SOCKETPAIR if(tsd->sock_pair[1] != CURL_SOCKET_BAD) { /* DNS has been resolved, signal client task */ @@ -392,9 +392,9 @@ static unsigned int CURL_STDCALL getaddrinfo_thread(void *arg) } } #endif - tsd->done = 1; - Curl_mutex_release(tsd->mtx); - } + tsd->done = 1; + Curl_mutex_release(tsd->mtx); + } if(orphan) signal_orphan_is_exiting(orphan); @@ -407,10 +407,10 @@ static unsigned int CURL_STDCALL getaddrinfo_thread(void *arg) /* * gethostbyname_thread() resolves a name and then exits. */ -static unsigned int CURL_STDCALL gethostbyname_thread(void *arg) +static unsigned int CURL_STDCALL gethostbyname_thread(void *arg) { struct thread_sync_data *tsd = (struct thread_sync_data *)arg; - struct thread_data *td = tsd->td; + struct thread_data *td = tsd->td; struct thread_list *orphan = NULL; tsd->res = Curl_ipv4_resolve_r(tsd->hostname, tsd->port); @@ -422,17 +422,17 @@ static unsigned int CURL_STDCALL gethostbyname_thread(void *arg) } Curl_mutex_acquire(tsd->mtx); - if(tsd->done) { - /* too late, gotta clean up the mess */ - Curl_mutex_release(tsd->mtx); - destroy_thread_sync_data(tsd); + if(tsd->done) { + /* too late, gotta clean up the mess */ + Curl_mutex_release(tsd->mtx); + destroy_thread_sync_data(tsd); orphan = (struct thread_list *)td->reserved; - free(td); - } - else { - tsd->done = 1; - Curl_mutex_release(tsd->mtx); - } + free(td); + } + else { + tsd->done = 1; + Curl_mutex_release(tsd->mtx); + } if(orphan) signal_orphan_is_exiting(orphan); @@ -445,11 +445,11 @@ static unsigned int CURL_STDCALL gethostbyname_thread(void *arg) /* * destroy_async_data() cleans up async resolver data and thread handle. */ -static void destroy_async_data(struct Curl_async *async) +static void destroy_async_data(struct Curl_async *async) { if(async->tdata) { struct thread_data *td = async->tdata; - int done; + int done; #ifdef USE_SOCKETPAIR curl_socket_t sock_rd = td->tsd.sock_pair[0]; struct connectdata *conn = td->tsd.conn; @@ -463,9 +463,9 @@ static void destroy_async_data(struct Curl_async *async) * * An orphaned thread does most of its own cleanup, and any remaining * cleanup is handled during global cleanup. - */ + */ - Curl_mutex_acquire(td->tsd.mtx); + Curl_mutex_acquire(td->tsd.mtx); if(!td->tsd.done && td->thread_hnd != curl_thread_t_null) { struct thread_list *orphan = (struct thread_list *)td->reserved; @@ -497,19 +497,19 @@ static void destroy_async_data(struct Curl_async *async) Curl_mutex_release(&orphaned_threads.mutex); } - done = td->tsd.done; - td->tsd.done = 1; + done = td->tsd.done; + td->tsd.done = 1; - Curl_mutex_release(td->tsd.mtx); + Curl_mutex_release(td->tsd.mtx); if(done) { - if(td->thread_hnd != curl_thread_t_null) - Curl_thread_join(&td->thread_hnd); + if(td->thread_hnd != curl_thread_t_null) + Curl_thread_join(&td->thread_hnd); - destroy_thread_sync_data(&td->tsd); + destroy_thread_sync_data(&td->tsd); free(td->reserved); free(td); - } + } #ifdef USE_SOCKETPAIR /* * ensure CURLMOPT_SOCKETFUNCTION fires CURL_POLL_REMOVE @@ -521,8 +521,8 @@ static void destroy_async_data(struct Curl_async *async) #endif } async->tdata = NULL; - - free(async->hostname); + + free(async->hostname); async->hostname = NULL; } @@ -532,16 +532,16 @@ static void destroy_async_data(struct Curl_async *async) * * Returns FALSE in case of failure, otherwise TRUE. */ -static bool init_resolve_thread(struct connectdata *conn, - const char *hostname, int port, - const struct addrinfo *hints) +static bool init_resolve_thread(struct connectdata *conn, + const char *hostname, int port, + const struct addrinfo *hints) { struct thread_data *td = calloc(1, sizeof(struct thread_data)); - int err = ENOMEM; + int err = ENOMEM; conn->async.tdata = td; if(!td) - goto errno_exit; + goto errno_exit; conn->async.port = port; conn->async.done = FALSE; @@ -553,18 +553,18 @@ static bool init_resolve_thread(struct connectdata *conn, if(!td->reserved || !init_thread_sync_data(td, hostname, port, hints)) { conn->async.tdata = NULL; free(td->reserved); - free(td); - goto errno_exit; - } + free(td); + goto errno_exit; + } - free(conn->async.hostname); + free(conn->async.hostname); conn->async.hostname = strdup(hostname); if(!conn->async.hostname) goto err_exit; - /* The thread will set this to 1 when complete. */ - td->tsd.done = 0; - + /* The thread will set this to 1 when complete. */ + td->tsd.done = 0; + #ifdef HAVE_GETADDRINFO td->thread_hnd = Curl_thread_create(getaddrinfo_thread, &td->tsd); #else @@ -572,8 +572,8 @@ static bool init_resolve_thread(struct connectdata *conn, #endif if(td->thread_hnd == curl_thread_t_null) { - /* The thread never started, so mark it as done here for proper cleanup. */ - td->tsd.done = 1; + /* The thread never started, so mark it as done here for proper cleanup. */ + td->tsd.done = 1; err = errno; goto err_exit; } @@ -583,8 +583,8 @@ static bool init_resolve_thread(struct connectdata *conn, err_exit: destroy_async_data(&conn->async); - errno_exit: - errno = err; + errno_exit: + errno = err; return FALSE; } @@ -596,24 +596,24 @@ static bool init_resolve_thread(struct connectdata *conn, static CURLcode resolver_error(struct connectdata *conn) { const char *host_or_proxy; - CURLcode result; - + CURLcode result; + #ifndef CURL_DISABLE_PROXY if(conn->bits.httpproxy) { host_or_proxy = "proxy"; - result = CURLE_COULDNT_RESOLVE_PROXY; + result = CURLE_COULDNT_RESOLVE_PROXY; } else #endif { host_or_proxy = "host"; - result = CURLE_COULDNT_RESOLVE_HOST; + result = CURLE_COULDNT_RESOLVE_HOST; } failf(conn->data, "Could not resolve %s: %s", host_or_proxy, conn->async.hostname); - - return result; + + return result; } /* @@ -624,16 +624,16 @@ static CURLcode thread_wait_resolv(struct connectdata *conn, bool report) { struct thread_data *td = conn->async.tdata; - CURLcode result = CURLE_OK; + CURLcode result = CURLE_OK; DEBUGASSERT(conn && td); DEBUGASSERT(td->thread_hnd != curl_thread_t_null); /* wait for the thread to resolve the name */ - if(Curl_thread_join(&td->thread_hnd)) { - if(entry) - result = getaddrinfo_complete(conn); - } + if(Curl_thread_join(&td->thread_hnd)) { + if(entry) + result = getaddrinfo_complete(conn); + } else DEBUGASSERT(0); @@ -644,14 +644,14 @@ static CURLcode thread_wait_resolv(struct connectdata *conn, if(!conn->async.dns && report) /* a name was not resolved, report error */ - result = resolver_error(conn); + result = resolver_error(conn); destroy_async_data(&conn->async); if(!conn->async.dns && report) - connclose(conn, "asynch resolve failed"); + connclose(conn, "asynch resolve failed"); - return result; + return result; } @@ -699,7 +699,7 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn, CURLcode Curl_resolver_is_resolved(struct connectdata *conn, struct Curl_dns_entry **entry) { - struct Curl_easy *data = conn->data; + struct Curl_easy *data = conn->data; struct thread_data *td = conn->async.tdata; int done = 0; @@ -719,9 +719,9 @@ CURLcode Curl_resolver_is_resolved(struct connectdata *conn, getaddrinfo_complete(conn); if(!conn->async.dns) { - CURLcode result = resolver_error(conn); + CURLcode result = resolver_error(conn); destroy_async_data(&conn->async); - return result; + return result; } destroy_async_data(&conn->async); *entry = conn->async.dns; @@ -745,7 +745,7 @@ CURLcode Curl_resolver_is_resolved(struct connectdata *conn, td->poll_interval = 250; td->interval_end = elapsed + td->poll_interval; - Curl_expire(conn->data, td->poll_interval, EXPIRE_ASYNC_NAME); + Curl_expire(conn->data, td->poll_interval, EXPIRE_ASYNC_NAME); } return CURLE_OK; @@ -756,9 +756,9 @@ int Curl_resolver_getsock(struct connectdata *conn, { int ret_val = 0; timediff_t milli; - timediff_t ms; - struct Curl_easy *data = conn->data; - struct resdata *reslv = (struct resdata *)data->state.resolver; + timediff_t ms; + struct Curl_easy *data = conn->data; + struct resdata *reslv = (struct resdata *)data->state.resolver; #ifdef USE_SOCKETPAIR struct thread_data *td = conn->async.tdata; #else @@ -802,22 +802,22 @@ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn, int port, int *waitp) { - struct Curl_easy *data = conn->data; - struct resdata *reslv = (struct resdata *)data->state.resolver; + struct Curl_easy *data = conn->data; + struct resdata *reslv = (struct resdata *)data->state.resolver; *waitp = 0; /* default to synchronous response */ - reslv->start = Curl_now(); - + reslv->start = Curl_now(); + /* fire up a new resolver thread! */ if(init_resolve_thread(conn, hostname, port, NULL)) { *waitp = 1; /* expect asynchronous response */ return NULL; } - failf(conn->data, "getaddrinfo() thread failed\n"); - - return NULL; + failf(conn->data, "getaddrinfo() thread failed\n"); + + return NULL; } #else /* !HAVE_GETADDRINFO */ @@ -832,12 +832,12 @@ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn, { struct addrinfo hints; int pf = PF_INET; - struct Curl_easy *data = conn->data; - struct resdata *reslv = (struct resdata *)data->state.resolver; + struct Curl_easy *data = conn->data; + struct resdata *reslv = (struct resdata *)data->state.resolver; *waitp = 0; /* default to synchronous response */ -#ifdef CURLRES_IPV6 +#ifdef CURLRES_IPV6 /* * Check if a limited name resolve has been requested. */ @@ -854,7 +854,7 @@ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn, } if((pf != PF_INET) && !Curl_ipv6works(conn)) - /* The stack seems to be a non-IPv6 one */ + /* The stack seems to be a non-IPv6 one */ pf = PF_INET; #endif /* CURLRES_IPV6 */ @@ -863,21 +863,21 @@ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn, hints.ai_socktype = (conn->transport == TRNSPRT_TCP)? SOCK_STREAM : SOCK_DGRAM; - reslv->start = Curl_now(); + reslv->start = Curl_now(); /* fire up a new resolver thread! */ if(init_resolve_thread(conn, hostname, port, &hints)) { *waitp = 1; /* expect asynchronous response */ return NULL; } - failf(data, "getaddrinfo() thread failed to start\n"); - return NULL; + failf(data, "getaddrinfo() thread failed to start\n"); + return NULL; } #endif /* !HAVE_GETADDRINFO */ -CURLcode Curl_set_dns_servers(struct Curl_easy *data, +CURLcode Curl_set_dns_servers(struct Curl_easy *data, char *servers) { (void)data; @@ -886,7 +886,7 @@ CURLcode Curl_set_dns_servers(struct Curl_easy *data, } -CURLcode Curl_set_dns_interface(struct Curl_easy *data, +CURLcode Curl_set_dns_interface(struct Curl_easy *data, const char *interf) { (void)data; @@ -894,7 +894,7 @@ CURLcode Curl_set_dns_interface(struct Curl_easy *data, return CURLE_NOT_BUILT_IN; } -CURLcode Curl_set_dns_local_ip4(struct Curl_easy *data, +CURLcode Curl_set_dns_local_ip4(struct Curl_easy *data, const char *local_ip4) { (void)data; @@ -902,7 +902,7 @@ CURLcode Curl_set_dns_local_ip4(struct Curl_easy *data, return CURLE_NOT_BUILT_IN; } -CURLcode Curl_set_dns_local_ip6(struct Curl_easy *data, +CURLcode Curl_set_dns_local_ip6(struct Curl_easy *data, const char *local_ip6) { (void)data; |