Commit efef51d7 authored by rswindell's avatar rswindell
Browse files

Define nonblocking_connect() for use with bon-blocking sockets.

parent 700a6510
......@@ -362,3 +362,23 @@ int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen
}
return(result);
}
int nonblocking_connect(SOCKET sock, struct sockaddr* addr, size_t size, unsigned timeout)
{
int result;
result=connect(sock, addr, size);
if(result==SOCKET_ERROR
&& (ERROR_VALUE==EWOULDBLOCK || ERROR_VALUE==EINPROGRESS)) {
fd_set socket_set;
struct timeval tv;
tv.tv_sec = timeout;
tv.tv_usec = 0;
FD_ZERO(&socket_set);
FD_SET(sock,&socket_set);
if(select(sock,NULL,&socket_set,NULL,&tv)==1)
return 0; /* success */
}
return result;
}
......@@ -178,6 +178,7 @@ BOOL socket_check(SOCKET sock, BOOL* rd_p, BOOL* wr_p, DWORD timeout);
int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen
,uint retries, uint wait_secs, const char* prot
,int (*lprintf)(int level, const char *fmt, ...));
int nonblocking_connect(SOCKET, struct sockaddr*, size_t, unsigned timeout /* seconds */);
#ifdef __cplusplus
}
......
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