Commit 4ca53984 authored by Bruno Jesus's avatar Bruno Jesus Committed by Alexandre Julliard

ws2_32/tests: Improve setup_connector_socket to allow non-blocking connect calls.

parent 9eaf92d6
...@@ -196,6 +196,9 @@ static int client_id; ...@@ -196,6 +196,9 @@ static int client_id;
/**************** General utility functions ***************/ /**************** General utility functions ***************/
static SOCKET setup_server_socket(struct sockaddr_in *addr, int *len);
static SOCKET setup_connector_socket(struct sockaddr_in *addr, int len, BOOL nonblock);
static int tcp_socketpair(SOCKET *src, SOCKET *dst) static int tcp_socketpair(SOCKET *src, SOCKET *dst)
{ {
SOCKET server = INVALID_SOCKET; SOCKET server = INVALID_SOCKET;
...@@ -3632,7 +3635,7 @@ static SOCKET setup_server_socket(struct sockaddr_in *addr, int *len) ...@@ -3632,7 +3635,7 @@ static SOCKET setup_server_socket(struct sockaddr_in *addr, int *len)
return server_socket; return server_socket;
} }
static SOCKET setup_connector_socket(struct sockaddr_in *addr, int len) static SOCKET setup_connector_socket(struct sockaddr_in *addr, int len, BOOL nonblock)
{ {
int ret; int ret;
SOCKET connector; SOCKET connector;
...@@ -3640,8 +3643,18 @@ static SOCKET setup_connector_socket(struct sockaddr_in *addr, int len) ...@@ -3640,8 +3643,18 @@ static SOCKET setup_connector_socket(struct sockaddr_in *addr, int len)
connector = socket(AF_INET, SOCK_STREAM, 0); connector = socket(AF_INET, SOCK_STREAM, 0);
ok(connector != INVALID_SOCKET, "failed to create connector socket %d\n", WSAGetLastError()); ok(connector != INVALID_SOCKET, "failed to create connector socket %d\n", WSAGetLastError());
if (nonblock)
set_blocking(connector, !nonblock);
ret = connect(connector, (struct sockaddr *)addr, len); ret = connect(connector, (struct sockaddr *)addr, len);
if (!nonblock)
ok(!ret, "connecting to accepting socket failed %d\n", WSAGetLastError()); ok(!ret, "connecting to accepting socket failed %d\n", WSAGetLastError());
else if (ret == SOCKET_ERROR)
{
DWORD error = WSAGetLastError();
ok(error == WSAEWOULDBLOCK || error == WSAEINPROGRESS,
"expected 10035 or 10036, got %d\n", error);
}
return connector; return connector;
} }
...@@ -3669,7 +3682,7 @@ static void test_accept(void) ...@@ -3669,7 +3682,7 @@ static void test_accept(void)
return; return;
} }
connector = setup_connector_socket(&address, socklen); connector = setup_connector_socket(&address, socklen, FALSE);
if (connector == INVALID_SOCKET) goto done; if (connector == INVALID_SOCKET) goto done;
trace("Blocking accept next\n"); trace("Blocking accept next\n");
...@@ -3717,7 +3730,7 @@ static void test_accept(void) ...@@ -3717,7 +3730,7 @@ static void test_accept(void)
server_socket = setup_server_socket(&address, &socklen); server_socket = setup_server_socket(&address, &socklen);
if (server_socket == INVALID_SOCKET) goto done; if (server_socket == INVALID_SOCKET) goto done;
connector = setup_connector_socket(&address, socklen); connector = setup_connector_socket(&address, socklen, FALSE);
if (connector == INVALID_SOCKET) goto done; if (connector == INVALID_SOCKET) goto done;
socklen = 0; socklen = 0;
...@@ -3728,7 +3741,7 @@ static void test_accept(void) ...@@ -3728,7 +3741,7 @@ static void test_accept(void)
connector = INVALID_SOCKET; connector = INVALID_SOCKET;
socklen = sizeof(address); socklen = sizeof(address);
connector = setup_connector_socket(&address, socklen); connector = setup_connector_socket(&address, socklen, FALSE);
if (connector == INVALID_SOCKET) goto done; if (connector == INVALID_SOCKET) goto done;
accepted = WSAAccept(server_socket, NULL, NULL, NULL, 0); accepted = WSAAccept(server_socket, NULL, NULL, NULL, 0);
...@@ -3738,7 +3751,7 @@ static void test_accept(void) ...@@ -3738,7 +3751,7 @@ static void test_accept(void)
accepted = connector = INVALID_SOCKET; accepted = connector = INVALID_SOCKET;
socklen = sizeof(address); socklen = sizeof(address);
connector = setup_connector_socket(&address, socklen); connector = setup_connector_socket(&address, socklen, FALSE);
if (connector == INVALID_SOCKET) goto done; if (connector == INVALID_SOCKET) goto done;
socklen = sizeof(ss); socklen = sizeof(ss);
...@@ -3752,7 +3765,7 @@ static void test_accept(void) ...@@ -3752,7 +3765,7 @@ static void test_accept(void)
accepted = connector = INVALID_SOCKET; accepted = connector = INVALID_SOCKET;
socklen = sizeof(address); socklen = sizeof(address);
connector = setup_connector_socket(&address, socklen); connector = setup_connector_socket(&address, socklen, FALSE);
if (connector == INVALID_SOCKET) goto done; if (connector == INVALID_SOCKET) goto done;
socklen = 0; socklen = 0;
...@@ -3763,7 +3776,7 @@ static void test_accept(void) ...@@ -3763,7 +3776,7 @@ static void test_accept(void)
accepted = connector = INVALID_SOCKET; accepted = connector = INVALID_SOCKET;
socklen = sizeof(address); socklen = sizeof(address);
connector = setup_connector_socket(&address, socklen); connector = setup_connector_socket(&address, socklen, FALSE);
if (connector == INVALID_SOCKET) goto done; if (connector == INVALID_SOCKET) goto done;
accepted = accept(server_socket, NULL, NULL); accepted = accept(server_socket, NULL, NULL);
...@@ -3773,7 +3786,7 @@ static void test_accept(void) ...@@ -3773,7 +3786,7 @@ static void test_accept(void)
accepted = connector = INVALID_SOCKET; accepted = connector = INVALID_SOCKET;
socklen = sizeof(address); socklen = sizeof(address);
connector = setup_connector_socket(&address, socklen); connector = setup_connector_socket(&address, socklen, FALSE);
if (connector == INVALID_SOCKET) goto done; if (connector == INVALID_SOCKET) goto done;
socklen = sizeof(ss); socklen = sizeof(ss);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment