Module: wine Branch: oldstable Commit: 5a174e05f41502caa096a54e26878330b25af35d URL: https://source.winehq.org/git/wine.git/?a=commit;h=5a174e05f41502caa096a54e2...
Author: Alistair Leslie-Hughes leslie_alistair@hotmail.com Date: Mon Jul 27 12:51:46 2020 +1000
ws2_32: Correct returned error code for an invalid socket.
Signed-off-by: Alistair Leslie-Hughes leslie_alistair@hotmail.com Signed-off-by: Alexandre Julliard julliard@winehq.org (cherry picked from commit 587732acb7834a52a2af5bb45e59899ab8ec3f5d) Signed-off-by: Michael Stefaniuc mstefani@winehq.org
---
dlls/ws2_32/socket.c | 32 +++++++------------------------- dlls/ws2_32/tests/sock.c | 7 ++----- 2 files changed, 9 insertions(+), 30 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 374eec37f2e..73c605238ed 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -1117,8 +1117,8 @@ static DWORD NtStatusToWSAError( DWORD status ) { case STATUS_SUCCESS: return 0; case STATUS_PENDING: return WSA_IO_PENDING; + case STATUS_INVALID_HANDLE: case STATUS_OBJECT_TYPE_MISMATCH: return WSAENOTSOCK; - case STATUS_INVALID_HANDLE: return WSAEBADF; case STATUS_INVALID_PARAMETER: return WSAEINVAL; case STATUS_PIPE_DISCONNECTED: return WSAESHUTDOWN; case STATUS_NETWORK_BUSY: return WSAEALREADY; @@ -2887,19 +2887,11 @@ static BOOL WINAPI WS2_AcceptEx(SOCKET listener, SOCKET acceptor, PVOID dest, DW }
fd = get_sock_fd( listener, FILE_READ_DATA, NULL ); - if (fd == -1) - { - SetLastError(WSAENOTSOCK); - return FALSE; - } + if (fd == -1) return FALSE; release_sock_fd( listener, fd );
fd = get_sock_fd( acceptor, FILE_READ_DATA, NULL ); - if (fd == -1) - { - SetLastError(WSAENOTSOCK); - return FALSE; - } + if (fd == -1) return FALSE; release_sock_fd( acceptor, fd );
wsa = (struct ws2_accept_async *)alloc_async_io( sizeof(*wsa), WS2_async_accept ); @@ -3145,11 +3137,8 @@ static BOOL WINAPI WS2_TransmitFile( SOCKET s, HANDLE h, DWORD file_bytes, DWORD buffers, flags );
fd = get_sock_fd( s, FILE_WRITE_DATA, NULL ); - if (fd == -1) - { - WSASetLastError( WSAENOTSOCK ); - return FALSE; - } + if (fd == -1) return FALSE; + if (getpeername( fd, &uaddr.addr, &uaddrlen ) != 0) { release_sock_fd( s, fd ); @@ -3495,8 +3484,6 @@ int WINAPI WS_closesocket(SOCKET s) if (CloseHandle(SOCKET2HANDLE(s))) res = 0; } - else - SetLastError(WSAENOTSOCK); } else SetLastError(WSANOTINITIALISED); @@ -3607,11 +3594,7 @@ static BOOL WINAPI WS2_ConnectEx(SOCKET s, const struct WS_sockaddr* name, int n }
fd = get_sock_fd( s, FILE_READ_DATA, NULL ); - if (fd == -1) - { - SetLastError( WSAENOTSOCK ); - return FALSE; - } + if (fd == -1) return FALSE;
TRACE("socket %04lx, ptr %p %s, length %d, sendptr %p, len %d, ov %p\n", s, name, debugstr_sockaddr(name), namelen, sendBuf, sendBufLen, ov); @@ -5205,8 +5188,7 @@ int WINAPI WS_listen(SOCKET s, int backlog) SetLastError(wsaErrno()); release_sock_fd( s, fd ); } - else - SetLastError(WSAENOTSOCK); + return ret; }
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index bf1aeefb852..15954b0fa91 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -1562,7 +1562,6 @@ todo_wine size = sizeof(i); i = 1234; err = getsockopt(s, SOL_SOCKET, SO_ERROR, (char *) &i, &size); -todo_wine ok( (err == SOCKET_ERROR) && (WSAGetLastError() == WSAENOTSOCK), "got %d with %d (expected SOCKET_ERROR with WSAENOTSOCK)\n", err, WSAGetLastError()); @@ -4152,8 +4151,7 @@ static void test_select(void) SetLastError(0xdeadbeef); ret = select(0, &readfds, NULL, &exceptfds, &select_timeout); ok(ret == SOCKET_ERROR, "expected -1, got %d\n", ret); -todo_wine - ok(GetLastError() == WSAENOTSOCK, "expected 10038, got %d\n", GetLastError()); + ok(GetLastError() == WSAENOTSOCK, "got %d\n", GetLastError()); /* descriptor sets are unchanged */ ok(readfds.fd_count == 2, "expected 2, got %d\n", readfds.fd_count); ok(exceptfds.fd_count == 2, "expected 2, got %d\n", exceptfds.fd_count); @@ -4180,8 +4178,7 @@ todo_wine ret = select(0, NULL, NULL, &exceptfds, &select_timeout); todo_wine ok(ret == SOCKET_ERROR, "expected -1, got %d\n", ret); -todo_wine - ok(GetLastError() == WSAENOTSOCK, "expected 10038, got %d\n", GetLastError()); + ok(GetLastError() == WSAENOTSOCK, "got %d\n", GetLastError()); WaitForSingleObject (thread_handle, 1000); closesocket(fdRead);