server: Fail with WSAEINVAL or WSAEALREADY when trying to connect a socket that is already connecting via nonblocking connect().

Fixes connection in Mortal Kombat 11; reported by Thomas Crider.

Fixes: a891713f48
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-06-10 12:36:37 -05:00 committed by Alexandre Julliard
parent 7326b21241
commit 9344a490a4
3 changed files with 12 additions and 3 deletions

View File

@ -2222,7 +2222,8 @@ int WINAPI WS_connect( SOCKET s, const struct WS_sockaddr *addr, int len )
}
if (status)
{
SetLastError( NtStatusToWSAError( status ) );
/* NtStatusToWSAError() has no mapping for WSAEALREADY */
SetLastError( status == STATUS_ADDRESS_ALREADY_ASSOCIATED ? WSAEALREADY : NtStatusToWSAError( status ) );
return -1;
}
return 0;

View File

@ -10251,7 +10251,7 @@ static void test_connecting_socket(void)
* second to return WSAEALREADY. */
ret = connect(client, (struct sockaddr *)&invalid_addr, sizeof(invalid_addr));
ok(ret == -1, "got %d\n", ret);
todo_wine ok(WSAGetLastError() == WSAEALREADY, "got %u\n", WSAGetLastError());
ok(WSAGetLastError() == WSAEALREADY, "got %u\n", WSAGetLastError());
ret = WSAIoctl(client, SIO_GET_EXTENSION_FUNCTION_POINTER, &connectex_guid, sizeof(connectex_guid),
&pConnectEx, sizeof(pConnectEx), &size, NULL, NULL);
@ -10260,7 +10260,7 @@ static void test_connecting_socket(void)
overlapped.InternalHigh = 0xdeadbeef;
ret = pConnectEx(client, (struct sockaddr *)&invalid_addr, sizeof(invalid_addr), NULL, 0, &size, &overlapped);
ok(!ret, "got %d\n", ret);
todo_wine ok(WSAGetLastError() == WSAEINVAL, "got %u\n", WSAGetLastError());
ok(WSAGetLastError() == WSAEINVAL, "got %u\n", WSAGetLastError());
ok((NTSTATUS)overlapped.Internal == STATUS_PENDING, "got status %#x\n", (NTSTATUS)overlapped.Internal);
todo_wine ok(overlapped.InternalHigh == 0xdeadbeef, "got size %Iu\n", overlapped.InternalHigh);

View File

@ -1784,6 +1784,14 @@ static int sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async )
return 0;
}
if (sock->state & FD_CONNECT)
{
/* FIXME: STATUS_ADDRESS_ALREADY_ASSOCIATED probably isn't right,
* but there's no status code that maps to WSAEALREADY... */
set_error( params->synchronous ? STATUS_ADDRESS_ALREADY_ASSOCIATED : STATUS_INVALID_PARAMETER );
return 0;
}
ret = connect( unix_fd, addr, params->addr_len );
if (ret < 0 && errno != EINPROGRESS)
{