mirror of
https://github.com/moparisthebest/curl
synced 2025-01-11 14:08:07 -05:00
asyn-thread: make use of Curl_socketpair() where available
This commit is contained in:
parent
bc2dbef0af
commit
9c76f694de
@ -21,6 +21,7 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include "curl_setup.h"
|
#include "curl_setup.h"
|
||||||
|
#include "socketpair.h"
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* Only for threaded name resolves builds
|
* Only for threaded name resolves builds
|
||||||
@ -74,6 +75,7 @@
|
|||||||
#include "inet_ntop.h"
|
#include "inet_ntop.h"
|
||||||
#include "curl_threads.h"
|
#include "curl_threads.h"
|
||||||
#include "connect.h"
|
#include "connect.h"
|
||||||
|
#include "socketpair.h"
|
||||||
/* The last 3 #include files should be in this order */
|
/* The last 3 #include files should be in this order */
|
||||||
#include "curl_printf.h"
|
#include "curl_printf.h"
|
||||||
#include "curl_memory.h"
|
#include "curl_memory.h"
|
||||||
@ -163,7 +165,7 @@ struct thread_sync_data {
|
|||||||
char *hostname; /* hostname to resolve, Curl_async.hostname
|
char *hostname; /* hostname to resolve, Curl_async.hostname
|
||||||
duplicate */
|
duplicate */
|
||||||
int port;
|
int port;
|
||||||
#ifdef HAVE_SOCKETPAIR
|
#ifdef USE_SOCKETPAIR
|
||||||
struct connectdata *conn;
|
struct connectdata *conn;
|
||||||
curl_socket_t sock_pair[2]; /* socket pair */
|
curl_socket_t sock_pair[2]; /* socket pair */
|
||||||
#endif
|
#endif
|
||||||
@ -201,7 +203,7 @@ void destroy_thread_sync_data(struct thread_sync_data * tsd)
|
|||||||
if(tsd->res)
|
if(tsd->res)
|
||||||
Curl_freeaddrinfo(tsd->res);
|
Curl_freeaddrinfo(tsd->res);
|
||||||
|
|
||||||
#ifdef HAVE_SOCKETPAIR
|
#ifdef USE_SOCKETPAIR
|
||||||
/*
|
/*
|
||||||
* close one end of the socket pair (may be done in resolver thread);
|
* close one end of the socket pair (may be done in resolver thread);
|
||||||
* the other end (for reading) is always closed in the parent thread.
|
* the other end (for reading) is always closed in the parent thread.
|
||||||
@ -243,9 +245,9 @@ int init_thread_sync_data(struct thread_data * td,
|
|||||||
|
|
||||||
Curl_mutex_init(tsd->mtx);
|
Curl_mutex_init(tsd->mtx);
|
||||||
|
|
||||||
#ifdef HAVE_SOCKETPAIR
|
#ifdef USE_SOCKETPAIR
|
||||||
/* create socket pair, avoid AF_LOCAL since it doesn't build on Solaris */
|
/* create socket pair, avoid AF_LOCAL since it doesn't build on Solaris */
|
||||||
if(socketpair(AF_UNIX, SOCK_STREAM, 0, &tsd->sock_pair[0]) < 0) {
|
if(Curl_socketpair(AF_UNIX, SOCK_STREAM, 0, &tsd->sock_pair[0]) < 0) {
|
||||||
tsd->sock_pair[0] = CURL_SOCKET_BAD;
|
tsd->sock_pair[0] = CURL_SOCKET_BAD;
|
||||||
tsd->sock_pair[1] = CURL_SOCKET_BAD;
|
tsd->sock_pair[1] = CURL_SOCKET_BAD;
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
@ -297,7 +299,7 @@ static unsigned int CURL_STDCALL getaddrinfo_thread(void *arg)
|
|||||||
struct thread_data *td = tsd->td;
|
struct thread_data *td = tsd->td;
|
||||||
char service[12];
|
char service[12];
|
||||||
int rc;
|
int rc;
|
||||||
#ifdef HAVE_SOCKETPAIR
|
#ifdef USE_SOCKETPAIR
|
||||||
char buf[1];
|
char buf[1];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -322,11 +324,11 @@ static unsigned int CURL_STDCALL getaddrinfo_thread(void *arg)
|
|||||||
free(td);
|
free(td);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#ifdef HAVE_SOCKETPAIR
|
#ifdef USE_SOCKETPAIR
|
||||||
if(tsd->sock_pair[1] != CURL_SOCKET_BAD) {
|
if(tsd->sock_pair[1] != CURL_SOCKET_BAD) {
|
||||||
/* DNS has been resolved, signal client task */
|
/* DNS has been resolved, signal client task */
|
||||||
buf[0] = 1;
|
buf[0] = 1;
|
||||||
if(write(tsd->sock_pair[1], buf, sizeof(buf)) < 0) {
|
if(swrite(tsd->sock_pair[1], buf, sizeof(buf)) < 0) {
|
||||||
/* update sock_erro to errno */
|
/* update sock_erro to errno */
|
||||||
tsd->sock_error = SOCKERRNO;
|
tsd->sock_error = SOCKERRNO;
|
||||||
}
|
}
|
||||||
@ -382,7 +384,7 @@ static void destroy_async_data(struct Curl_async *async)
|
|||||||
if(async->os_specific) {
|
if(async->os_specific) {
|
||||||
struct thread_data *td = (struct thread_data*) async->os_specific;
|
struct thread_data *td = (struct thread_data*) async->os_specific;
|
||||||
int done;
|
int done;
|
||||||
#ifdef HAVE_SOCKETPAIR
|
#ifdef USE_SOCKETPAIR
|
||||||
curl_socket_t sock_rd = td->tsd.sock_pair[0];
|
curl_socket_t sock_rd = td->tsd.sock_pair[0];
|
||||||
struct connectdata *conn = td->tsd.conn;
|
struct connectdata *conn = td->tsd.conn;
|
||||||
#endif
|
#endif
|
||||||
@ -407,7 +409,7 @@ static void destroy_async_data(struct Curl_async *async)
|
|||||||
|
|
||||||
free(async->os_specific);
|
free(async->os_specific);
|
||||||
}
|
}
|
||||||
#ifdef HAVE_SOCKETPAIR
|
#ifdef USE_SOCKETPAIR
|
||||||
/*
|
/*
|
||||||
* ensure CURLMOPT_SOCKETFUNCTION fires CURL_POLL_REMOVE
|
* ensure CURLMOPT_SOCKETFUNCTION fires CURL_POLL_REMOVE
|
||||||
* before the FD is invalidated to avoid EBADF on EPOLL_CTL_DEL
|
* before the FD is invalidated to avoid EBADF on EPOLL_CTL_DEL
|
||||||
@ -647,13 +649,13 @@ int Curl_resolver_getsock(struct connectdata *conn,
|
|||||||
timediff_t ms;
|
timediff_t ms;
|
||||||
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 HAVE_SOCKETPAIR
|
#ifdef USE_SOCKETPAIR
|
||||||
struct thread_data *td = (struct thread_data*)conn->async.os_specific;
|
struct thread_data *td = (struct thread_data*)conn->async.os_specific;
|
||||||
#else
|
#else
|
||||||
(void)socks;
|
(void)socks;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_SOCKETPAIR
|
#ifdef USE_SOCKETPAIR
|
||||||
if(td) {
|
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[0] = td->tsd.sock_pair[0];
|
socks[0] = td->tsd.sock_pair[0];
|
||||||
@ -673,7 +675,7 @@ int Curl_resolver_getsock(struct connectdata *conn,
|
|||||||
else
|
else
|
||||||
milli = 200;
|
milli = 200;
|
||||||
Curl_expire(data, milli, EXPIRE_ASYNC_NAME);
|
Curl_expire(data, milli, EXPIRE_ASYNC_NAME);
|
||||||
#ifdef HAVE_SOCKETPAIR
|
#ifdef USE_SOCKETPAIR
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user