[vtk-developers] Proposed change to vtkSocket.cxx

Moreland, Kenneth kmorel at sandia.gov
Wed Jul 23 09:46:54 EDT 2008


Not long ago while on travel I was using ParaView over a very slow network connection.  I noticed that I kept getting errors that the connection dropped even though there was no particular reason why it should fail (and in fact, the connection was still up).

After some poking around, I noticed that the recv call was returning before any data was retrieved because it was apparently interrupted by a signal.  I found that the attached patch fixes the problem by simply retrying the recv if it is interrupted by a signal.

Are there any objections to applying this patch to vtkSocket.cxx below?

-Ken


Index: vtkSocket.cxx
===================================================================
RCS file: /cvsroot/ParaView3/ParaView3/VTK/Common/vtkSocket.cxx,v
retrieving revision 1.2
diff -u -r1.2 vtkSocket.cxx
--- vtkSocket.cxx       22 Apr 2008 16:42:57 -0000      1.2
+++ vtkSocket.cxx       9 Jul 2008 18:23:46 -0000
@@ -37,6 +37,7 @@
   #include <netdb.h>
   #include <unistd.h>
   #include <sys/time.h>
+  #include <errno.h>
 #endif
 #endif

@@ -374,9 +375,7 @@
   int total = 0;
   do
     {
-#if defined(_WIN32) && !defined(__CYGWIN__)
     int trys = 0;
-#endif
     int n = recv(this->SocketDescriptor, buffer+total, length-total, 0);
     if(n < 1)
       {
@@ -389,6 +388,15 @@
         Sleep(1);
         continue;
         }
+#else
+      // On unix, a recv may be interrupted by a signal.  In this case we should
+      // retry.
+      int errorNumber = errno;
+      if ((errorNumber == EINTR) && (trys++ < 1000))
+        {
+        usleep(1);
+        continue;
+        }
 #endif
       vtkErrorMacro("Socket Error: Receive failed.");
       return 0;




More information about the vtk-developers mailing list