Commit 5d6d2fda authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

wininet: Use set_socket_blocking helper in a few more places.

parent 7410bf58
......@@ -346,6 +346,14 @@ void init_winsock(void)
#endif
}
static void set_socket_blocking(int socket, blocking_mode_t mode)
{
#ifdef USE_WINSOCK
ULONG arg = mode == BLOCKING_DISALLOW;
ioctlsocket(socket, FIONBIO, &arg);
#endif
}
static DWORD create_netconn_socket(server_t *server, netconn_t *netconn, DWORD timeout)
{
int result;
......@@ -357,8 +365,7 @@ static DWORD create_netconn_socket(server_t *server, netconn_t *netconn, DWORD t
assert(server->addr_len);
result = netconn->socket = socket(server->addr.ss_family, SOCK_STREAM, 0);
if(result != -1) {
flag = 1;
ioctlsocket(netconn->socket, FIONBIO, &flag);
set_socket_blocking(netconn->socket, BLOCKING_DISALLOW);
result = connect(netconn->socket, (struct sockaddr*)&server->addr, server->addr_len);
if(result == -1)
{
......@@ -391,8 +398,7 @@ static DWORD create_netconn_socket(server_t *server, netconn_t *netconn, DWORD t
netconn->socket = -1;
}
else {
flag = 0;
ioctlsocket(netconn->socket, FIONBIO, &flag);
set_socket_blocking(netconn->socket, BLOCKING_ALLOW);
}
}
if(result == -1)
......@@ -573,14 +579,6 @@ int sock_recv(int fd, void *msg, size_t len, int flags)
return ret;
}
static void set_socket_blocking(int socket, blocking_mode_t mode)
{
#ifdef USE_WINSOCK
ULONG arg = mode == BLOCKING_DISALLOW;
ioctlsocket(socket, FIONBIO, &arg);
#endif
}
static DWORD netcon_secure_connect_setup(netconn_t *connection, BOOL compat_mode)
{
SecBuffer out_buf = {0, SECBUFFER_TOKEN, NULL}, in_bufs[2] = {{0, SECBUFFER_TOKEN}, {0, SECBUFFER_EMPTY}};
......@@ -1079,19 +1077,12 @@ BOOL NETCON_is_alive(netconn_t *netconn)
len = sock_recv(netconn->socket, &b, 1, MSG_PEEK|MSG_DONTWAIT);
return len == 1 || (len == -1 && sock_get_error() == WSAEWOULDBLOCK);
#elif defined(USE_WINSOCK)
ULONG mode;
int len;
char b;
mode = 1;
if(ioctlsocket(netconn->socket, FIONBIO, &mode))
return FALSE;
set_socket_blocking(netconn->socket, BLOCKING_DISALLOW);
len = sock_recv(netconn->socket, &b, 1, MSG_PEEK);
mode = 0;
if(ioctlsocket(netconn->socket, FIONBIO, &mode))
return FALSE;
set_socket_blocking(netconn->socket, BLOCKING_ALLOW);
return len == 1 || (len == -1 && sock_get_error() == WSAEWOULDBLOCK);
#else
......
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