Socket recv calls should detect signals via EINTR and retry the call.
authorScott Cantor <cantor.2@osu.edu>
Wed, 2 Apr 2008 15:54:45 +0000 (15:54 +0000)
committerScott Cantor <cantor.2@osu.edu>
Wed, 2 Apr 2008 15:54:45 +0000 (15:54 +0000)
shibsp/remoting/impl/SocketListener.cpp

index c67492d..e211b20 100644 (file)
@@ -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) {