Commit 45bd91b2 authored by Mike Kaplinskiy's avatar Mike Kaplinskiy Committed by Alexandre Julliard

ws2_32/tests: Test WSAAccept with CF_DEFER.

parent 3905c7a0
...@@ -1949,11 +1949,20 @@ static DWORD WINAPI AcceptKillThread(select_thread_params *par) ...@@ -1949,11 +1949,20 @@ static DWORD WINAPI AcceptKillThread(select_thread_params *par)
return 0; return 0;
} }
static int CALLBACK AlwaysDeferConditionFunc(LPWSABUF lpCallerId, LPWSABUF lpCallerData, LPQOS pQos,
LPQOS lpGQOS, LPWSABUF lpCalleeId, LPWSABUF lpCalleeData,
GROUP FAR * g, DWORD_PTR dwCallbackData)
{
return CF_DEFER;
}
static void test_accept(void) static void test_accept(void)
{ {
int ret; int ret;
SOCKET server_socket = INVALID_SOCKET; SOCKET server_socket = INVALID_SOCKET, accepted = INVALID_SOCKET, connector = INVALID_SOCKET;
struct sockaddr_in address; struct sockaddr_in address;
int socklen;
select_thread_params thread_params; select_thread_params thread_params;
HANDLE thread_handle = NULL; HANDLE thread_handle = NULL;
DWORD id; DWORD id;
...@@ -1966,6 +1975,7 @@ static void test_accept(void) ...@@ -1966,6 +1975,7 @@ static void test_accept(void)
} }
memset(&address, 0, sizeof(address)); memset(&address, 0, sizeof(address));
address.sin_addr.s_addr = inet_addr("127.0.0.1");
address.sin_family = AF_INET; address.sin_family = AF_INET;
ret = bind(server_socket, (struct sockaddr*) &address, sizeof(address)); ret = bind(server_socket, (struct sockaddr*) &address, sizeof(address));
if (ret != 0) if (ret != 0)
...@@ -1974,13 +1984,34 @@ static void test_accept(void) ...@@ -1974,13 +1984,34 @@ static void test_accept(void)
goto done; goto done;
} }
ret = listen(server_socket, 1); socklen = sizeof(address);
ret = getsockname(server_socket, (struct sockaddr*)&address, &socklen);
if (ret != 0) {
skip("failed to lookup bind address, error %d\n", WSAGetLastError());
goto done;
}
ret = listen(server_socket, 5);
if (ret != 0) if (ret != 0)
{ {
trace("error making server socket listen: %d\n", WSAGetLastError()); trace("error making server socket listen: %d\n", WSAGetLastError());
goto done; goto done;
} }
trace("Blocking accept next\n");
connector = socket(AF_INET, SOCK_STREAM, 0);
ok(connector != INVALID_SOCKET, "Failed to create connector socket, error %d\n", WSAGetLastError());
ret = connect(connector, (struct sockaddr*)&address, sizeof(address));
ok(ret == 0, "connecting to accepting socket failed, error %d\n", WSAGetLastError());
accepted = WSAAccept(server_socket, NULL, NULL, (LPCONDITIONPROC) AlwaysDeferConditionFunc, 0);
ok(accepted == INVALID_SOCKET && WSAGetLastError() == WSATRY_AGAIN, "Failed to defer connection, %d\n", WSAGetLastError());
accepted = accept(server_socket, NULL, 0);
ok(accepted != INVALID_SOCKET, "Failed to accept deferred connection, error %d\n", WSAGetLastError());
server_ready = CreateEventA(NULL, TRUE, FALSE, NULL); server_ready = CreateEventA(NULL, TRUE, FALSE, NULL);
if (server_ready == INVALID_HANDLE_VALUE) if (server_ready == INVALID_HANDLE_VALUE)
{ {
...@@ -2011,6 +2042,10 @@ static void test_accept(void) ...@@ -2011,6 +2042,10 @@ static void test_accept(void)
ok(thread_params.ReadKilled, "closesocket did not wakeup accept\n"); ok(thread_params.ReadKilled, "closesocket did not wakeup accept\n");
done: done:
if (accepted != INVALID_SOCKET)
closesocket(accepted);
if (connector != INVALID_SOCKET)
closesocket(connector);
if (thread_handle != NULL) if (thread_handle != NULL)
CloseHandle(thread_handle); CloseHandle(thread_handle);
if (server_ready != INVALID_HANDLE_VALUE) if (server_ready != INVALID_HANDLE_VALUE)
...@@ -2757,13 +2792,6 @@ static void test_GetAddrInfoW(void) ...@@ -2757,13 +2792,6 @@ static void test_GetAddrInfoW(void)
pFreeAddrInfoW(result); pFreeAddrInfoW(result);
} }
static int CALLBACK AlwaysDeferConditionFunc(LPWSABUF lpCallerId, LPWSABUF lpCallerData, LPQOS pQos,
LPQOS lpGQOS, LPWSABUF lpCalleeId, LPWSABUF lpCalleeData,
GROUP FAR * g, DWORD_PTR dwCallbackData)
{
return CF_DEFER;
}
static void test_AcceptEx(void) static void test_AcceptEx(void)
{ {
SOCKET listener = INVALID_SOCKET; SOCKET listener = INVALID_SOCKET;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment