mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-12 17:18:57 +00:00
bring old network code back for windows,
narrows the problem with the new code a bit down
This commit is contained in:
parent
aebaa6481a
commit
ff1fecc7e6
@ -148,6 +148,16 @@ bool receive_with_timeout(TCPsocket s, char* buf, size_t nbytes, bool update_sta
|
||||
{
|
||||
int nsleeps = 0;
|
||||
while(nbytes > 0) {
|
||||
#ifdef _WIN32
|
||||
{
|
||||
// if we are receiving the socket is in sockets_locked
|
||||
// check if it is still locked
|
||||
const threading::lock lock(*global_mutex);
|
||||
if(sockets_locked[s] != SOCKET_LOCKED) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif //_WIN32
|
||||
const int bytes_read = receive_bytes(s, buf, nbytes);
|
||||
if(bytes_read == 0) {
|
||||
return false;
|
||||
@ -160,6 +170,37 @@ bool receive_with_timeout(TCPsocket s, char* buf, size_t nbytes, bool update_sta
|
||||
if(false)
|
||||
#endif
|
||||
{
|
||||
#ifdef _WIN32
|
||||
#ifdef USE_POLL
|
||||
struct pollfd fd = { ((_TCPsocket*)s)->channel, POLLIN, 0 };
|
||||
int poll_res;
|
||||
do {
|
||||
poll_res = poll(&fd, 1, 15000);
|
||||
} while(poll_res == -1 && errno == EINTR);
|
||||
|
||||
if(poll_res > 0)
|
||||
continue;
|
||||
#elif defined(USE_SELECT)
|
||||
fd_set readfds;
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(((_TCPsocket*)s)->channel, &readfds);
|
||||
int retval;
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 15;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
do {
|
||||
retval = select(((_TCPsocket*)s)->channel + 1, &readfds, NULL, NULL, &tv);
|
||||
} while(retval == -1 && errno == EINTR);
|
||||
|
||||
if(retval > 0)
|
||||
continue;
|
||||
#endif
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#else //_WIN32
|
||||
//TODO: consider replacing this with a select call
|
||||
if(++nsleeps == timeout_ms) {
|
||||
return false;
|
||||
@ -173,13 +214,16 @@ bool receive_with_timeout(TCPsocket s, char* buf, size_t nbytes, bool update_sta
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif //_WIN32
|
||||
nbytes -= bytes_read;
|
||||
buf += bytes_read;
|
||||
if(update_stats) {
|
||||
const threading::lock lock(*global_mutex);
|
||||
transfer_stats[s].second.transfer(static_cast<size_t>(bytes_read));
|
||||
}
|
||||
#ifndef _WIN32
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user