From f8f60e3b3492c8bdb09f659e8a7be9888985e914 Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Wed, 2 Apr 2008 15:54:45 +0000 Subject: [PATCH] Socket recv calls should detect signals via EINTR and retry the call. --- shibsp/remoting/impl/SocketListener.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/shibsp/remoting/impl/SocketListener.cpp b/shibsp/remoting/impl/SocketListener.cpp index c67492d..e211b20 100644 --- a/shibsp/remoting/impl/SocketListener.cpp +++ b/shibsp/remoting/impl/SocketListener.cpp @@ -305,7 +305,8 @@ DDF SocketListener::send(const DDF& in) log->debug("send completed, reading response message"); // Read the message. - if (recv(sock,(char*)&len,sizeof(len)) != sizeof(len)) { + while (recv(sock,(char*)&len,sizeof(len)) != sizeof(len)) { + if (errno == EINTR) continue; // Apparently this happens when a signal interrupts the blocking call. log->error("error reading size of output message"); this->close(sock); throw ListenerException("Failure receiving response to remoted message ($1).", params(1,in.name())); @@ -315,9 +316,15 @@ DDF SocketListener::send(const DDF& in) char buf[16384]; int size_read; stringstream is; - while (len && (size_read = recv(sock, buf, sizeof(buf))) > 0) { - is.write(buf, size_read); - len -= size_read; + while (len) { + size_read = recv(sock, buf, sizeof(buf)); + if (size_read > 0) { + is.write(buf, size_read); + len -= size_read; + } + else if (errno != EINTR) { + break; + } } if (len) { -- 2.1.4