summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2020-11-23 14:54:10 +0100
committerDaniel Stenberg <daniel@haxx.se>2020-11-23 22:54:18 +0100
commit37cdc2a05c964a7212848149725e8072741f4213 (patch)
treeb55645c0e67f8d561b67a903fc04b9c43ada855f
parent3e092adf673ead8b25167df9583ac6ac1ba77261 (diff)
downloadcurl-37cdc2a05c964a7212848149725e8072741f4213.tar.gz
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
-rw-r--r--lib/asyn-ares.c23
-rw-r--r--lib/asyn-thread.c24
-rw-r--r--lib/urldata.h2
3 files changed, 24 insertions, 25 deletions
diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c
index 96ef1ef9c..174757188 100644
--- a/lib/asyn-ares.c
+++ b/lib/asyn-ares.c
@@ -85,7 +85,7 @@
#include "curl_memory.h"
#include "memdebug.h"
-struct ResolverResults {
+struct thread_data {
int num_pending; /* number of ares_gethostbyname() requests */
struct Curl_addrinfo *temp_ai; /* intermediary result while fetching c-ares
parts */
@@ -229,8 +229,8 @@ static void destroy_async_data(struct Curl_async *async)
{
free(async->hostname);
- if(async->os_specific) {
- struct ResolverResults *res = (struct ResolverResults *)async->os_specific;
+ if(async->tdata) {
+ struct thread_data *res = async->tdata;
if(res) {
if(res->temp_ai) {
Curl_freeaddrinfo(res->temp_ai);
@@ -238,7 +238,7 @@ static void destroy_async_data(struct Curl_async *async)
}
free(res);
}
- async->os_specific = NULL;
+ async->tdata = NULL;
}
async->hostname = NULL;
@@ -349,8 +349,7 @@ CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
struct Curl_dns_entry **dns)
{
struct Curl_easy *data = conn->data;
- struct ResolverResults *res = (struct ResolverResults *)
- conn->async.os_specific;
+ struct thread_data *res = conn->async.tdata;
CURLcode result = CURLE_OK;
DEBUGASSERT(dns);
@@ -498,7 +497,7 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
}
/* 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_tail;
@@ -527,7 +526,7 @@ static void query_completed_cb(void *arg, /* (struct connectdata *) */
struct hostent *hostent)
{
struct connectdata *conn = (struct connectdata *)arg;
- struct ResolverResults *res;
+ struct thread_data *res;
#ifdef HAVE_CARES_CALLBACK_TIMEOUTS
(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! */
return;
- res = (struct ResolverResults *)conn->async.os_specific;
+ res = conn->async.tdata;
if(res) {
res->num_pending--;
@@ -653,20 +652,20 @@ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
bufp = strdup(hostname);
if(bufp) {
- struct ResolverResults *res = NULL;
+ struct thread_data *res = NULL;
free(conn->async.hostname);
conn->async.hostname = bufp;
conn->async.port = port;
conn->async.done = FALSE; /* not done */
conn->async.status = 0; /* clear */
conn->async.dns = NULL; /* clear */
- res = calloc(sizeof(struct ResolverResults), 1);
+ res = calloc(sizeof(struct thread_data), 1);
if(!res) {
free(conn->async.hostname);
conn->async.hostname = NULL;
return NULL;
}
- conn->async.os_specific = res;
+ conn->async.tdata = res;
/* initial status - failed */
res->last_status = ARES_ENOTFOUND;
diff --git a/lib/asyn-thread.c b/lib/asyn-thread.c
index e17e4f802..7c8598274 100644
--- a/lib/asyn-thread.c
+++ b/lib/asyn-thread.c
@@ -185,7 +185,7 @@ struct thread_data {
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 */
@@ -294,7 +294,7 @@ static int getaddrinfo_complete(struct connectdata *conn)
*/
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;
char service[12];
int rc;
@@ -380,8 +380,8 @@ static unsigned int CURL_STDCALL gethostbyname_thread(void *arg)
*/
static void destroy_async_data(struct Curl_async *async)
{
- if(async->os_specific) {
- struct thread_data *td = (struct thread_data*) async->os_specific;
+ if(async->tdata) {
+ struct thread_data *td = async->tdata;
int done;
#ifdef USE_SOCKETPAIR
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);
- free(async->os_specific);
+ free(async->tdata);
}
#ifdef USE_SOCKETPAIR
/*
@@ -418,7 +418,7 @@ static void destroy_async_data(struct Curl_async *async)
sclose(sock_rd);
#endif
}
- async->os_specific = NULL;
+ async->tdata = NULL;
free(async->hostname);
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));
int err = ENOMEM;
- conn->async.os_specific = (void *)td;
+ conn->async.tdata = td;
if(!td)
goto errno_exit;
@@ -448,7 +448,7 @@ static bool init_resolve_thread(struct connectdata *conn,
td->thread_hnd = curl_thread_t_null;
if(!init_thread_sync_data(td, hostname, port, hints)) {
- conn->async.os_specific = NULL;
+ conn->async.tdata = NULL;
free(td);
goto errno_exit;
}
@@ -519,7 +519,7 @@ static CURLcode thread_wait_resolv(struct connectdata *conn,
struct Curl_dns_entry **entry,
bool report)
{
- struct thread_data *td = (struct thread_data*) conn->async.os_specific;
+ struct thread_data *td = conn->async.tdata;
CURLcode result = CURLE_OK;
DEBUGASSERT(conn && td);
@@ -557,7 +557,7 @@ static CURLcode thread_wait_resolv(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,
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_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;
DEBUGASSERT(entry);
@@ -656,7 +656,7 @@ int Curl_resolver_getsock(struct connectdata *conn,
struct Curl_easy *data = conn->data;
struct resdata *reslv = (struct resdata *)data->state.resolver;
#ifdef USE_SOCKETPAIR
- struct thread_data *td = (struct thread_data*)conn->async.os_specific;
+ struct thread_data *td = conn->async.tdata;
#else
(void)socks;
#endif
diff --git a/lib/urldata.h b/lib/urldata.h
index 805957153..f085c093c 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -519,7 +519,7 @@ struct Curl_async {
int port;
struct Curl_dns_entry *dns;
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 */
};