[3/3] ws2_32: Handle SO_ERROR manually in getsockopt()
Bruno Jesus
00cpxxx at gmail.com
Wed Apr 8 00:02:55 CDT 2015
As soon as SO_ERROR is read from getsockopt it is reset in the kernel,
when attempting a non-blocking connection the wine server reads
SO_ERROR first so when the application tries to read the value it will
end with zero. This patch allows us to retrieve the wine server value
if SO_ERROR no longer have it.
Fixes bug https://bugs.winehq.org/show_bug.cgi?id=38372
-------------- next part --------------
---
dlls/ws2_32/socket.c | 31 ++++++++++++++++++++++++++++++-
dlls/ws2_32/tests/sock.c | 1 -
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index ad75a75..6903909 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -3286,7 +3286,6 @@ INT WINAPI WS_getsockopt(SOCKET s, INT level,
* alphabetically */
case WS_SO_BROADCAST:
case WS_SO_DEBUG:
- case WS_SO_ERROR:
case WS_SO_KEEPALIVE:
case WS_SO_OOBINLINE:
case WS_SO_RCVBUF:
@@ -3450,6 +3449,36 @@ INT WINAPI WS_getsockopt(SOCKET s, INT level,
*optlen = sizeof(BOOL);
return 0;
+ case WS_SO_ERROR:
+ {
+ if ( (fd = get_sock_fd( s, 0, NULL )) == -1)
+ return SOCKET_ERROR;
+ if (getsockopt(fd, SOL_SOCKET, SO_ERROR, optval, (socklen_t *)optlen) != 0 )
+ {
+ SetLastError((errno == EBADF) ? WSAENOTSOCK : wsaErrno());
+ ret = SOCKET_ERROR;
+ }
+ release_sock_fd( s, fd );
+
+ /* The wineserver may have swallowed the error before us */
+ if (!ret && *(int*) optval == 0)
+ {
+ int i, events[FD_MAX_EVENTS];
+ _get_sock_errors(s, events);
+ for (i = 0; i < FD_MAX_EVENTS; i++)
+ {
+ if(events[i])
+ {
+ events[i] = NtStatusToWSAError(events[i]);
+ TRACE("returning SO_ERROR %d from wine server\n", events[i]);
+ *(int*) optval = events[i];
+ break;
+ }
+ }
+ }
+ return ret;
+ }
+
case WS_SO_LINGER:
{
struct linger lingval;
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 2b4daae..5f25471 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -3788,7 +3788,6 @@ static void test_select(void)
len = sizeof(id);
id = 0xdeadbeef;
ok(!getsockopt(fdWrite, SOL_SOCKET, SO_ERROR, (char*)&id, &len), "getsockopt failed with %d\n",WSAGetLastError());
-todo_wine
ok(id == WSAECONNREFUSED, "expected 10061, got %d\n", id);
ok(FD_ISSET(fdWrite, &exceptfds), "fdWrite socket is not in the set\n");
ok(select_timeout.tv_usec == 250000, "select timeout should not have changed\n");
--
2.1.4
More information about the wine-patches
mailing list