1
0
mirror of https://github.com/moparisthebest/curl synced 2025-03-03 18:59:46 -05:00

asyn: use 'struct thread_data *' instead of 'void *'

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
This commit is contained in:
Daniel Stenberg 2020-11-23 14:54:10 +01:00
parent 3e092adf67
commit 37cdc2a05c
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
3 changed files with 24 additions and 25 deletions

View File

@ -85,7 +85,7 @@
#include "curl_memory.h" #include "curl_memory.h"
#include "memdebug.h" #include "memdebug.h"
struct ResolverResults { struct thread_data {
int num_pending; /* number of ares_gethostbyname() requests */ int num_pending; /* number of ares_gethostbyname() requests */
struct Curl_addrinfo *temp_ai; /* intermediary result while fetching c-ares struct Curl_addrinfo *temp_ai; /* intermediary result while fetching c-ares
parts */ parts */
@ -229,8 +229,8 @@ static void destroy_async_data(struct Curl_async *async)
{ {
free(async->hostname); free(async->hostname);
if(async->os_specific) { if(async->tdata) {
struct ResolverResults *res = (struct ResolverResults *)async->os_specific; struct thread_data *res = async->tdata;
if(res) { if(res) {
if(res->temp_ai) { if(res->temp_ai) {
Curl_freeaddrinfo(res->temp_ai); Curl_freeaddrinfo(res->temp_ai);
@ -238,7 +238,7 @@ static void destroy_async_data(struct Curl_async *async)
} }
free(res); free(res);
} }
async->os_specific = NULL; async->tdata = NULL;
} }
async->hostname = NULL; async->hostname = NULL;
@ -349,8 +349,7 @@ CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
struct Curl_dns_entry **dns) struct Curl_dns_entry **dns)
{ {
struct Curl_easy *data = conn->data; struct Curl_easy *data = conn->data;
struct ResolverResults *res = (struct ResolverResults *) struct thread_data *res = conn->async.tdata;
conn->async.os_specific;
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
DEBUGASSERT(dns); DEBUGASSERT(dns);
@ -498,7 +497,7 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
} }
/* Connects results to the list */ /* Connects results to the list */
static void compound_results(struct ResolverResults *res, static void compound_results(struct thread_data *res,
struct Curl_addrinfo *ai) struct Curl_addrinfo *ai)
{ {
struct Curl_addrinfo *ai_tail; struct Curl_addrinfo *ai_tail;
@ -527,7 +526,7 @@ static void query_completed_cb(void *arg, /* (struct connectdata *) */
struct hostent *hostent) struct hostent *hostent)
{ {
struct connectdata *conn = (struct connectdata *)arg; struct connectdata *conn = (struct connectdata *)arg;
struct ResolverResults *res; struct thread_data *res;
#ifdef HAVE_CARES_CALLBACK_TIMEOUTS #ifdef HAVE_CARES_CALLBACK_TIMEOUTS
(void)timeouts; /* ignored */ (void)timeouts; /* ignored */
@ -538,7 +537,7 @@ static void query_completed_cb(void *arg, /* (struct connectdata *) */
be valid so only defer it when we know the 'status' says its fine! */ be valid so only defer it when we know the 'status' says its fine! */
return; return;
res = (struct ResolverResults *)conn->async.os_specific; res = conn->async.tdata;
if(res) { if(res) {
res->num_pending--; res->num_pending--;
@ -653,20 +652,20 @@ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
bufp = strdup(hostname); bufp = strdup(hostname);
if(bufp) { if(bufp) {
struct ResolverResults *res = NULL; struct thread_data *res = NULL;
free(conn->async.hostname); free(conn->async.hostname);
conn->async.hostname = bufp; conn->async.hostname = bufp;
conn->async.port = port; conn->async.port = port;
conn->async.done = FALSE; /* not done */ conn->async.done = FALSE; /* not done */
conn->async.status = 0; /* clear */ conn->async.status = 0; /* clear */
conn->async.dns = NULL; /* clear */ conn->async.dns = NULL; /* clear */
res = calloc(sizeof(struct ResolverResults), 1); res = calloc(sizeof(struct thread_data), 1);
if(!res) { if(!res) {
free(conn->async.hostname); free(conn->async.hostname);
conn->async.hostname = NULL; conn->async.hostname = NULL;
return NULL; return NULL;
} }
conn->async.os_specific = res; conn->async.tdata = res;
/* initial status - failed */ /* initial status - failed */
res->last_status = ARES_ENOTFOUND; res->last_status = ARES_ENOTFOUND;

View File

@ -185,7 +185,7 @@ struct thread_data {
static struct thread_sync_data *conn_thread_sync_data(struct connectdata *conn) static struct thread_sync_data *conn_thread_sync_data(struct connectdata *conn)
{ {
return &(((struct thread_data *)conn->async.os_specific)->tsd); return &(conn->async.tdata->tsd);
} }
/* Destroy resolver thread synchronization data */ /* Destroy resolver thread synchronization data */
@ -294,7 +294,7 @@ static int getaddrinfo_complete(struct connectdata *conn)
*/ */
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_sync_data *tsd = (struct thread_sync_data *)arg;
struct thread_data *td = tsd->td; struct thread_data *td = tsd->td;
char service[12]; char service[12];
int rc; int rc;
@ -380,8 +380,8 @@ static unsigned int CURL_STDCALL gethostbyname_thread(void *arg)
*/ */
static void destroy_async_data(struct Curl_async *async) static void destroy_async_data(struct Curl_async *async)
{ {
if(async->os_specific) { if(async->tdata) {
struct thread_data *td = (struct thread_data*) async->os_specific; struct thread_data *td = async->tdata;
int done; int done;
#ifdef USE_SOCKETPAIR #ifdef USE_SOCKETPAIR
curl_socket_t sock_rd = td->tsd.sock_pair[0]; curl_socket_t sock_rd = td->tsd.sock_pair[0];
@ -406,7 +406,7 @@ static void destroy_async_data(struct Curl_async *async)
destroy_thread_sync_data(&td->tsd); destroy_thread_sync_data(&td->tsd);
free(async->os_specific); free(async->tdata);
} }
#ifdef USE_SOCKETPAIR #ifdef USE_SOCKETPAIR
/* /*
@ -418,7 +418,7 @@ static void destroy_async_data(struct Curl_async *async)
sclose(sock_rd); sclose(sock_rd);
#endif #endif
} }
async->os_specific = NULL; async->tdata = NULL;
free(async->hostname); free(async->hostname);
async->hostname = NULL; async->hostname = NULL;
@ -437,7 +437,7 @@ static bool init_resolve_thread(struct connectdata *conn,
struct thread_data *td = calloc(1, sizeof(struct thread_data)); struct thread_data *td = calloc(1, sizeof(struct thread_data));
int err = ENOMEM; int err = ENOMEM;
conn->async.os_specific = (void *)td; conn->async.tdata = td;
if(!td) if(!td)
goto errno_exit; goto errno_exit;
@ -448,7 +448,7 @@ static bool init_resolve_thread(struct connectdata *conn,
td->thread_hnd = curl_thread_t_null; td->thread_hnd = curl_thread_t_null;
if(!init_thread_sync_data(td, hostname, port, hints)) { if(!init_thread_sync_data(td, hostname, port, hints)) {
conn->async.os_specific = NULL; conn->async.tdata = NULL;
free(td); free(td);
goto errno_exit; goto errno_exit;
} }
@ -519,7 +519,7 @@ static CURLcode thread_wait_resolv(struct connectdata *conn,
struct Curl_dns_entry **entry, struct Curl_dns_entry **entry,
bool report) bool report)
{ {
struct thread_data *td = (struct thread_data*) conn->async.os_specific; struct thread_data *td = conn->async.tdata;
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
DEBUGASSERT(conn && td); DEBUGASSERT(conn && td);
@ -557,7 +557,7 @@ static CURLcode thread_wait_resolv(struct connectdata *conn,
*/ */
void Curl_resolver_kill(struct connectdata *conn) void Curl_resolver_kill(struct connectdata *conn)
{ {
struct thread_data *td = (struct thread_data*) conn->async.os_specific; struct thread_data *td = conn->async.tdata;
/* If we're still resolving, we must wait for the threads to fully clean up, /* If we're still resolving, we must wait for the threads to fully clean up,
unfortunately. Otherwise, we can simply cancel to clean up any resolver unfortunately. Otherwise, we can simply cancel to clean up any resolver
@ -596,7 +596,7 @@ CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
struct Curl_dns_entry **entry) struct Curl_dns_entry **entry)
{ {
struct Curl_easy *data = conn->data; struct Curl_easy *data = conn->data;
struct thread_data *td = (struct thread_data*) conn->async.os_specific; struct thread_data *td = conn->async.tdata;
int done = 0; int done = 0;
DEBUGASSERT(entry); DEBUGASSERT(entry);
@ -656,7 +656,7 @@ int Curl_resolver_getsock(struct connectdata *conn,
struct Curl_easy *data = conn->data; struct Curl_easy *data = conn->data;
struct resdata *reslv = (struct resdata *)data->state.resolver; struct resdata *reslv = (struct resdata *)data->state.resolver;
#ifdef USE_SOCKETPAIR #ifdef USE_SOCKETPAIR
struct thread_data *td = (struct thread_data*)conn->async.os_specific; struct thread_data *td = conn->async.tdata;
#else #else
(void)socks; (void)socks;
#endif #endif

View File

@ -519,7 +519,7 @@ struct Curl_async {
int port; int port;
struct Curl_dns_entry *dns; struct Curl_dns_entry *dns;
int status; /* if done is TRUE, this is the status from the callback */ int status; /* if done is TRUE, this is the status from the callback */
void *os_specific; /* 'struct thread_data' for Windows */ struct thread_data *tdata;
BIT(done); /* set TRUE when the lookup is complete */ BIT(done); /* set TRUE when the lookup is complete */
}; };