ws2_32: Handle SO_ERROR manually in getsockopt().

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 commit is contained in:
Bruno Jesus 2015-04-08 02:02:55 -03:00 committed by Alexandre Julliard
parent b34ca6f4fe
commit 71c60d15d3
2 changed files with 30 additions and 2 deletions

View File

@ -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;

View File

@ -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");