C4NetIO: Endless polls cut short by cheap hack

heavy-resources
Martin Plicht 2014-01-27 14:09:47 +01:00
parent 3ce7d7ae7f
commit 09e1a47cf9
1 changed files with 10 additions and 0 deletions

View File

@ -385,6 +385,13 @@ bool C4NetIOTCP::CloseBroadcast()
return true;
}
static int fix_poll_timeout(int timeout) {
if (timeout < 0 || timeout > 1000)
return 1000;
else
return timeout;
}
bool C4NetIOTCP::Execute(int iMaxTime, pollfd *fds) // (mt-safe)
{
// security
@ -400,6 +407,8 @@ bool C4NetIOTCP::Execute(int iMaxTime, pollfd *fds) // (mt-safe)
WSANETWORKEVENTS wsaEvents;
#else
iMaxTime = fix_poll_timeout(iMaxTime);
std::vector<pollfd> fdvec;
std::map<SOCKET, const pollfd*> fdmap;
if (!fds)
@ -1529,6 +1538,7 @@ bool C4NetIOSimpleUDP::Execute(int iMaxTime, pollfd *)
// The FIONREAD ioctl call takes an int on unix
int iMaxMsgSize;
#endif
iMaxTime = fix_poll_timeout(iMaxTime);
if (::ioctlsocket(sock, FIONREAD, &iMaxMsgSize) == SOCKET_ERROR)
{
SetError("Could not determine the amount of data that can be read from socket", true);