If we hit EINTR in a blocking recv/send, retry instead of failing

* blocking send/recv will not be resumed after a signal handler no matter what,
  so we need to retry ourselves. This does mean extending the timeout but that's
  fine since it would be pathological to have EINTR continually arrive and
  extend the timeout to an unreasonable duration.
This commit is contained in:
baldurk
2019-09-18 11:01:40 +01:00
parent 8060693188
commit 52e4c6db70
+14 -2
View File
@@ -167,7 +167,13 @@ bool Socket::SendDataBlocking(const void *buf, uint32_t length)
{
int err = errno;
if(err == EWOULDBLOCK || err == EAGAIN || err == EINTR)
if(err == EINTR)
{
// if we hit EINTR, just try again completely. Technically this restarts the timeout but we
// expect EINTR to be rare so it's not a big deal.
continue;
}
else if(err == EWOULDBLOCK || err == EAGAIN)
{
RDCWARN("Timeout in send");
Shutdown();
@@ -293,7 +299,13 @@ bool Socket::RecvDataBlocking(void *buf, uint32_t length)
{
int err = errno;
if(err == EWOULDBLOCK || err == EAGAIN || err == EINTR)
if(err == EINTR)
{
// if we hit EINTR, just try again completely. Technically this restarts the timeout but we
// expect EINTR to be rare so it's not a big deal.
continue;
}
else if(err == EWOULDBLOCK || err == EAGAIN)
{
RDCWARN("Timeout in recv");
Shutdown();