Permalink
Browse files

async resolvers: further cleanups

asyn-ares.c and asyn-thread.c are two separate backends that implement
the same (internal) async resolver API for libcurl to use. Backend is
specified at build time.

The internal resolver API is defined in asyn.h for asynch resolvers.
  • Loading branch information...
1 parent 24d84da commit 7de2f9271c68c10ee7057c10741b0406bca6c156 @bagder bagder committed Jan 30, 2011
Showing with 302 additions and 299 deletions.
  1. +10 −11 lib/Makefile.inc
  2. +25 −20 lib/{hostares.c → asyn-ares.c}
  3. +26 −23 lib/{hostthre.c → asyn-thread.c}
  4. +169 −0 lib/asyn.h
  5. +1 −1 lib/connect.c
  6. +3 −3 lib/ftp.c
  7. +39 −0 lib/hostasyn.c
  8. +2 −2 lib/hostip.c
  9. +1 −69 lib/hostip.h
  10. +0 −102 lib/hostsyn.c
  11. +2 −2 lib/multi.c
  12. +2 −2 lib/socks.c
  13. +2 −2 lib/transfer.c
  14. +17 −61 lib/url.c
  15. +3 −1 lib/url.h
View
@@ -15,14 +15,14 @@ CSOURCES = file.c timeval.c base64.c hostip.c progress.c formdata.c \
memdebug.c http_chunks.c strtok.c connect.c llist.c hash.c multi.c \
content_encoding.c share.c http_digest.c md4.c md5.c curl_rand.c \
http_negotiate.c http_ntlm.c inet_pton.c strtoofft.c strerror.c \
- hostares.c hostasyn.c hostip4.c hostip6.c hostsyn.c hostthre.c \
- inet_ntop.c parsedate.c select.c gtls.c sslgen.c tftp.c splay.c \
- strdup.c socks.c ssh.c nss.c qssl.c rawstr.c curl_addrinfo.c \
- socks_gssapi.c socks_sspi.c curl_sspi.c slist.c nonblock.c \
- curl_memrchr.c imap.c pop3.c smtp.c pingpong.c rtsp.c curl_threads.c \
- warnless.c hmac.c polarssl.c curl_rtmp.c openldap.c curl_gethostname.c\
- gopher.c axtls.c idn_win32.c http_negotiate_sspi.c cyassl.c http_proxy.c \
- non-ascii.c
+ hostasyn.c hostip4.c hostip6.c hostsyn.c inet_ntop.c parsedate.c \
+ select.c gtls.c sslgen.c tftp.c splay.c strdup.c socks.c ssh.c nss.c \
+ qssl.c rawstr.c curl_addrinfo.c socks_gssapi.c socks_sspi.c \
+ curl_sspi.c slist.c nonblock.c curl_memrchr.c imap.c pop3.c smtp.c \
+ pingpong.c rtsp.c curl_threads.c warnless.c hmac.c polarssl.c \
+ curl_rtmp.c openldap.c curl_gethostname.c gopher.c axtls.c \
+ idn_win32.c http_negotiate_sspi.c cyassl.c http_proxy.c non-ascii.c \
+ asyn-ares.c asyn-thread.c
HHEADERS = arpa_telnet.h netrc.h file.h timeval.h qssl.h hostip.h \
progress.h formdata.h cookie.h http.h sendf.h ftp.h url.h dict.h \
@@ -36,6 +36,5 @@ HHEADERS = arpa_telnet.h netrc.h file.h timeval.h qssl.h hostip.h \
tftp.h sockaddr.h splay.h strdup.h setup_once.h socks.h ssh.h nssg.h \
curl_base64.h rawstr.h curl_addrinfo.h curl_sspi.h slist.h nonblock.h \
curl_memrchr.h imap.h pop3.h smtp.h pingpong.h rtsp.h curl_threads.h \
- warnless.h curl_hmac.h polarssl.h curl_rtmp.h curl_gethostname.h \
- gopher.h axtls.h cyassl.h http_proxy.h non-ascii.h
-
+ warnless.h curl_hmac.h polarssl.h curl_rtmp.h curl_gethostname.h \
+ gopher.h axtls.h cyassl.h http_proxy.h non-ascii.h asyn.h
@@ -62,6 +62,8 @@
/***********************************************************************
* Only for ares-enabled builds
+ * And only for functions that fulfill the asynch resolver backend API
+ * as defined in asyn.h, nothing else belongs in this file!
**********************************************************************/
#ifdef CURLRES_ARES
@@ -180,10 +182,11 @@ int Curl_resolver_duphandle(void **to, void *from)
}
static void destroy_async_data (struct Curl_async *async);
+
/*
* Cancel all possibly still on-going resolves for this connection.
*/
-void Curl_async_cancel(struct connectdata *conn)
+void Curl_resolver_cancel(struct connectdata *conn)
{
if( conn && conn->data && conn->data->state.resolver )
ares_cancel((ares_channel)conn->data->state.resolver);
@@ -214,17 +217,17 @@ static void destroy_async_data (struct Curl_async *async)
}
/*
- * Curl_resolv_fdset() is called when someone from the outside world (using
+ * Curl_resolver_fdset() is called when someone from the outside world (using
* curl_multi_fdset()) wants to get our fd_set setup and we're talking with
* ares. The caller must make sure that this function is only called when we
* have a working ares channel.
*
* Returns: CURLE_OK always!
*/
-int Curl_resolv_getsock(struct connectdata *conn,
- curl_socket_t *socks,
- int numsocks)
+int Curl_resolver_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks)
{
struct timeval maxtime;
@@ -309,14 +312,14 @@ static int waitperform(struct connectdata *conn, int timeout_ms)
}
/*
- * Curl_is_resolved() is called repeatedly to check if a previous name resolve
- * request has completed. It should also make sure to time-out if the
- * operation seems to take too long.
+ * Curl_resolver_is_resolved() is called repeatedly to check if a previous
+ * name resolve request has completed. It should also make sure to time-out if
+ * the operation seems to take too long.
*
* Returns normal CURLcode errors.
*/
-CURLcode Curl_is_resolved(struct connectdata *conn,
- struct Curl_dns_entry **dns)
+CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
+ struct Curl_dns_entry **dns)
{
struct SessionHandle *data = conn->data;
struct ResolverResults *res = (struct ResolverResults *)
@@ -344,16 +347,18 @@ CURLcode Curl_is_resolved(struct connectdata *conn,
}
/*
- * Curl_wait_for_resolv() waits for a resolve to finish. This function should
- * be avoided since using this risk getting the multi interface to "hang".
+ * Curl_resolver_wait_resolv()
+ *
+ * waits for a resolve to finish. This function should be avoided since using
+ * this risk getting the multi interface to "hang".
*
* If 'entry' is non-NULL, make it point to the resolved dns entry
*
* Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved, and
* CURLE_OPERATION_TIMEDOUT if a time-out occurred.
*/
-CURLcode Curl_wait_for_resolv(struct connectdata *conn,
- struct Curl_dns_entry **entry)
+CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
+ struct Curl_dns_entry **entry)
{
CURLcode rc=CURLE_OK;
struct SessionHandle *data = conn->data;
@@ -388,7 +393,7 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn,
timeout_ms = 1000;
waitperform(conn, timeout_ms);
- Curl_is_resolved(conn,&temp_entry);
+ Curl_resolver_is_resolved(conn,&temp_entry);
if(conn->async.done)
break;
@@ -507,17 +512,17 @@ static void query_completed_cb(void *arg, /* (struct connectdata *) */
}
/*
- * Curl_getaddrinfo() - when using ares
+ * Curl_resolver_getaddrinfo() - when using ares
*
* Returns name information about the given hostname and port number. If
* successful, the 'hostent' is returned and the forth argument will point to
* memory we need to free after use. That memory *MUST* be freed with
* Curl_freeaddrinfo(), nothing else.
*/
-Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
- const char *hostname,
- int port,
- int *waitp)
+Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
+ const char *hostname,
+ int port,
+ int *waitp)
{
char *bufp;
struct SessionHandle *data = conn->data;
@@ -144,10 +144,11 @@ int Curl_resolver_duphandle(void **to, void *from)
}
static void destroy_async_data(struct Curl_async *);
+
/*
* Cancel all possibly still on-going resolves for this connection.
*/
-void Curl_async_cancel(struct connectdata *conn)
+void Curl_resolver_cancel(struct connectdata *conn)
{
destroy_async_data(&conn->async);
}
@@ -374,7 +375,7 @@ static bool init_resolve_thread (struct connectdata *conn,
goto err_exit;
#ifdef WIN32
- /* This socket is only to keep Curl_resolv_fdset() and select() happy;
+ /* This socket is only to keep Curl_resolver_fdset() and select() happy;
* should never become signalled for read since it's unbound but
* Windows needs at least 1 socket in select().
*/
@@ -408,15 +409,17 @@ static bool init_resolve_thread (struct connectdata *conn,
/*
- * Curl_wait_for_resolv() waits for a resolve to finish. This function should
- * be avoided since using this risk getting the multi interface to "hang".
+ * Curl_resolver_wait_resolv()
+ *
+ * waits for a resolve to finish. This function should be avoided since using
+ * this risk getting the multi interface to "hang".
*
* If 'entry' is non-NULL, make it point to the resolved dns entry
*
* This is the version for resolves-in-a-thread.
*/
-CURLcode Curl_wait_for_resolv(struct connectdata *conn,
- struct Curl_dns_entry **entry)
+CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
+ struct Curl_dns_entry **entry)
{
struct thread_data *td = (struct thread_data*) conn->async.os_specific;
struct SessionHandle *data = conn->data;
@@ -458,12 +461,12 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn,
}
/*
- * Curl_is_resolved() is called repeatedly to check if a previous name resolve
- * request has completed. It should also make sure to time-out if the
- * operation seems to take too long.
+ * Curl_resolver_is_resolved() is called repeatedly to check if a previous
+ * name resolve request has completed. It should also make sure to time-out if
+ * the operation seems to take too long.
*/
-CURLcode Curl_is_resolved(struct connectdata *conn,
- struct Curl_dns_entry **entry)
+CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
+ struct Curl_dns_entry **entry)
{
struct SessionHandle *data = conn->data;
struct thread_data *td = (struct thread_data*) conn->async.os_specific;
@@ -513,9 +516,9 @@ CURLcode Curl_is_resolved(struct connectdata *conn,
return CURLE_OK;
}
-int Curl_resolv_getsock(struct connectdata *conn,
- curl_socket_t *socks,
- int numsocks)
+int Curl_resolver_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks)
{
const struct thread_data *td =
(const struct thread_data *) conn->async.os_specific;
@@ -535,10 +538,10 @@ int Curl_resolv_getsock(struct connectdata *conn,
/*
* Curl_getaddrinfo() - for platforms without getaddrinfo
*/
-Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
- const char *hostname,
- int port,
- int *waitp)
+Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
+ const char *hostname,
+ int port,
+ int *waitp)
{
struct in_addr in;
@@ -561,12 +564,12 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
#else /* !HAVE_GETADDRINFO */
/*
- * Curl_getaddrinfo() - for getaddrinfo
+ * Curl_resolver_getaddrinfo() - for getaddrinfo
*/
-Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
- const char *hostname,
- int port,
- int *waitp)
+Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
+ const char *hostname,
+ int port,
+ int *waitp)
{
struct addrinfo hints;
Curl_addrinfo *res;
Oops, something went wrong.

0 comments on commit 7de2f92

Please sign in to comment.