From ee30a6200f28c8d64e55976937fa8a545392b8a1 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Sun, 11 Sep 2011 12:03:38 +0000 Subject: [PATCH] Some bugfixes in the DirectPlay service provider code. --- src/directplay.c | 21 +++++++++++++-------- src/ipxwrapper.def | 1 + src/ipxwrapper_stubs.txt | 1 + src/router.c | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/directplay.c b/src/directplay.c index d33ae9a..ab87e97 100644 --- a/src/directplay.c +++ b/src/directplay.c @@ -128,11 +128,15 @@ static DWORD WINAPI worker_main(LPVOID sp) { } if(!recv_packet(sp_data->sock, buf, sp)) { + release_sp_data((IDirectPlaySP*)sp); return 1; } - if(sp_data->ns_sock != -1 && recv_packet(sp_data->ns_sock, buf, sp)) { - return 1; + if(sp_data->ns_sock != -1 && !recv_packet(sp_data->ns_sock, buf, sp)) { + log_printf("Closing ns_sock due to error"); + + closesocket(sp_data->ns_sock); + sp_data->ns_sock = -1; } release_sp_data((IDirectPlaySP*)sp); @@ -354,7 +358,7 @@ static HRESULT WINAPI IPX_Open(LPDPSP_OPENDATA data) { memcpy(&addr, &(sp_data->addr), sizeof(addr)); addr.sa_socket = htons(DISCOVERY_SOCKET); - + if(bind(sp_data->ns_sock, (struct sockaddr*)&addr, sizeof(addr)) == -1) { closesocket(sp_data->ns_sock); sp_data->ns_sock = -1; @@ -365,7 +369,7 @@ static HRESULT WINAPI IPX_Open(LPDPSP_OPENDATA data) { return DPERR_CANNOTCREATESERVER; } - if(WSAEventSelect(sp_data->sock, sp_data->event, FD_READ) == -1) { + if(WSAEventSelect(sp_data->ns_sock, sp_data->event, FD_READ) == -1) { closesocket(sp_data->ns_sock); sp_data->ns_sock = -1; @@ -403,11 +407,12 @@ static HRESULT WINAPI IPX_ShutdownEx(LPDPSP_SHUTDOWNDATA data) { struct sp_data *sp_data = get_sp_data(data->lpISP); + sp_data->running = FALSE; + WSASetEvent(sp_data->event); + + release_sp_data(data->lpISP); + if(sp_data->worker_thread) { - sp_data->running = FALSE; - - release_sp_data(data->lpISP); - if(WaitForSingleObject(sp_data->worker_thread, 3000) == WAIT_TIMEOUT) { log_printf("DirectPlay worker didn't exit in 3 seconds, killing"); TerminateThread(sp_data->worker_thread, 0); diff --git a/src/ipxwrapper.def b/src/ipxwrapper.def index fec0a58..be45be5 100644 --- a/src/ipxwrapper.def +++ b/src/ipxwrapper.def @@ -19,3 +19,4 @@ EXPORTS WSACloseEvent WSAEventSelect WSAResetEvent + WSASetEvent diff --git a/src/ipxwrapper_stubs.txt b/src/ipxwrapper_stubs.txt index 1481108..91a1e8d 100644 --- a/src/ipxwrapper_stubs.txt +++ b/src/ipxwrapper_stubs.txt @@ -16,6 +16,7 @@ WSACreateEvent WSAEventSelect WSACloseEvent WSAResetEvent +WSASetEvent r_EnumProtocolsA r_EnumProtocolsW r_WSARecvEx diff --git a/src/router.c b/src/router.c index f4cf2e6..1407dca 100644 --- a/src/router.c +++ b/src/router.c @@ -716,7 +716,7 @@ void rclient_stop(struct rclient *rclient) { EnterCriticalSection(&(rclient->router->crit_sec)); rclient->router->running = FALSE; - SetEvent(rclient->router->wsa_event); + WSASetEvent(rclient->router->wsa_event); LeaveCriticalSection(&(rclient->router->crit_sec));