mirror of
https://github.com/curl/curl.git
synced 2025-09-11 06:32:41 +03:00
asyn-thread: avoid the separate 'struct resdata' alloc
Instead move the only struct field (start) into the thread_data struct. Closes #16321
This commit is contained in:
parent
d9fc64d3ab
commit
074048ae80
|
@ -78,9 +78,6 @@
|
||||||
#include "curl_memory.h"
|
#include "curl_memory.h"
|
||||||
#include "memdebug.h"
|
#include "memdebug.h"
|
||||||
|
|
||||||
struct resdata {
|
|
||||||
struct curltime start;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Curl_resolver_global_init()
|
* Curl_resolver_global_init()
|
||||||
|
@ -110,9 +107,7 @@ void Curl_resolver_global_cleanup(void)
|
||||||
CURLcode Curl_resolver_init(struct Curl_easy *easy, void **resolver)
|
CURLcode Curl_resolver_init(struct Curl_easy *easy, void **resolver)
|
||||||
{
|
{
|
||||||
(void)easy;
|
(void)easy;
|
||||||
*resolver = calloc(1, sizeof(struct resdata));
|
(void)resolver;
|
||||||
if(!*resolver)
|
|
||||||
return CURLE_OUT_OF_MEMORY;
|
|
||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +119,7 @@ CURLcode Curl_resolver_init(struct Curl_easy *easy, void **resolver)
|
||||||
*/
|
*/
|
||||||
void Curl_resolver_cleanup(void *resolver)
|
void Curl_resolver_cleanup(void *resolver)
|
||||||
{
|
{
|
||||||
free(resolver);
|
(void)resolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -452,6 +447,7 @@ static bool init_resolve_thread(struct Curl_easy *data,
|
||||||
async->status = 0;
|
async->status = 0;
|
||||||
async->dns = NULL;
|
async->dns = NULL;
|
||||||
td->thread_hnd = curl_thread_t_null;
|
td->thread_hnd = curl_thread_t_null;
|
||||||
|
td->start = Curl_now();
|
||||||
|
|
||||||
if(!init_thread_sync_data(td, hostname, port, hints)) {
|
if(!init_thread_sync_data(td, hostname, port, hints)) {
|
||||||
free(td);
|
free(td);
|
||||||
|
@ -646,9 +642,6 @@ CURLcode Curl_resolver_is_resolved(struct Curl_easy *data,
|
||||||
int Curl_resolver_getsock(struct Curl_easy *data, curl_socket_t *socks)
|
int Curl_resolver_getsock(struct Curl_easy *data, curl_socket_t *socks)
|
||||||
{
|
{
|
||||||
int ret_val = 0;
|
int ret_val = 0;
|
||||||
timediff_t milli;
|
|
||||||
timediff_t ms;
|
|
||||||
struct resdata *reslv = (struct resdata *)data->state.async.resolver;
|
|
||||||
#ifndef CURL_DISABLE_SOCKETPAIR
|
#ifndef CURL_DISABLE_SOCKETPAIR
|
||||||
struct thread_data *td = &data->state.async.thdata;
|
struct thread_data *td = &data->state.async.thdata;
|
||||||
#endif
|
#endif
|
||||||
|
@ -668,14 +661,13 @@ int Curl_resolver_getsock(struct Curl_easy *data, curl_socket_t *socks)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifndef CURL_DISABLE_SOCKETPAIR
|
#ifndef CURL_DISABLE_SOCKETPAIR
|
||||||
if(td) {
|
|
||||||
/* return read fd to client for polling the DNS resolution status */
|
/* return read fd to client for polling the DNS resolution status */
|
||||||
socks[socketi] = td->tsd.sock_pair[0];
|
socks[socketi] = td->tsd.sock_pair[0];
|
||||||
ret_val |= GETSOCK_READSOCK(socketi);
|
ret_val |= GETSOCK_READSOCK(socketi);
|
||||||
}
|
#else
|
||||||
else {
|
{
|
||||||
#endif
|
timediff_t milli;
|
||||||
ms = Curl_timediff(Curl_now(), reslv->start);
|
timediff_t ms = Curl_timediff(Curl_now(), td->start);
|
||||||
if(ms < 3)
|
if(ms < 3)
|
||||||
milli = 0;
|
milli = 0;
|
||||||
else if(ms <= 50)
|
else if(ms <= 50)
|
||||||
|
@ -685,11 +677,9 @@ int Curl_resolver_getsock(struct Curl_easy *data, curl_socket_t *socks)
|
||||||
else
|
else
|
||||||
milli = 200;
|
milli = 200;
|
||||||
Curl_expire(data, milli, EXPIRE_ASYNC_NAME);
|
Curl_expire(data, milli, EXPIRE_ASYNC_NAME);
|
||||||
#ifndef CURL_DISABLE_SOCKETPAIR
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -702,12 +692,10 @@ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct Curl_easy *data,
|
||||||
int port,
|
int port,
|
||||||
int *waitp)
|
int *waitp)
|
||||||
{
|
{
|
||||||
struct resdata *reslv = (struct resdata *)data->state.async.resolver;
|
struct thread_data *td = &data->state.async.thdata;
|
||||||
|
|
||||||
*waitp = 0; /* default to synchronous response */
|
*waitp = 0; /* default to synchronous response */
|
||||||
|
|
||||||
reslv->start = Curl_now();
|
|
||||||
|
|
||||||
/* fire up a new resolver thread! */
|
/* fire up a new resolver thread! */
|
||||||
if(init_resolve_thread(data, hostname, port, NULL)) {
|
if(init_resolve_thread(data, hostname, port, NULL)) {
|
||||||
*waitp = 1; /* expect asynchronous response */
|
*waitp = 1; /* expect asynchronous response */
|
||||||
|
@ -731,8 +719,6 @@ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct Curl_easy *data,
|
||||||
{
|
{
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
int pf = PF_INET;
|
int pf = PF_INET;
|
||||||
struct resdata *reslv = (struct resdata *)data->state.async.resolver;
|
|
||||||
|
|
||||||
*waitp = 0; /* default to synchronous response */
|
*waitp = 0; /* default to synchronous response */
|
||||||
|
|
||||||
#ifdef CURLRES_IPV6
|
#ifdef CURLRES_IPV6
|
||||||
|
@ -750,7 +736,6 @@ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct Curl_easy *data,
|
||||||
hints.ai_socktype = (data->conn->transport == TRNSPRT_TCP) ?
|
hints.ai_socktype = (data->conn->transport == TRNSPRT_TCP) ?
|
||||||
SOCK_STREAM : SOCK_DGRAM;
|
SOCK_STREAM : SOCK_DGRAM;
|
||||||
|
|
||||||
reslv->start = Curl_now();
|
|
||||||
/* fire up a new resolver thread! */
|
/* fire up a new resolver thread! */
|
||||||
if(init_resolve_thread(data, hostname, port, &hints)) {
|
if(init_resolve_thread(data, hostname, port, &hints)) {
|
||||||
*waitp = 1; /* expect asynchronous response */
|
*waitp = 1; /* expect asynchronous response */
|
||||||
|
|
|
@ -58,6 +58,7 @@ struct thread_data {
|
||||||
curl_thread_t thread_hnd;
|
curl_thread_t thread_hnd;
|
||||||
unsigned int poll_interval;
|
unsigned int poll_interval;
|
||||||
timediff_t interval_end;
|
timediff_t interval_end;
|
||||||
|
struct curltime start;
|
||||||
struct thread_sync_data tsd;
|
struct thread_sync_data tsd;
|
||||||
#if defined(USE_HTTPSRR) && defined(USE_ARES)
|
#if defined(USE_HTTPSRR) && defined(USE_ARES)
|
||||||
struct Curl_https_rrinfo hinfo;
|
struct Curl_https_rrinfo hinfo;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user