win32: socket IO fixes.

This commit is contained in:
Daniel Beer 2011-07-27 23:50:54 +12:00
parent 5084d0d925
commit a361e68843
1 changed files with 13 additions and 4 deletions

View File

@ -87,9 +87,18 @@ int sockets_connect(SOCKET s, const struct sockaddr *addr, socklen_t addrlen)
sockets_begin(s, FD_CONNECT); sockets_begin(s, FD_CONNECT);
connect(s, addr, addrlen);
do { do {
ret = connect(s, addr, addrlen); WSANETWORKEVENTS evts;
} while (ret < 0 && !sockets_wait(INFINITE));
WSAEnumNetworkEvents(s, NULL, &evts);
if (evts.lNetworkEvents & FD_CONNECT) {
error_save = evts.iErrorCode[FD_CONNECT_BIT];
if (!error_save)
ret = 0;
break;
}
} while (!sockets_wait(INFINITE));
sockets_end(s); sockets_end(s);
return ret; return ret;
@ -99,7 +108,7 @@ ssize_t sockets_send(SOCKET s, const void *buf, size_t len, int flags)
{ {
int ret = -1; int ret = -1;
sockets_begin(s, FD_WRITE); sockets_begin(s, FD_WRITE | FD_CLOSE);
do { do {
ret = send(s, buf, len, flags); ret = send(s, buf, len, flags);
@ -115,7 +124,7 @@ ssize_t sockets_recv(SOCKET s, void *buf, size_t len, int flags,
int ret = -1; int ret = -1;
DWORD to_arg = (timeout_ms >= 0) ? timeout_ms : INFINITE; DWORD to_arg = (timeout_ms >= 0) ? timeout_ms : INFINITE;
sockets_begin(s, FD_READ); sockets_begin(s, FD_READ | FD_CLOSE);
do { do {
ret = recv(s, buf, len, flags); ret = recv(s, buf, len, flags);