winhttp: Use the thread pool for asynchronous hostname resolution.
Signed-off-by: Hans Leidekker <hans@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
c6251cbb12
commit
539f2f1530
|
@ -651,42 +651,44 @@ static DWORD resolve_hostname( const WCHAR *name, INTERNET_PORT port, struct soc
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct resolve_args
|
struct async_resolve
|
||||||
{
|
{
|
||||||
const WCHAR *hostname;
|
const WCHAR *hostname;
|
||||||
INTERNET_PORT port;
|
INTERNET_PORT port;
|
||||||
struct sockaddr_storage *sa;
|
struct sockaddr_storage *addr;
|
||||||
|
DWORD result;
|
||||||
|
HANDLE done;
|
||||||
};
|
};
|
||||||
|
|
||||||
static DWORD CALLBACK resolve_proc( LPVOID arg )
|
static void CALLBACK resolve_proc( TP_CALLBACK_INSTANCE *instance, void *ctx )
|
||||||
{
|
{
|
||||||
struct resolve_args *ra = arg;
|
struct async_resolve *async = ctx;
|
||||||
return resolve_hostname( ra->hostname, ra->port, ra->sa );
|
async->result = resolve_hostname( async->hostname, async->port, async->addr );
|
||||||
|
SetEvent( async->done );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL netconn_resolve( WCHAR *hostname, INTERNET_PORT port, struct sockaddr_storage *sa, int timeout )
|
BOOL netconn_resolve( WCHAR *hostname, INTERNET_PORT port, struct sockaddr_storage *addr, int timeout )
|
||||||
{
|
{
|
||||||
DWORD ret;
|
DWORD ret;
|
||||||
|
|
||||||
if (timeout)
|
if (!timeout) ret = resolve_hostname( hostname, port, addr );
|
||||||
|
else
|
||||||
{
|
{
|
||||||
DWORD status;
|
struct async_resolve async;
|
||||||
HANDLE thread;
|
|
||||||
struct resolve_args ra;
|
|
||||||
|
|
||||||
ra.hostname = hostname;
|
async.hostname = hostname;
|
||||||
ra.port = port;
|
async.port = port;
|
||||||
ra.sa = sa;
|
async.addr = addr;
|
||||||
|
if (!(async.done = CreateEventW( NULL, FALSE, FALSE, NULL ))) return FALSE;
|
||||||
thread = CreateThread( NULL, 0, resolve_proc, &ra, 0, NULL );
|
if (!TrySubmitThreadpoolCallback( resolve_proc, &async, NULL ))
|
||||||
if (!thread) return FALSE;
|
{
|
||||||
|
CloseHandle( async.done );
|
||||||
status = WaitForSingleObject( thread, timeout );
|
return FALSE;
|
||||||
if (status == WAIT_OBJECT_0) GetExitCodeThread( thread, &ret );
|
}
|
||||||
else ret = ERROR_WINHTTP_TIMEOUT;
|
if (WaitForSingleObject( async.done, timeout ) != WAIT_OBJECT_0) ret = ERROR_WINHTTP_TIMEOUT;
|
||||||
CloseHandle( thread );
|
else ret = async.result;
|
||||||
|
CloseHandle( async.done );
|
||||||
}
|
}
|
||||||
else ret = resolve_hostname( hostname, port, sa );
|
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue