Commit d1461b62 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

ws2_32/tests: Rewrite the CF_DEFER test in test_AcceptEx().

The previous test in fact regularly failed on Windows, hidden by the presence of broken(), since both sockets could be connected before the listener was signaled. Signed-off-by: 's avatarZebediah Figura <z.figura12@gmail.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 5a68001d
...@@ -7413,18 +7413,14 @@ static void test_ConnectEx(void) ...@@ -7413,18 +7413,14 @@ static void test_ConnectEx(void)
static void test_AcceptEx(void) static void test_AcceptEx(void)
{ {
SOCKET listener = INVALID_SOCKET; SOCKET listener, acceptor, acceptor2, connector, connector2;
SOCKET acceptor = INVALID_SOCKET;
SOCKET connector = INVALID_SOCKET;
SOCKET connector2 = INVALID_SOCKET;
struct sockaddr_in bindAddress, peerAddress, *readBindAddress, *readRemoteAddress; struct sockaddr_in bindAddress, peerAddress, *readBindAddress, *readRemoteAddress;
int socklen, optlen; int socklen, optlen;
GUID acceptExGuid = WSAID_ACCEPTEX, getAcceptExGuid = WSAID_GETACCEPTEXSOCKADDRS; GUID acceptExGuid = WSAID_ACCEPTEX, getAcceptExGuid = WSAID_GETACCEPTEXSOCKADDRS;
LPFN_ACCEPTEX pAcceptEx = NULL; LPFN_ACCEPTEX pAcceptEx = NULL;
LPFN_GETACCEPTEXSOCKADDRS pGetAcceptExSockaddrs = NULL; LPFN_GETACCEPTEXSOCKADDRS pGetAcceptExSockaddrs = NULL;
fd_set fds_accept, fds_send; fd_set fds_accept, fds_send;
struct timeval timeout = {0,10}; /* wait for 10 milliseconds */ static const struct timeval timeout = {1, 0};
int got, conn1, i;
DWORD bytesReturned, connect_time; DWORD bytesReturned, connect_time;
char buffer[1024], ipbuffer[32]; char buffer[1024], ipbuffer[32];
OVERLAPPED overlapped; OVERLAPPED overlapped;
...@@ -7703,66 +7699,47 @@ todo_wine ...@@ -7703,66 +7699,47 @@ todo_wine
iret = connect(connector, (struct sockaddr*)&bindAddress, sizeof(bindAddress)); iret = connect(connector, (struct sockaddr*)&bindAddress, sizeof(bindAddress));
ok(iret == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK, "connecting to accepting socket failed, error %d\n", WSAGetLastError()); ok(iret == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK, "connecting to accepting socket failed, error %d\n", WSAGetLastError());
FD_ZERO ( &fds_accept ); buffer[0] = '0';
FD_ZERO ( &fds_send );
FD_SET ( listener, &fds_accept ); FD_ZERO(&fds_accept);
FD_SET ( connector, &fds_send ); FD_SET(listener, &fds_accept);
iret = select(0, &fds_accept, NULL, NULL, &timeout);
ok(iret == 1, "wait timed out\n");
buffer[0] = '0'; acceptor2 = WSAAccept(listener, NULL, NULL, AlwaysDeferConditionFunc, 0);
got = 0; ok(acceptor2 == INVALID_SOCKET, "expected failure\n");
conn1 = 0; ok(WSAGetLastError() == WSATRY_AGAIN, "got error %u\n", WSAGetLastError());
bret = pAcceptEx(listener, acceptor, buffer, 0, sizeof(struct sockaddr_in) + 16,
sizeof(struct sockaddr_in) + 16, &bytesReturned, &overlapped);
ok(!bret, "expected failure\n");
ok(WSAGetLastError() == ERROR_IO_PENDING, "got error %u\n", WSAGetLastError());
for (i = 0; i < 4000; ++i) FD_ZERO(&fds_send);
{ FD_SET(connector, &fds_send);
fd_set fds_openaccept = fds_accept, fds_opensend = fds_send; iret = select(0, NULL, &fds_send, NULL, &timeout);
ok(iret == 1, "wait timed out\n");
wsa_ok ( ( select ( 0, &fds_openaccept, &fds_opensend, NULL, &timeout ) ), SOCKET_ERROR !=, iret = send(connector, "1", 1, 0);
"acceptex test(%d): could not select on socket, errno %d\n" ); ok(iret == 1, "got ret %d, error %u\n", iret, WSAGetLastError());
/* check for incoming requests */ iret = connect(connector2, (struct sockaddr *)&bindAddress, sizeof(bindAddress));
if ( FD_ISSET ( listener, &fds_openaccept ) ) { ok(iret == SOCKET_ERROR, "expected failure\n");
got++; ok(WSAGetLastError() == WSAEWOULDBLOCK, "got error %u\n", WSAGetLastError());
if (got == 1) {
SOCKET tmp = WSAAccept(listener, NULL, NULL, (LPCONDITIONPROC) AlwaysDeferConditionFunc, 0);
ok(tmp == INVALID_SOCKET && WSAGetLastError() == WSATRY_AGAIN, "Failed to defer connection, %d\n", WSAGetLastError());
bret = pAcceptEx(listener, acceptor, buffer, 0,
sizeof(struct sockaddr_in) + 16, sizeof(struct sockaddr_in) + 16,
&bytesReturned, &overlapped);
ok(bret == FALSE && WSAGetLastError() == ERROR_IO_PENDING, "AcceptEx returned %d + errno %d\n", bret, WSAGetLastError());
}
else if (got == 2) {
/* this should be socket #2 */
SOCKET tmp = accept(listener, NULL, NULL);
ok(tmp != INVALID_SOCKET, "accept failed %d\n", WSAGetLastError());
closesocket(tmp);
}
else {
ok(FALSE, "Got more than 2 connections?\n");
}
}
if ( conn1 && FD_ISSET ( connector2, &fds_opensend ) ) {
/* Send data on second socket, and stop */
send(connector2, "2", 1, 0);
FD_CLR ( connector2, &fds_send );
break; iret = select(0, &fds_accept, NULL, NULL, &timeout);
} ok(iret == 1, "wait timed out\n");
if ( FD_ISSET ( connector, &fds_opensend ) ) {
/* Once #1 is connected, allow #2 to connect */
conn1 = 1;
send(connector, "1", 1, 0); acceptor2 = accept(listener, NULL, NULL);
FD_CLR ( connector, &fds_send ); ok(acceptor2 != INVALID_SOCKET, "failed to accept, error %u\n", WSAGetLastError());
closesocket(acceptor2);
iret = connect(connector2, (struct sockaddr*)&bindAddress, sizeof(bindAddress)); FD_ZERO(&fds_send);
ok(iret == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK, "connecting to accepting socket failed, error %d\n", WSAGetLastError()); FD_SET(connector2, &fds_send);
FD_SET ( connector2, &fds_send ); iret = select(0, NULL, &fds_send, NULL, &timeout);
} ok(iret == 1, "wait timed out\n");
}
ok (got == 2 || broken(got == 1) /* NT4 */, iret = send(connector2, "2", 1, 0);
"Did not get both connections, got %d\n", got); ok(iret == 1, "got ret %d, error %u\n", iret, WSAGetLastError());
dwret = WaitForSingleObject(overlapped.hEvent, 0); dwret = WaitForSingleObject(overlapped.hEvent, 0);
ok(dwret == WAIT_OBJECT_0, "Waiting for accept event failed with %d + errno %d\n", dwret, GetLastError()); ok(dwret == WAIT_OBJECT_0, "Waiting for accept event failed with %d + errno %d\n", dwret, GetLastError());
...@@ -7774,7 +7751,6 @@ todo_wine ...@@ -7774,7 +7751,6 @@ todo_wine
set_blocking(acceptor, TRUE); set_blocking(acceptor, TRUE);
iret = recv( acceptor, buffer, 2, 0); iret = recv( acceptor, buffer, 2, 0);
ok(iret == 1, "Failed to get data, %d, errno: %d\n", iret, WSAGetLastError()); ok(iret == 1, "Failed to get data, %d, errno: %d\n", iret, WSAGetLastError());
ok(buffer[0] == '1', "The wrong first client was accepted by acceptex: %c != 1\n", buffer[0]); ok(buffer[0] == '1', "The wrong first client was accepted by acceptex: %c != 1\n", buffer[0]);
closesocket(connector); closesocket(connector);
......
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