From 89e5218a1de761452ba1c38b512cd3c00c64e3ad Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 15 Aug 2014 22:48:10 +0000 Subject: Fix poll timeout calculation for infinite timeouts. --- lib/server/SocketStream.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'lib/server/SocketStream.cpp') diff --git a/lib/server/SocketStream.cpp b/lib/server/SocketStream.cpp index dafb4338..db71227f 100644 --- a/lib/server/SocketStream.cpp +++ b/lib/server/SocketStream.cpp @@ -218,7 +218,7 @@ int SocketStream::Read(void *pBuffer, int NBytes, int Timeout) p.fd = mSocketHandle; p.events = POLLIN; p.revents = 0; - switch(::poll(&p, 1, PollTimeout(Timeout))) + switch(::poll(&p, 1, PollTimeout(Timeout, 0))) { case -1: // error @@ -287,13 +287,11 @@ bool SocketStream::Poll(short Events, int Timeout) p.revents = 0; box_time_t start = GetCurrentBoxTime(); - box_time_t end = start + MilliSecondsToBoxTime(Timeout); int result; do { - box_time_t now = GetCurrentBoxTime(); - result = ::poll(&p, 1, PollTimeout(end - now)); + result = ::poll(&p, 1, PollTimeout(Timeout, start)); } while(result == -1 && errno == EINTR); @@ -337,7 +335,6 @@ void SocketStream::Write(const void *pBuffer, int NBytes, int Timeout) // Bytes left to send int bytesLeft = NBytes; box_time_t start = GetCurrentBoxTime(); - box_time_t end = start + MilliSecondsToBoxTime(Timeout); while(bytesLeft > 0) { @@ -370,9 +367,7 @@ void SocketStream::Write(const void *pBuffer, int NBytes, int Timeout) mSocketHandle << " (" << bytesLeft << " of " << NBytes << " bytes left)"); - box_time_t now = GetCurrentBoxTime(); - - if(!Poll(POLLOUT, PollTimeout(end - now))) + if(!Poll(POLLOUT, PollTimeout(Timeout, start))) { THROW_EXCEPTION_MESSAGE(ConnectionException, Protocol_Timeout, "Timed out waiting " -- cgit v1.2.3