ws2_32: Cache the synchronous I/O event in the per-thread data.

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-05-17 21:29:56 -05:00 committed by Alexandre Julliard
parent 9172ca5baa
commit 520a84870f
2 changed files with 14 additions and 5 deletions

View File

@ -1280,6 +1280,8 @@ static void free_per_thread_data(void)
if (!ptb) return;
CloseHandle( ptb->sync_event );
/* delete scratch buffers */
HeapFree( GetProcessHeap(), 0, ptb->he_buffer );
HeapFree( GetProcessHeap(), 0, ptb->se_buffer );
@ -1290,6 +1292,16 @@ static void free_per_thread_data(void)
NtCurrentTeb()->WinSockData = NULL;
}
static HANDLE get_sync_event(void)
{
struct per_thread_data *data;
if (!(data = get_per_thread_data())) return NULL;
if (!data->sync_event)
data->sync_event = CreateEventW( NULL, TRUE, FALSE, NULL );
return data->sync_event;
}
/***********************************************************************
* DllMain (WS2_32.init)
*/
@ -2339,19 +2351,15 @@ SOCKET WINAPI WS_accept( SOCKET s, struct WS_sockaddr *addr, int *len )
TRACE("%#lx\n", s);
if (!(sync_event = CreateEventW( NULL, TRUE, FALSE, NULL ))) return INVALID_SOCKET;
if (!(sync_event = get_sync_event())) return INVALID_SOCKET;
status = NtDeviceIoControlFile( SOCKET2HANDLE(s), (HANDLE)((ULONG_PTR)sync_event | 0), NULL, NULL, &io,
IOCTL_AFD_WINE_ACCEPT, NULL, 0, &accept_handle, sizeof(accept_handle) );
if (status == STATUS_PENDING)
{
if (WaitForSingleObject( sync_event, INFINITE ) == WAIT_FAILED)
{
CloseHandle( sync_event );
return SOCKET_ERROR;
}
status = io.u.Status;
}
CloseHandle( sync_event );
if (status)
{
WARN("failed; status %#x\n", status);

View File

@ -181,6 +181,7 @@ UINT sock_get_error( int err ) DECLSPEC_HIDDEN;
struct per_thread_data
{
HANDLE sync_event; /* event to wait on for synchronous ioctls */
int opentype;
struct WS_hostent *he_buffer;
struct WS_servent *se_buffer;