ws2_32: Return the right value for SO_CONNECT_TIME if the socket is not connected.

This commit is contained in:
Hans Leidekker 2011-12-19 15:42:08 +01:00 committed by Alexandre Julliard
parent 895e7a5f5b
commit c42989ed9a
2 changed files with 23 additions and 4 deletions

View File

@ -2548,14 +2548,21 @@ INT WINAPI WS_getsockopt(SOCKET s, INT level,
case WS_SO_CONNECT_TIME: case WS_SO_CONNECT_TIME:
{ {
static int pretendtime = 0; static int pretendtime = 0;
struct WS_sockaddr addr;
int len = sizeof(addr);
if (!pretendtime) FIXME("WS_SO_CONNECT_TIME - faking results\n");
if (!optlen || *optlen < sizeof(DWORD) || !optval) if (!optlen || *optlen < sizeof(DWORD) || !optval)
{ {
SetLastError(WSAEFAULT); SetLastError(WSAEFAULT);
return SOCKET_ERROR; return SOCKET_ERROR;
} }
*(DWORD*)optval = pretendtime++; if (WS_getpeername(s, &addr, &len) == SOCKET_ERROR)
*(DWORD *)optval = ~0u;
else
{
if (!pretendtime) FIXME("WS_SO_CONNECT_TIME - faking results\n");
*(DWORD *)optval = pretendtime++;
}
*optlen = sizeof(DWORD); *optlen = sizeof(DWORD);
return ret; return ret;
} }

View File

@ -4496,14 +4496,14 @@ static void test_AcceptEx(void)
SOCKET connector = INVALID_SOCKET; SOCKET connector = INVALID_SOCKET;
SOCKET connector2 = INVALID_SOCKET; SOCKET connector2 = INVALID_SOCKET;
struct sockaddr_in bindAddress, peerAddress, *readBindAddress, *readRemoteAddress; struct sockaddr_in bindAddress, peerAddress, *readBindAddress, *readRemoteAddress;
int socklen; int socklen, optlen;
GUID acceptExGuid = WSAID_ACCEPTEX, getAcceptExGuid = WSAID_GETACCEPTEXSOCKADDRS; GUID acceptExGuid = WSAID_ACCEPTEX, getAcceptExGuid = WSAID_GETACCEPTEXSOCKADDRS;
LPFN_ACCEPTEX pAcceptEx = NULL; LPFN_ACCEPTEX pAcceptEx = NULL;
LPFN_GETACCEPTEXSOCKADDRS pGetAcceptExSockaddrs = NULL; LPFN_GETACCEPTEXSOCKADDRS pGetAcceptExSockaddrs = NULL;
fd_set fds_accept, fds_send; fd_set fds_accept, fds_send;
struct timeval timeout = {0,10}; /* wait for 10 milliseconds */ struct timeval timeout = {0,10}; /* wait for 10 milliseconds */
int got, conn1, i; int got, conn1, i;
DWORD bytesReturned; DWORD bytesReturned, connect_time;
char buffer[1024]; char buffer[1024];
OVERLAPPED overlapped; OVERLAPPED overlapped;
int iret, localSize = sizeof(struct sockaddr_in), remoteSize = localSize; int iret, localSize = sizeof(struct sockaddr_in), remoteSize = localSize;
@ -4695,9 +4695,21 @@ static void test_AcceptEx(void)
&bytesReturned, &overlapped); &bytesReturned, &overlapped);
ok(bret == FALSE && WSAGetLastError() == ERROR_IO_PENDING, "AcceptEx returned %d + errno %d\n", bret, WSAGetLastError()); ok(bret == FALSE && WSAGetLastError() == ERROR_IO_PENDING, "AcceptEx returned %d + errno %d\n", bret, WSAGetLastError());
connect_time = 0xdeadbeef;
optlen = sizeof(connect_time);
iret = getsockopt(connector, SOL_SOCKET, SO_CONNECT_TIME, (char *)&connect_time, &optlen);
ok(!iret, "getsockopt failed %d\n", WSAGetLastError());
ok(connect_time == ~0u, "unexpected connect time %u\n", connect_time);
iret = connect(connector, (struct sockaddr*)&bindAddress, sizeof(bindAddress)); iret = connect(connector, (struct sockaddr*)&bindAddress, sizeof(bindAddress));
ok(iret == 0, "connecting to accepting socket failed, error %d\n", WSAGetLastError()); ok(iret == 0, "connecting to accepting socket failed, error %d\n", WSAGetLastError());
connect_time = 0xdeadbeef;
optlen = sizeof(connect_time);
iret = getsockopt(connector, SOL_SOCKET, SO_CONNECT_TIME, (char *)&connect_time, &optlen);
ok(!iret, "getsockopt failed %d\n", WSAGetLastError());
ok(connect_time < 0xdeadbeef, "unexpected connect time %u\n", connect_time);
dwret = WaitForSingleObject(overlapped.hEvent, 0); dwret = WaitForSingleObject(overlapped.hEvent, 0);
ok(dwret == WAIT_TIMEOUT, "Waiting for accept event timeout failed with %d + errno %d\n", dwret, GetLastError()); ok(dwret == WAIT_TIMEOUT, "Waiting for accept event timeout failed with %d + errno %d\n", dwret, GetLastError());