From 52e4c6db70af28caaf3b43a681d89d5968d4a1a5 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 18 Sep 2019 11:01:40 +0100 Subject: [PATCH] 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. --- renderdoc/os/posix/posix_network.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/renderdoc/os/posix/posix_network.cpp b/renderdoc/os/posix/posix_network.cpp index 1fa90c49b..00844ad92 100644 --- a/renderdoc/os/posix/posix_network.cpp +++ b/renderdoc/os/posix/posix_network.cpp @@ -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();