2004-04-26 03:20:11 -04:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2009-04-21 06:26:58 -04:00
|
|
|
* Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2004-04-26 03:20:11 -04:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
|
|
|
* are also available at http://curl.haxx.se/docs/copyright.html.
|
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "setup.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NETDB_H
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ARPA_INET_H
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STDLIB_H
|
2004-10-06 03:50:18 -04:00
|
|
|
#include <stdlib.h> /* required for free() prototypes */
|
2004-04-26 03:20:11 -04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h> /* for the close() proto */
|
|
|
|
#endif
|
2004-10-06 03:50:18 -04:00
|
|
|
#ifdef VMS
|
2004-04-26 03:20:11 -04:00
|
|
|
#include <in.h>
|
|
|
|
#include <inet.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
2006-04-26 13:23:28 -04:00
|
|
|
#ifdef HAVE_PROCESS_H
|
2004-04-26 03:20:11 -04:00
|
|
|
#include <process.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(NETWARE) && defined(__NOVELL_LIBC__))
|
|
|
|
#undef in_addr_t
|
|
|
|
#define in_addr_t unsigned long
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "urldata.h"
|
|
|
|
#include "sendf.h"
|
|
|
|
#include "hostip.h"
|
|
|
|
#include "hash.h"
|
|
|
|
#include "share.h"
|
|
|
|
#include "strerror.h"
|
|
|
|
#include "url.h"
|
2006-04-12 09:54:07 -04:00
|
|
|
#include "multiif.h"
|
2008-11-06 12:19:56 -05:00
|
|
|
#include "inet_pton.h"
|
2004-04-26 03:20:11 -04:00
|
|
|
|
|
|
|
#define _MPRINTF_REPLACE /* use our functions only */
|
|
|
|
#include <curl/mprintf.h>
|
|
|
|
|
2004-04-26 10:03:25 -04:00
|
|
|
#include "inet_ntop.h"
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2009-04-21 07:46:16 -04:00
|
|
|
#include "curl_memory.h"
|
2004-04-26 03:20:11 -04:00
|
|
|
/* The last #include file should be: */
|
|
|
|
#include "memdebug.h"
|
|
|
|
|
2005-10-02 12:52:07 -04:00
|
|
|
#if defined(_MSC_VER) && defined(CURL_NO__BEGINTHREADEX)
|
|
|
|
#pragma message ("No _beginthreadex() available in this RTL")
|
|
|
|
#endif
|
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
/***********************************************************************
|
|
|
|
* Only for Windows threaded name resolves builds
|
|
|
|
**********************************************************************/
|
|
|
|
#ifdef CURLRES_THREADED
|
|
|
|
|
|
|
|
/* This function is used to init a threaded resolve */
|
|
|
|
static bool init_resolve_thread(struct connectdata *conn,
|
|
|
|
const char *hostname, int port,
|
2008-11-01 11:16:47 -04:00
|
|
|
const struct addrinfo *hints);
|
2004-04-26 03:20:11 -04:00
|
|
|
|
|
|
|
#ifdef CURLRES_IPV4
|
|
|
|
#define THREAD_FUNC gethostbyname_thread
|
|
|
|
#define THREAD_NAME "gethostbyname_thread"
|
|
|
|
#else
|
|
|
|
#define THREAD_FUNC getaddrinfo_thread
|
|
|
|
#define THREAD_NAME "getaddrinfo_thread"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct thread_data {
|
|
|
|
HANDLE thread_hnd;
|
|
|
|
unsigned thread_id;
|
|
|
|
DWORD thread_status;
|
2005-02-09 08:06:40 -05:00
|
|
|
curl_socket_t dummy_sock; /* dummy for Curl_resolv_fdset() */
|
2004-10-16 08:59:05 -04:00
|
|
|
HANDLE mutex_waiting; /* marks that we are still waiting for a resolve */
|
|
|
|
HANDLE event_resolved; /* marks that the thread obtained the information */
|
2005-08-29 10:23:53 -04:00
|
|
|
HANDLE event_thread_started; /* marks that the thread has initialized and
|
|
|
|
started */
|
|
|
|
HANDLE mutex_terminate; /* serializes access to flag_terminate */
|
|
|
|
HANDLE event_terminate; /* flag for thread to terminate instead of calling
|
|
|
|
callbacks */
|
2004-04-26 03:20:11 -04:00
|
|
|
#ifdef CURLRES_IPV6
|
|
|
|
struct addrinfo hints;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2005-08-29 10:23:53 -04:00
|
|
|
/* Data for synchronization between resolver thread and its parent */
|
|
|
|
struct thread_sync_data {
|
|
|
|
HANDLE mutex_waiting; /* thread_data.mutex_waiting duplicate */
|
|
|
|
HANDLE mutex_terminate; /* thread_data.mutex_terminate duplicate */
|
|
|
|
HANDLE event_terminate; /* thread_data.event_terminate duplicate */
|
|
|
|
char * hostname; /* hostname to resolve, Curl_async.hostname
|
|
|
|
duplicate */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Destroy resolver thread synchronization data */
|
2005-11-24 15:39:00 -05:00
|
|
|
static
|
2005-08-29 10:23:53 -04:00
|
|
|
void destroy_thread_sync_data(struct thread_sync_data * tsd)
|
|
|
|
{
|
2007-11-05 04:45:09 -05:00
|
|
|
if(tsd->hostname)
|
2005-08-29 10:23:53 -04:00
|
|
|
free(tsd->hostname);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(tsd->event_terminate)
|
2005-08-29 10:23:53 -04:00
|
|
|
CloseHandle(tsd->event_terminate);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(tsd->mutex_terminate)
|
2005-08-29 10:23:53 -04:00
|
|
|
CloseHandle(tsd->mutex_terminate);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(tsd->mutex_waiting)
|
2005-08-29 10:23:53 -04:00
|
|
|
CloseHandle(tsd->mutex_waiting);
|
2007-06-11 00:33:21 -04:00
|
|
|
memset(tsd,0,sizeof(*tsd));
|
2005-08-29 10:23:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize resolver thread synchronization data */
|
2005-11-24 15:39:00 -05:00
|
|
|
static
|
2005-08-29 10:23:53 -04:00
|
|
|
BOOL init_thread_sync_data(struct thread_data * td,
|
2007-06-11 00:33:21 -04:00
|
|
|
const char * hostname,
|
2005-08-29 10:23:53 -04:00
|
|
|
struct thread_sync_data * tsd)
|
|
|
|
{
|
|
|
|
HANDLE curr_proc = GetCurrentProcess();
|
|
|
|
|
2006-10-17 16:34:11 -04:00
|
|
|
memset(tsd, 0, sizeof(*tsd));
|
2007-11-05 04:45:09 -05:00
|
|
|
if(!DuplicateHandle(curr_proc, td->mutex_waiting,
|
2005-08-29 10:23:53 -04:00
|
|
|
curr_proc, &tsd->mutex_waiting, 0, FALSE,
|
|
|
|
DUPLICATE_SAME_ACCESS)) {
|
|
|
|
/* failed to duplicate the mutex, no point in continuing */
|
|
|
|
destroy_thread_sync_data(tsd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-11-05 04:45:09 -05:00
|
|
|
if(!DuplicateHandle(curr_proc, td->mutex_terminate,
|
2005-08-29 10:23:53 -04:00
|
|
|
curr_proc, &tsd->mutex_terminate, 0, FALSE,
|
|
|
|
DUPLICATE_SAME_ACCESS)) {
|
|
|
|
/* failed to duplicate the mutex, no point in continuing */
|
|
|
|
destroy_thread_sync_data(tsd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-11-05 04:45:09 -05:00
|
|
|
if(!DuplicateHandle(curr_proc, td->event_terminate,
|
2005-08-29 10:23:53 -04:00
|
|
|
curr_proc, &tsd->event_terminate, 0, FALSE,
|
|
|
|
DUPLICATE_SAME_ACCESS)) {
|
|
|
|
/* failed to duplicate the event, no point in continuing */
|
|
|
|
destroy_thread_sync_data(tsd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* Copying hostname string because original can be destroyed by parent
|
|
|
|
* thread during gethostbyname execution.
|
|
|
|
*/
|
|
|
|
tsd->hostname = strdup(hostname);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(!tsd->hostname) {
|
2005-08-29 10:23:53 -04:00
|
|
|
/* Memory allocation failed */
|
|
|
|
destroy_thread_sync_data(tsd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* acquire resolver thread synchronization */
|
2005-11-24 15:39:00 -05:00
|
|
|
static
|
2005-08-29 10:23:53 -04:00
|
|
|
BOOL acquire_thread_sync(struct thread_sync_data * tsd)
|
|
|
|
{
|
|
|
|
/* is the thread initiator still waiting for us ? */
|
2007-11-05 04:45:09 -05:00
|
|
|
if(WaitForSingleObject(tsd->mutex_waiting, 0) == WAIT_TIMEOUT) {
|
2005-08-29 10:23:53 -04:00
|
|
|
/* yes, it is */
|
|
|
|
|
|
|
|
/* Waiting access to event_terminate */
|
2007-11-05 04:45:09 -05:00
|
|
|
if(WaitForSingleObject(tsd->mutex_terminate, INFINITE) != WAIT_OBJECT_0) {
|
2005-08-29 10:23:53 -04:00
|
|
|
/* Something went wrong - now just ignoring */
|
|
|
|
}
|
|
|
|
else {
|
2007-11-05 04:45:09 -05:00
|
|
|
if(WaitForSingleObject(tsd->event_terminate, 0) != WAIT_TIMEOUT) {
|
2005-08-29 10:23:53 -04:00
|
|
|
/* Parent thread signaled us to terminate.
|
|
|
|
* This means that all data in conn->async is now destroyed
|
|
|
|
* and we cannot use it.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* release resolver thread synchronization */
|
2005-11-24 15:39:00 -05:00
|
|
|
static
|
2005-08-29 10:23:53 -04:00
|
|
|
void release_thread_sync(struct thread_sync_data * tsd)
|
|
|
|
{
|
|
|
|
ReleaseMutex(tsd->mutex_terminate);
|
|
|
|
}
|
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
#if defined(CURLRES_IPV4)
|
|
|
|
/*
|
2004-06-24 10:39:52 -04:00
|
|
|
* gethostbyname_thread() resolves a name, calls the Curl_addrinfo4_callback
|
2004-04-26 03:20:11 -04:00
|
|
|
* and then exits.
|
|
|
|
*
|
|
|
|
* For builds without ARES/ENABLE_IPV6, create a resolver thread and wait on
|
|
|
|
* it.
|
|
|
|
*/
|
|
|
|
static unsigned __stdcall gethostbyname_thread (void *arg)
|
|
|
|
{
|
|
|
|
struct connectdata *conn = (struct connectdata*) arg;
|
|
|
|
struct thread_data *td = (struct thread_data*) conn->async.os_specific;
|
|
|
|
struct hostent *he;
|
2004-10-16 08:59:05 -04:00
|
|
|
int rc = 0;
|
|
|
|
|
2005-08-29 10:23:53 -04:00
|
|
|
/* Duplicate the passed mutex and event handles.
|
2004-10-16 08:59:05 -04:00
|
|
|
* This allows us to use it even after the container gets destroyed
|
|
|
|
* due to a resolver timeout.
|
|
|
|
*/
|
2005-09-06 11:58:09 -04:00
|
|
|
struct thread_sync_data tsd = { 0,0,0,NULL };
|
2007-06-11 00:33:21 -04:00
|
|
|
|
2007-11-05 04:45:09 -05:00
|
|
|
if(!init_thread_sync_data(td, conn->async.hostname, &tsd)) {
|
2005-08-29 10:23:53 -04:00
|
|
|
/* thread synchronization data initialization failed */
|
2006-04-26 13:23:28 -04:00
|
|
|
return (unsigned)-1;
|
2004-10-16 08:59:05 -04:00
|
|
|
}
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2007-02-16 13:19:35 -05:00
|
|
|
conn->async.status = NO_DATA; /* pending status */
|
|
|
|
SET_SOCKERRNO(conn->async.status);
|
2004-10-16 08:59:05 -04:00
|
|
|
|
2005-08-29 10:23:53 -04:00
|
|
|
/* Signaling that we have initialized all copies of data and handles we
|
|
|
|
need */
|
|
|
|
SetEvent(td->event_thread_started);
|
2004-10-16 08:59:05 -04:00
|
|
|
|
2005-08-29 10:23:53 -04:00
|
|
|
he = gethostbyname (tsd.hostname);
|
2004-10-16 08:59:05 -04:00
|
|
|
|
2005-08-29 10:23:53 -04:00
|
|
|
/* is parent thread waiting for us and are we able to access conn members? */
|
2007-11-05 04:45:09 -05:00
|
|
|
if(acquire_thread_sync(&tsd)) {
|
2005-08-29 10:23:53 -04:00
|
|
|
/* Mark that we have obtained the information, and that we are calling
|
|
|
|
* back with it. */
|
|
|
|
SetEvent(td->event_resolved);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(he) {
|
2005-02-08 07:36:13 -05:00
|
|
|
rc = Curl_addrinfo4_callback(conn, CURL_ASYNC_SUCCESS, he);
|
2004-10-16 08:59:05 -04:00
|
|
|
}
|
|
|
|
else {
|
2007-02-16 13:19:35 -05:00
|
|
|
rc = Curl_addrinfo4_callback(conn, SOCKERRNO, NULL);
|
2004-10-16 08:59:05 -04:00
|
|
|
}
|
2005-08-29 10:23:53 -04:00
|
|
|
release_thread_sync(&tsd);
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
2004-10-16 08:59:05 -04:00
|
|
|
|
|
|
|
/* clean up */
|
2005-08-29 10:23:53 -04:00
|
|
|
destroy_thread_sync_data(&tsd);
|
2004-10-16 08:59:05 -04:00
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
return (rc);
|
|
|
|
/* An implicit _endthreadex() here */
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(CURLRES_IPV6)
|
|
|
|
|
|
|
|
/*
|
2004-06-24 10:39:52 -04:00
|
|
|
* getaddrinfo_thread() resolves a name, calls Curl_addrinfo6_callback and then
|
2004-04-26 03:20:11 -04:00
|
|
|
* exits.
|
|
|
|
*
|
|
|
|
* For builds without ARES, but with ENABLE_IPV6, create a resolver thread
|
|
|
|
* and wait on it.
|
|
|
|
*/
|
|
|
|
static unsigned __stdcall getaddrinfo_thread (void *arg)
|
|
|
|
{
|
|
|
|
struct connectdata *conn = (struct connectdata*) arg;
|
|
|
|
struct thread_data *td = (struct thread_data*) conn->async.os_specific;
|
2008-10-30 09:45:25 -04:00
|
|
|
Curl_addrinfo *res;
|
2004-04-26 03:20:11 -04:00
|
|
|
char service [NI_MAXSERV];
|
|
|
|
int rc;
|
2005-08-31 02:04:48 -04:00
|
|
|
struct addrinfo hints = td->hints;
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2004-10-16 08:59:05 -04:00
|
|
|
/* Duplicate the passed mutex handle.
|
|
|
|
* This allows us to use it even after the container gets destroyed
|
|
|
|
* due to a resolver timeout.
|
|
|
|
*/
|
2005-09-06 11:58:09 -04:00
|
|
|
struct thread_sync_data tsd = { 0,0,0,NULL };
|
2007-06-11 00:33:21 -04:00
|
|
|
|
2007-11-05 04:45:09 -05:00
|
|
|
if(!init_thread_sync_data(td, conn->async.hostname, &tsd)) {
|
2005-08-29 10:23:53 -04:00
|
|
|
/* thread synchronization data initialization failed */
|
2005-02-08 07:36:13 -05:00
|
|
|
return -1;
|
2004-10-16 08:59:05 -04:00
|
|
|
}
|
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
itoa(conn->async.port, service, 10);
|
|
|
|
|
2007-02-16 13:19:35 -05:00
|
|
|
conn->async.status = NO_DATA; /* pending status */
|
|
|
|
SET_SOCKERRNO(conn->async.status);
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2005-08-29 10:23:53 -04:00
|
|
|
/* Signaling that we have initialized all copies of data and handles we
|
|
|
|
need */
|
|
|
|
SetEvent(td->event_thread_started);
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2008-10-30 09:45:25 -04:00
|
|
|
rc = Curl_getaddrinfo_ex(tsd.hostname, service, &hints, &res);
|
2004-10-16 08:59:05 -04:00
|
|
|
|
2005-08-29 10:23:53 -04:00
|
|
|
/* is parent thread waiting for us and are we able to access conn members? */
|
2007-11-05 04:45:09 -05:00
|
|
|
if(acquire_thread_sync(&tsd)) {
|
2005-08-29 10:23:53 -04:00
|
|
|
/* Mark that we have obtained the information, and that we are calling
|
|
|
|
back with it. */
|
2004-10-16 08:59:05 -04:00
|
|
|
SetEvent(td->event_resolved);
|
|
|
|
|
2007-11-05 04:45:09 -05:00
|
|
|
if(rc == 0) {
|
2005-02-08 07:36:13 -05:00
|
|
|
rc = Curl_addrinfo6_callback(conn, CURL_ASYNC_SUCCESS, res);
|
2004-10-16 08:59:05 -04:00
|
|
|
}
|
|
|
|
else {
|
2007-02-16 13:19:35 -05:00
|
|
|
rc = Curl_addrinfo6_callback(conn, SOCKERRNO, NULL);
|
2004-10-16 08:59:05 -04:00
|
|
|
}
|
2005-08-29 10:23:53 -04:00
|
|
|
release_thread_sync(&tsd);
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
2004-10-16 08:59:05 -04:00
|
|
|
|
|
|
|
/* clean up */
|
2005-08-29 10:23:53 -04:00
|
|
|
destroy_thread_sync_data(&tsd);
|
2004-10-16 08:59:05 -04:00
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
return (rc);
|
|
|
|
/* An implicit _endthreadex() here */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2005-06-14 10:47:21 -04:00
|
|
|
* Curl_destroy_thread_data() cleans up async resolver data and thread handle.
|
2004-04-26 03:20:11 -04:00
|
|
|
* Complementary of ares_destroy.
|
|
|
|
*/
|
2005-04-04 08:30:03 -04:00
|
|
|
void Curl_destroy_thread_data (struct Curl_async *async)
|
2004-04-26 03:20:11 -04:00
|
|
|
{
|
2007-11-05 04:45:09 -05:00
|
|
|
if(async->hostname)
|
2004-04-26 03:20:11 -04:00
|
|
|
free(async->hostname);
|
|
|
|
|
2007-11-05 04:45:09 -05:00
|
|
|
if(async->os_specific) {
|
2004-10-16 08:59:05 -04:00
|
|
|
struct thread_data *td = (struct thread_data*) async->os_specific;
|
|
|
|
curl_socket_t sock = td->dummy_sock;
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2007-11-05 04:45:09 -05:00
|
|
|
if(td->mutex_terminate && td->event_terminate) {
|
2005-08-29 10:23:53 -04:00
|
|
|
/* Signaling resolver thread to terminate */
|
2007-11-05 04:45:09 -05:00
|
|
|
if(WaitForSingleObject(td->mutex_terminate, INFINITE) == WAIT_OBJECT_0) {
|
2005-08-29 10:23:53 -04:00
|
|
|
SetEvent(td->event_terminate);
|
|
|
|
ReleaseMutex(td->mutex_terminate);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Something went wrong - just ignoring it */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-05 04:45:09 -05:00
|
|
|
if(td->mutex_terminate)
|
2005-08-29 10:23:53 -04:00
|
|
|
CloseHandle(td->mutex_terminate);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(td->event_terminate)
|
2005-08-29 10:23:53 -04:00
|
|
|
CloseHandle(td->event_terminate);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(td->event_thread_started)
|
2005-08-29 10:23:53 -04:00
|
|
|
CloseHandle(td->event_thread_started);
|
|
|
|
|
2007-11-05 04:45:09 -05:00
|
|
|
if(sock != CURL_SOCKET_BAD)
|
2004-04-26 03:20:11 -04:00
|
|
|
sclose(sock);
|
2004-10-16 08:59:05 -04:00
|
|
|
|
|
|
|
/* destroy the synchronization objects */
|
2007-11-05 04:45:09 -05:00
|
|
|
if(td->mutex_waiting)
|
2004-10-16 08:59:05 -04:00
|
|
|
CloseHandle(td->mutex_waiting);
|
2005-04-04 08:30:03 -04:00
|
|
|
td->mutex_waiting = NULL;
|
2007-11-05 04:45:09 -05:00
|
|
|
if(td->event_resolved)
|
2004-10-16 08:59:05 -04:00
|
|
|
CloseHandle(td->event_resolved);
|
|
|
|
|
2007-11-05 04:45:09 -05:00
|
|
|
if(td->thread_hnd)
|
2005-06-14 10:47:21 -04:00
|
|
|
CloseHandle(td->thread_hnd);
|
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
free(async->os_specific);
|
|
|
|
}
|
|
|
|
async->hostname = NULL;
|
|
|
|
async->os_specific = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* init_resolve_thread() starts a new thread that performs the actual
|
|
|
|
* resolve. This function returns before the resolve is done.
|
|
|
|
*
|
|
|
|
* Returns FALSE in case of failure, otherwise TRUE.
|
|
|
|
*/
|
|
|
|
static bool init_resolve_thread (struct connectdata *conn,
|
|
|
|
const char *hostname, int port,
|
2008-11-01 11:16:47 -04:00
|
|
|
const struct addrinfo *hints)
|
2004-04-26 03:20:11 -04:00
|
|
|
{
|
|
|
|
struct thread_data *td = calloc(sizeof(*td), 1);
|
2005-08-29 10:23:53 -04:00
|
|
|
HANDLE thread_and_event[2] = {0};
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2007-11-05 04:45:09 -05:00
|
|
|
if(!td) {
|
2007-02-16 13:19:35 -05:00
|
|
|
SET_ERRNO(ENOMEM);
|
2004-04-26 03:20:11 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Curl_safefree(conn->async.hostname);
|
|
|
|
conn->async.hostname = strdup(hostname);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(!conn->async.hostname) {
|
2004-04-26 03:20:11 -04:00
|
|
|
free(td);
|
2007-02-16 13:19:35 -05:00
|
|
|
SET_ERRNO(ENOMEM);
|
2004-04-26 03:20:11 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
conn->async.port = port;
|
|
|
|
conn->async.done = FALSE;
|
|
|
|
conn->async.status = 0;
|
|
|
|
conn->async.dns = NULL;
|
|
|
|
conn->async.os_specific = (void*) td;
|
|
|
|
td->dummy_sock = CURL_SOCKET_BAD;
|
2004-10-16 08:59:05 -04:00
|
|
|
|
|
|
|
/* Create the mutex used to inform the resolver thread that we're
|
|
|
|
* still waiting, and take initial ownership.
|
|
|
|
*/
|
|
|
|
td->mutex_waiting = CreateMutex(NULL, TRUE, NULL);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(td->mutex_waiting == NULL) {
|
2005-04-04 08:30:03 -04:00
|
|
|
Curl_destroy_thread_data(&conn->async);
|
2007-02-16 13:19:35 -05:00
|
|
|
SET_ERRNO(EAGAIN);
|
2004-10-16 08:59:05 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the event that the thread uses to inform us that it's
|
|
|
|
* done resolving. Do not signal it.
|
|
|
|
*/
|
|
|
|
td->event_resolved = CreateEvent(NULL, TRUE, FALSE, NULL);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(td->event_resolved == NULL) {
|
2005-04-04 08:30:03 -04:00
|
|
|
Curl_destroy_thread_data(&conn->async);
|
2007-02-16 13:19:35 -05:00
|
|
|
SET_ERRNO(EAGAIN);
|
2004-10-16 08:59:05 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2005-08-29 10:23:53 -04:00
|
|
|
/* Create the mutex used to serialize access to event_terminated
|
|
|
|
* between us and resolver thread.
|
|
|
|
*/
|
|
|
|
td->mutex_terminate = CreateMutex(NULL, FALSE, NULL);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(td->mutex_terminate == NULL) {
|
2005-08-29 10:23:53 -04:00
|
|
|
Curl_destroy_thread_data(&conn->async);
|
2007-02-16 13:19:35 -05:00
|
|
|
SET_ERRNO(EAGAIN);
|
2005-08-29 10:23:53 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* Create the event used to signal thread that it should terminate.
|
|
|
|
*/
|
|
|
|
td->event_terminate = CreateEvent(NULL, TRUE, FALSE, NULL);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(td->event_terminate == NULL) {
|
2005-08-29 10:23:53 -04:00
|
|
|
Curl_destroy_thread_data(&conn->async);
|
2007-02-16 13:19:35 -05:00
|
|
|
SET_ERRNO(EAGAIN);
|
2005-08-29 10:23:53 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* Create the event used by thread to inform it has initialized its own data.
|
|
|
|
*/
|
|
|
|
td->event_thread_started = CreateEvent(NULL, TRUE, FALSE, NULL);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(td->event_thread_started == NULL) {
|
2005-08-29 10:23:53 -04:00
|
|
|
Curl_destroy_thread_data(&conn->async);
|
2007-02-16 13:19:35 -05:00
|
|
|
SET_ERRNO(EAGAIN);
|
2005-08-29 10:23:53 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-10-16 08:59:05 -04:00
|
|
|
|
2004-11-02 05:12:22 -05:00
|
|
|
#ifdef _WIN32_WCE
|
2004-11-25 11:49:14 -05:00
|
|
|
td->thread_hnd = (HANDLE) CreateThread(NULL, 0,
|
|
|
|
(LPTHREAD_START_ROUTINE) THREAD_FUNC,
|
|
|
|
conn, 0, &td->thread_id);
|
2004-11-02 05:12:22 -05:00
|
|
|
#else
|
2004-04-26 03:20:11 -04:00
|
|
|
td->thread_hnd = (HANDLE) _beginthreadex(NULL, 0, THREAD_FUNC,
|
|
|
|
conn, 0, &td->thread_id);
|
2004-11-02 05:12:22 -05:00
|
|
|
#endif
|
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
#ifdef CURLRES_IPV6
|
2007-02-21 14:03:20 -05:00
|
|
|
DEBUGASSERT(hints);
|
2004-04-26 03:20:11 -04:00
|
|
|
td->hints = *hints;
|
|
|
|
#else
|
|
|
|
(void) hints;
|
|
|
|
#endif
|
|
|
|
|
2007-11-05 04:45:09 -05:00
|
|
|
if(!td->thread_hnd) {
|
2008-08-06 04:05:09 -04:00
|
|
|
#ifndef _WIN32_WCE
|
2007-02-16 13:19:35 -05:00
|
|
|
SET_ERRNO(errno);
|
2006-07-07 03:49:16 -04:00
|
|
|
#endif
|
2005-04-04 08:30:03 -04:00
|
|
|
Curl_destroy_thread_data(&conn->async);
|
2004-04-26 03:20:11 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2005-08-29 10:23:53 -04:00
|
|
|
/* Waiting until the thread will initialize its data or it will exit due errors.
|
|
|
|
*/
|
|
|
|
thread_and_event[0] = td->thread_hnd;
|
|
|
|
thread_and_event[1] = td->event_thread_started;
|
2007-11-05 04:45:09 -05:00
|
|
|
if(WaitForMultipleObjects(sizeof(thread_and_event) /
|
2005-09-16 17:30:08 -04:00
|
|
|
sizeof(thread_and_event[0]),
|
2006-04-26 13:23:28 -04:00
|
|
|
(const HANDLE*)thread_and_event, FALSE,
|
2005-09-16 17:30:08 -04:00
|
|
|
INFINITE) == WAIT_FAILED) {
|
2005-08-29 10:23:53 -04:00
|
|
|
/* The resolver thread has been created,
|
|
|
|
* most probably it works now - ignoring this "minor" error
|
|
|
|
*/
|
|
|
|
}
|
2005-02-09 08:06:40 -05:00
|
|
|
/* This socket is only to keep Curl_resolv_fdset() and select() happy;
|
|
|
|
* should never become signalled for read/write since it's unbound but
|
|
|
|
* Windows needs atleast 1 socket in select().
|
2004-04-26 03:20:11 -04:00
|
|
|
*/
|
|
|
|
td->dummy_sock = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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".
|
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
struct thread_data *td = (struct thread_data*) conn->async.os_specific;
|
|
|
|
struct SessionHandle *data = conn->data;
|
|
|
|
long timeout;
|
2008-08-06 04:05:09 -04:00
|
|
|
DWORD status;
|
2004-04-26 03:20:11 -04:00
|
|
|
CURLcode rc;
|
|
|
|
|
2007-02-21 14:03:20 -05:00
|
|
|
DEBUGASSERT(conn && td);
|
2004-04-26 03:20:11 -04:00
|
|
|
|
|
|
|
/* now, see if there's a connect timeout or a regular timeout to
|
|
|
|
use instead of the default one */
|
|
|
|
timeout =
|
|
|
|
conn->data->set.connecttimeout ? conn->data->set.connecttimeout :
|
|
|
|
conn->data->set.timeout ? conn->data->set.timeout :
|
2007-05-20 18:11:47 -04:00
|
|
|
CURL_TIMEOUT_RESOLVE * 1000; /* default name resolve timeout */
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2004-10-16 08:59:05 -04:00
|
|
|
/* wait for the thread to resolve the name */
|
2007-02-05 17:51:32 -05:00
|
|
|
status = WaitForSingleObject(td->event_resolved, timeout);
|
2004-10-16 08:59:05 -04:00
|
|
|
|
|
|
|
/* mark that we are now done waiting */
|
|
|
|
ReleaseMutex(td->mutex_waiting);
|
|
|
|
|
|
|
|
/* close our handle to the mutex, no point in hanging on to it */
|
|
|
|
CloseHandle(td->mutex_waiting);
|
|
|
|
td->mutex_waiting = NULL;
|
|
|
|
|
|
|
|
/* close the event handle, it's useless now */
|
|
|
|
CloseHandle(td->event_resolved);
|
|
|
|
td->event_resolved = NULL;
|
|
|
|
|
|
|
|
/* has the resolver thread succeeded in resolving our query ? */
|
2007-11-05 04:45:09 -05:00
|
|
|
if(status == WAIT_OBJECT_0) {
|
2004-10-16 08:59:05 -04:00
|
|
|
/* wait for the thread to exit, it's in the callback sequence */
|
2007-11-05 04:45:09 -05:00
|
|
|
if(WaitForSingleObject(td->thread_hnd, 5000) == WAIT_TIMEOUT) {
|
2004-10-16 08:59:05 -04:00
|
|
|
TerminateThread(td->thread_hnd, 0);
|
|
|
|
conn->async.done = TRUE;
|
|
|
|
td->thread_status = (DWORD)-1;
|
|
|
|
}
|
|
|
|
else {
|
2004-11-25 11:49:14 -05:00
|
|
|
/* Thread finished before timeout; propagate Winsock error to this
|
|
|
|
* thread. 'conn->async.done = TRUE' is set in
|
|
|
|
* Curl_addrinfo4/6_callback().
|
2004-10-16 08:59:05 -04:00
|
|
|
*/
|
2007-02-16 13:19:35 -05:00
|
|
|
SET_SOCKERRNO(conn->async.status);
|
2004-10-16 08:59:05 -04:00
|
|
|
GetExitCodeThread(td->thread_hnd, &td->thread_status);
|
|
|
|
}
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
|
|
|
else {
|
2004-10-16 08:59:05 -04:00
|
|
|
conn->async.done = TRUE;
|
|
|
|
td->thread_status = (DWORD)-1;
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(entry)
|
|
|
|
*entry = conn->async.dns;
|
|
|
|
|
|
|
|
rc = CURLE_OK;
|
|
|
|
|
2007-11-05 04:45:09 -05:00
|
|
|
if(!conn->async.dns) {
|
2004-04-26 03:20:11 -04:00
|
|
|
/* a name was not resolved */
|
2007-11-05 04:45:09 -05:00
|
|
|
if(td->thread_status == CURLE_OUT_OF_MEMORY) {
|
2005-02-08 07:36:13 -05:00
|
|
|
rc = CURLE_OUT_OF_MEMORY;
|
|
|
|
failf(data, "Could not resolve host: %s", curl_easy_strerror(rc));
|
|
|
|
}
|
2005-10-21 15:21:19 -04:00
|
|
|
else if(conn->async.done) {
|
|
|
|
if(conn->bits.httpproxy) {
|
|
|
|
failf(data, "Could not resolve proxy: %s; %s",
|
|
|
|
conn->proxy.dispname, Curl_strerror(conn, conn->async.status));
|
|
|
|
rc = CURLE_COULDNT_RESOLVE_PROXY;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
failf(data, "Could not resolve host: %s; %s",
|
|
|
|
conn->host.name, Curl_strerror(conn, conn->async.status));
|
|
|
|
rc = CURLE_COULDNT_RESOLVE_HOST;
|
|
|
|
}
|
|
|
|
}
|
2007-11-05 04:45:09 -05:00
|
|
|
else if(td->thread_status == (DWORD)-1 || conn->async.status == NO_DATA) {
|
2004-04-27 09:56:23 -04:00
|
|
|
failf(data, "Resolving host timed out: %s", conn->host.name);
|
2004-04-26 03:20:11 -04:00
|
|
|
rc = CURLE_OPERATION_TIMEDOUT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rc = CURLE_OPERATION_TIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2005-04-04 08:30:03 -04:00
|
|
|
Curl_destroy_thread_data(&conn->async);
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2005-02-08 07:36:13 -05:00
|
|
|
if(!conn->async.dns)
|
|
|
|
conn->bits.close = TRUE;
|
2004-04-26 03:20:11 -04:00
|
|
|
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
CURLcode Curl_is_resolved(struct connectdata *conn,
|
|
|
|
struct Curl_dns_entry **entry)
|
|
|
|
{
|
2008-02-09 23:20:09 -05:00
|
|
|
struct SessionHandle *data = conn->data;
|
|
|
|
|
2004-04-26 03:20:11 -04:00
|
|
|
*entry = NULL;
|
|
|
|
|
2007-11-05 04:45:09 -05:00
|
|
|
if(conn->async.done) {
|
2004-04-26 03:20:11 -04:00
|
|
|
/* we're done */
|
2005-04-04 08:30:03 -04:00
|
|
|
Curl_destroy_thread_data(&conn->async);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(!conn->async.dns) {
|
2008-02-09 23:20:09 -05:00
|
|
|
failf(data, "Could not resolve host: %s; %s",
|
|
|
|
conn->host.name, Curl_strerror(conn, conn->async.status));
|
2004-04-26 03:20:11 -04:00
|
|
|
return CURLE_COULDNT_RESOLVE_HOST;
|
|
|
|
}
|
|
|
|
*entry = conn->async.dns;
|
|
|
|
}
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2006-04-11 03:23:30 -04:00
|
|
|
int Curl_resolv_getsock(struct connectdata *conn,
|
|
|
|
curl_socket_t *socks,
|
|
|
|
int numsocks)
|
2004-04-26 03:20:11 -04:00
|
|
|
{
|
|
|
|
const struct thread_data *td =
|
|
|
|
(const struct thread_data *) conn->async.os_specific;
|
|
|
|
|
2007-11-05 04:45:09 -05:00
|
|
|
if(td && td->dummy_sock != CURL_SOCKET_BAD) {
|
2006-04-11 03:23:30 -04:00
|
|
|
if(numsocks) {
|
|
|
|
/* return one socket waiting for writable, even though this is just
|
|
|
|
a dummy */
|
|
|
|
socks[0] = td->dummy_sock;
|
|
|
|
return GETSOCK_WRITESOCK(0);
|
|
|
|
}
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
2006-04-11 03:23:30 -04:00
|
|
|
return 0;
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CURLRES_IPV4
|
|
|
|
/*
|
|
|
|
* Curl_getaddrinfo() - for Windows threading without ENABLE_IPV6.
|
|
|
|
*/
|
|
|
|
Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
|
2006-07-21 01:51:12 -04:00
|
|
|
const char *hostname,
|
2004-04-26 03:20:11 -04:00
|
|
|
int port,
|
|
|
|
int *waitp)
|
|
|
|
{
|
|
|
|
struct hostent *h = NULL;
|
|
|
|
struct SessionHandle *data = conn->data;
|
2008-11-06 12:19:56 -05:00
|
|
|
struct in_addr in;
|
2004-04-26 03:20:11 -04:00
|
|
|
|
|
|
|
*waitp = 0; /* don't wait, we act synchronously */
|
|
|
|
|
2008-11-06 12:19:56 -05:00
|
|
|
if(Curl_inet_pton(AF_INET, hostname, &in) > 0)
|
2004-04-26 03:20:11 -04:00
|
|
|
/* This is a dotted IP address 123.123.123.123-style */
|
2008-11-06 12:19:56 -05:00
|
|
|
return Curl_ip2addr(AF_INET, &in, hostname, port);
|
2004-04-26 03:20:11 -04:00
|
|
|
|
|
|
|
/* fire up a new resolver thread! */
|
2007-11-05 04:45:09 -05:00
|
|
|
if(init_resolve_thread(conn, hostname, port, NULL)) {
|
2004-04-26 03:20:11 -04:00
|
|
|
*waitp = TRUE; /* please wait for the response */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fall-back to blocking version */
|
2004-10-16 08:59:05 -04:00
|
|
|
infof(data, "init_resolve_thread() failed for %s; %s\n",
|
2007-02-16 13:19:35 -05:00
|
|
|
hostname, Curl_strerror(conn, ERRNO));
|
2004-04-26 03:20:11 -04:00
|
|
|
|
|
|
|
h = gethostbyname(hostname);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(!h) {
|
2004-04-26 03:20:11 -04:00
|
|
|
infof(data, "gethostbyname(2) failed for %s:%d; %s\n",
|
2007-02-16 13:19:35 -05:00
|
|
|
hostname, port, Curl_strerror(conn, SOCKERRNO));
|
2004-04-26 03:20:11 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-06-24 06:43:50 -04:00
|
|
|
return Curl_he2ai(h, port);
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
|
|
|
#endif /* CURLRES_IPV4 */
|
|
|
|
|
|
|
|
#ifdef CURLRES_IPV6
|
|
|
|
/*
|
|
|
|
* Curl_getaddrinfo() - for Windows threading IPv6 enabled
|
|
|
|
*/
|
|
|
|
Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
|
2006-07-21 01:51:12 -04:00
|
|
|
const char *hostname,
|
2004-04-26 03:20:11 -04:00
|
|
|
int port,
|
|
|
|
int *waitp)
|
|
|
|
{
|
2008-10-30 09:45:25 -04:00
|
|
|
struct addrinfo hints;
|
|
|
|
Curl_addrinfo *res;
|
2004-04-26 03:20:11 -04:00
|
|
|
int error;
|
|
|
|
char sbuf[NI_MAXSERV];
|
|
|
|
int pf;
|
|
|
|
struct SessionHandle *data = conn->data;
|
|
|
|
|
|
|
|
*waitp = FALSE; /* default to synch response */
|
|
|
|
|
2008-07-29 14:26:35 -04:00
|
|
|
/*
|
|
|
|
* Check if a limited name resolve has been requested.
|
|
|
|
*/
|
|
|
|
switch(data->set.ip_version) {
|
|
|
|
case CURL_IPRESOLVE_V4:
|
2004-04-26 03:20:11 -04:00
|
|
|
pf = PF_INET;
|
2008-07-29 14:26:35 -04:00
|
|
|
break;
|
|
|
|
case CURL_IPRESOLVE_V6:
|
|
|
|
pf = PF_INET6;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pf = PF_UNSPEC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pf != PF_INET) {
|
|
|
|
/* see if we have an IPv6 stack */
|
|
|
|
curl_socket_t s = socket(PF_INET6, SOCK_DGRAM, 0);
|
|
|
|
if(s == CURL_SOCKET_BAD) {
|
|
|
|
/* Some non-IPv6 stacks have been found to make very slow name resolves
|
|
|
|
* when PF_UNSPEC is used, so thus we switch to a mere PF_INET lookup if
|
|
|
|
* the stack seems to be a non-ipv6 one. */
|
2004-04-26 03:20:11 -04:00
|
|
|
|
|
|
|
pf = PF_INET;
|
2008-07-29 14:26:35 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* This seems to be an IPv6-capable stack, use PF_UNSPEC for the widest
|
|
|
|
* possible checks. And close the socket again.
|
|
|
|
*/
|
|
|
|
sclose(s);
|
2004-04-26 03:20:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_family = pf;
|
2005-09-16 17:30:08 -04:00
|
|
|
hints.ai_socktype = conn->socktype;
|
2005-11-08 09:45:58 -05:00
|
|
|
#if 0 /* removed nov 8 2005 before 7.15.1 */
|
2004-04-26 03:20:11 -04:00
|
|
|
hints.ai_flags = AI_CANONNAME;
|
2005-11-08 09:45:58 -05:00
|
|
|
#endif
|
2004-04-26 03:20:11 -04:00
|
|
|
itoa(port, sbuf, 10);
|
|
|
|
|
|
|
|
/* fire up a new resolver thread! */
|
2007-11-05 04:45:09 -05:00
|
|
|
if(init_resolve_thread(conn, hostname, port, &hints)) {
|
2004-04-26 03:20:11 -04:00
|
|
|
*waitp = TRUE; /* please wait for the response */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fall-back to blocking version */
|
2004-10-16 08:59:05 -04:00
|
|
|
infof(data, "init_resolve_thread() failed for %s; %s\n",
|
2007-02-16 13:19:35 -05:00
|
|
|
hostname, Curl_strerror(conn, ERRNO));
|
2004-04-26 03:20:11 -04:00
|
|
|
|
2008-10-30 09:45:25 -04:00
|
|
|
error = Curl_getaddrinfo_ex(hostname, sbuf, &hints, &res);
|
2007-11-05 04:45:09 -05:00
|
|
|
if(error) {
|
2004-04-26 03:20:11 -04:00
|
|
|
infof(data, "getaddrinfo() failed for %s:%d; %s\n",
|
2007-02-16 13:19:35 -05:00
|
|
|
hostname, port, Curl_strerror(conn, SOCKERRNO));
|
2004-04-26 03:20:11 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif /* CURLRES_IPV6 */
|
|
|
|
#endif /* CURLRES_THREADED */
|