server: Automatically sets a socket to non-blocking mode when WSAAsyncSelect or WSAEventSelect is called even when lEvent is zero.

This commit is contained in:
Qian Hong 2013-05-22 16:51:38 +08:00 committed by Alexandre Julliard
parent 8d18b89346
commit 31b9455b7e
2 changed files with 58 additions and 2 deletions

View File

@ -3571,6 +3571,8 @@ static void test_events(int useMessages)
goto end; goto end;
} }
ok(!set_blocking(src, TRUE), "set_blocking failed, error %d\n", WSAGetLastError());
src2 = socket(AF_INET, SOCK_STREAM, 0); src2 = socket(AF_INET, SOCK_STREAM, 0);
if (src2 == INVALID_SOCKET) if (src2 == INVALID_SOCKET)
{ {
@ -3578,6 +3580,8 @@ static void test_events(int useMessages)
goto end; goto end;
} }
ok(!set_blocking(src2, TRUE), "set_blocking failed, error %d\n", WSAGetLastError());
len = sizeof(BOOL); len = sizeof(BOOL);
if (getsockopt(src, SOL_SOCKET, SO_OOBINLINE, (void *)&bret, &len) == SOCKET_ERROR) if (getsockopt(src, SOL_SOCKET, SO_OOBINLINE, (void *)&bret, &len) == SOCKET_ERROR)
{ {
@ -3618,12 +3622,18 @@ static void test_events(int useMessages)
goto end; goto end;
} }
ok(set_blocking(src, TRUE) == SOCKET_ERROR, "set_blocking should failed!\n");
ok(WSAGetLastError() == WSAEINVAL, "expect WSAEINVAL, returned %x\n", WSAGetLastError());
ret = WSAAsyncSelect(src2, hWnd, WM_SOCKET, FD_CONNECT | FD_READ | FD_OOB | FD_WRITE | FD_CLOSE); ret = WSAAsyncSelect(src2, hWnd, WM_SOCKET, FD_CONNECT | FD_READ | FD_OOB | FD_WRITE | FD_CLOSE);
if (ret) if (ret)
{ {
ok(0, "WSAAsyncSelect failed, error %d\n", ret); ok(0, "WSAAsyncSelect failed, error %d\n", ret);
goto end; goto end;
} }
ok(set_blocking(src2, TRUE) == SOCKET_ERROR, "set_blocking should failed!\n");
ok(WSAGetLastError() == WSAEINVAL, "expect WSAEINVAL, returned %x\n", WSAGetLastError());
} }
else else
{ {
@ -3650,12 +3660,18 @@ static void test_events(int useMessages)
goto end; goto end;
} }
ok(set_blocking(src, TRUE) == SOCKET_ERROR, "set_blocking should failed!\n");
ok(WSAGetLastError() == WSAEINVAL, "expect WSAEINVAL, returned %x\n", WSAGetLastError());
ret = WSAEventSelect(src2, hEvent2, FD_CONNECT | FD_READ | FD_OOB | FD_WRITE | FD_CLOSE); ret = WSAEventSelect(src2, hEvent2, FD_CONNECT | FD_READ | FD_OOB | FD_WRITE | FD_CLOSE);
if (ret) if (ret)
{ {
ok(0, "WSAEventSelect failed, error %d\n", ret); ok(0, "WSAEventSelect failed, error %d\n", ret);
goto end; goto end;
} }
ok(set_blocking(src2, TRUE) == SOCKET_ERROR, "set_blocking should failed!\n");
ok(WSAGetLastError() == WSAEINVAL, "expect WSAEINVAL, returned %x\n", WSAGetLastError());
} }
server = socket(AF_INET, SOCK_STREAM, 0); server = socket(AF_INET, SOCK_STREAM, 0);
@ -3988,6 +4004,47 @@ static void test_events(int useMessages)
ok(ret == 1, "Sending to half-closed socket failed %d err %d\n", ret, GetLastError()); ok(ret == 1, "Sending to half-closed socket failed %d err %d\n", ret, GetLastError());
ok_event_seq(src2, hEvent2, empty_seq, NULL, 0); ok_event_seq(src2, hEvent2, empty_seq, NULL, 0);
if (useMessages)
{
ret = WSAAsyncSelect(src, hWnd, WM_SOCKET, 0);
if (ret)
{
ok(0, "WSAAsyncSelect failed, error %d\n", ret);
goto end;
}
ok(!set_blocking(src, TRUE), "set_blocking failed, error %d\n", WSAGetLastError());
ret = WSAAsyncSelect(src2, hWnd, WM_SOCKET, 0);
if (ret)
{
ok(0, "WSAAsyncSelect failed, error %d\n", ret);
goto end;
}
ok(!set_blocking(src2, TRUE), "set_blocking failed, error %d\n", WSAGetLastError());
}
else
{
ret = WSAEventSelect(src, hEvent2, 0);
if (ret)
{
ok(0, "WSAAsyncSelect failed, error %d\n", ret);
goto end;
}
ok(!set_blocking(src, TRUE), "set_blocking failed, error %d\n", WSAGetLastError());
ret = WSAEventSelect(src2, hEvent2, 0);
if (ret)
{
ok(0, "WSAAsyncSelect failed, error %d\n", ret);
goto end;
}
ok(!set_blocking(src2, TRUE), "set_blocking failed, error %d\n", WSAGetLastError());
}
end: end:
if (src != INVALID_SOCKET) if (src != INVALID_SOCKET)
{ {

View File

@ -978,8 +978,7 @@ DECL_HANDLER(set_socket_event)
sock_reselect( sock ); sock_reselect( sock );
if (sock->mask) sock->state |= FD_WINE_NONBLOCKING;
sock->state |= FD_WINE_NONBLOCKING;
/* if a network event is pending, signal the event object /* if a network event is pending, signal the event object
it is possible that FD_CONNECT or FD_ACCEPT network events has happened it is possible that FD_CONNECT or FD_ACCEPT network events has happened