ws2_32: Always set overlapped status in AcceptEx.

Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2019-02-22 13:59:28 +01:00 committed by Alexandre Julliard
parent ba14773187
commit 72c1cf59a3
2 changed files with 37 additions and 6 deletions

View File

@ -2822,17 +2822,18 @@ static BOOL WINAPI WS2_AcceptEx(SOCKET listener, SOCKET acceptor, PVOID dest, DW
TRACE("(%04lx, %04lx, %p, %d, %d, %d, %p, %p)\n", listener, acceptor, dest, dest_len, local_addr_len,
rem_addr_len, received, overlapped);
if (!dest)
{
SetLastError(WSAEINVAL);
return FALSE;
}
if (!overlapped)
{
SetLastError(WSA_INVALID_PARAMETER);
return FALSE;
}
overlapped->Internal = STATUS_PENDING;
if (!dest)
{
SetLastError(WSAEINVAL);
return FALSE;
}
if (!rem_addr_len)
{

View File

@ -8276,18 +8276,22 @@ static void test_AcceptEx(void)
goto end;
}
overlapped.Internal = 0xdeadbeef;
bret = pAcceptEx(INVALID_SOCKET, acceptor, buffer, sizeof(buffer) - 2*(sizeof(struct sockaddr_in) + 16),
sizeof(struct sockaddr_in) + 16, sizeof(struct sockaddr_in) + 16,
&bytesReturned, &overlapped);
ok(bret == FALSE && WSAGetLastError() == WSAENOTSOCK, "AcceptEx on invalid listening socket "
"returned %d + errno %d\n", bret, WSAGetLastError());
ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal);
overlapped.Internal = 0xdeadbeef;
bret = pAcceptEx(listener, acceptor, buffer, sizeof(buffer) - 2*(sizeof(struct sockaddr_in) + 16),
sizeof(struct sockaddr_in) + 16, sizeof(struct sockaddr_in) + 16,
&bytesReturned, &overlapped);
todo_wine
ok(bret == FALSE && WSAGetLastError() == WSAEINVAL, "AcceptEx on a non-listening socket "
"returned %d + errno %d\n", bret, WSAGetLastError());
ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal);
iret = listen(listener, 5);
if (iret != 0) {
@ -8295,43 +8299,55 @@ todo_wine
goto end;
}
overlapped.Internal = 0xdeadbeef;
bret = pAcceptEx(listener, INVALID_SOCKET, buffer, sizeof(buffer) - 2*(sizeof(struct sockaddr_in) + 16),
sizeof(struct sockaddr_in) + 16, sizeof(struct sockaddr_in) + 16,
&bytesReturned, &overlapped);
ok(bret == FALSE && WSAGetLastError() == WSAENOTSOCK, "AcceptEx on invalid accepting socket "
"returned %d + errno %d\n", bret, WSAGetLastError());
ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal);
overlapped.Internal = 0xdeadbeef;
bret = pAcceptEx(listener, acceptor, NULL, sizeof(buffer) - 2*(sizeof(struct sockaddr_in) + 16),
sizeof(struct sockaddr_in) + 16, sizeof(struct sockaddr_in) + 16,
&bytesReturned, &overlapped);
todo_wine ok(bret == FALSE && WSAGetLastError() == WSAEFAULT,
"AcceptEx on NULL buffer returned %d + errno %d\n", bret, WSAGetLastError());
ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal);
overlapped.Internal = 0xdeadbeef;
bret = pAcceptEx(listener, acceptor, buffer, 0, 0, sizeof(struct sockaddr_in) + 16,
&bytesReturned, &overlapped);
ok(bret == FALSE && WSAGetLastError() == ERROR_IO_PENDING,
"AcceptEx on too small local address size returned %d + errno %d\n",
bret, WSAGetLastError());
ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal);
bret = CancelIo((HANDLE) listener);
ok(bret, "Failed to cancel pending accept socket\n");
overlapped.Internal = 0xdeadbeef;
bret = pAcceptEx(listener, acceptor, buffer, 0, sizeof(struct sockaddr_in) + 15,
sizeof(struct sockaddr_in) + 16, &bytesReturned, &overlapped);
ok(bret == FALSE && WSAGetLastError() == ERROR_IO_PENDING, "AcceptEx on too small local address "
"size returned %d + errno %d\n",
bret, WSAGetLastError());
ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal);
bret = CancelIo((HANDLE) listener);
ok(bret, "Failed to cancel pending accept socket\n");
overlapped.Internal = 0xdeadbeef;
bret = pAcceptEx(listener, acceptor, buffer, 0, sizeof(struct sockaddr_in) + 16, 0,
&bytesReturned, &overlapped);
ok(bret == FALSE && WSAGetLastError() == WSAEFAULT,
"AcceptEx on too small remote address size returned %d + errno %d\n", bret, WSAGetLastError());
ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal);
overlapped.Internal = 0xdeadbeef;
bret = pAcceptEx(listener, acceptor, buffer, 0, sizeof(struct sockaddr_in) + 16,
sizeof(struct sockaddr_in) + 15, &bytesReturned, &overlapped);
ok(bret == FALSE && WSAGetLastError() == ERROR_IO_PENDING,
"AcceptEx on too small remote address size returned %d + errno %d\n", bret, WSAGetLastError());
ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal);
bret = CancelIo((HANDLE) listener);
ok(bret, "Failed to cancel pending accept socket\n");
@ -8351,16 +8367,20 @@ todo_wine
goto end;
}
overlapped.Internal = 0xdeadbeef;
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());
ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal);
overlapped.Internal = 0xdeadbeef;
bret = pAcceptEx(listener, acceptor, buffer, 0,
sizeof(struct sockaddr_in) + 16, sizeof(struct sockaddr_in) + 16,
&bytesReturned, &overlapped);
todo_wine ok(bret == FALSE && WSAGetLastError() == WSAEINVAL,
"AcceptEx on already pending socket returned %d + errno %d\n", bret, WSAGetLastError());
ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal);
if (bret == FALSE && WSAGetLastError() == ERROR_IO_PENDING) {
/* We need to cancel this call, otherwise things fail */
bret = CancelIo((HANDLE) listener);
@ -8368,10 +8388,12 @@ todo_wine
if (!bret) return;
WaitForSingleObject(overlapped.hEvent, 0);
overlapped.Internal = 0xdeadbeef;
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());
ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal);
}
iret = connect(acceptor, (struct sockaddr*)&bindAddress, sizeof(bindAddress));
@ -8390,17 +8412,21 @@ todo_wine
ok(bret, "Failed to cancel failed test. Bailing...\n");
if (!bret) return;
overlapped.Internal = 0xdeadbeef;
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());
ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal);
}
overlapped.Internal = 0xdeadbeef;
iret = connect(connector, (struct sockaddr*)&bindAddress, sizeof(bindAddress));
ok(iret == 0, "connecting to accepting socket failed, error %d\n", WSAGetLastError());
dwret = WaitForSingleObject(overlapped.hEvent, INFINITE);
ok(dwret == WAIT_OBJECT_0, "Waiting for accept event failed with %d + errno %d\n", dwret, GetLastError());
ok(overlapped.Internal == STATUS_SUCCESS, "got %08x\n", (ULONG)overlapped.Internal);
bret = GetOverlappedResult((HANDLE)listener, &overlapped, &bytesReturned, FALSE);
ok(bret, "GetOverlappedResult failed, error %d\n", GetLastError());
@ -8422,10 +8448,12 @@ todo_wine
skip("could not create connector socket, error %d\n", WSAGetLastError());
goto end;
}
overlapped.Internal = 0xdeadbeef;
bret = pAcceptEx(listener, acceptor, buffer, 2,
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());
ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal);
connect_time = 0xdeadbeef;
optlen = sizeof(connect_time);
@ -8445,6 +8473,7 @@ todo_wine
dwret = WaitForSingleObject(overlapped.hEvent, 0);
ok(dwret == WAIT_TIMEOUT, "Waiting for accept event timeout failed with %d + errno %d\n", dwret, GetLastError());
ok(overlapped.Internal == STATUS_PENDING, "got %08x\n", (ULONG)overlapped.Internal);
iret = getsockname( connector, (struct sockaddr *)&peerAddress, &remoteSize);
ok( !iret, "getsockname failed.\n");
@ -8455,6 +8484,7 @@ todo_wine
dwret = WaitForSingleObject(overlapped.hEvent, 1000);
ok(dwret == WAIT_OBJECT_0, "Waiting for accept event failed with %d + errno %d\n", dwret, GetLastError());
ok(overlapped.Internal == STATUS_SUCCESS, "got %08x\n", (ULONG)overlapped.Internal);
/* Check if the buffer from AcceptEx is decoded correctly */
pGetAcceptExSockaddrs(buffer, 2, sizeof(struct sockaddr_in) + 16, sizeof(struct sockaddr_in) + 16,