[vtk-developers] Proposed change to vtkSocket.cxx

Brad King brad.king at kitware.com
Wed Jul 23 09:52:53 EDT 2008


Moreland, Kenneth wrote:
> 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.
[snip]
>      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;
> +        }

Good catch.  However, I don't think there needs to be a limited attempt
count or a usleep to yield.  It can just try again immediately.  This is
a common idiom on posix system calls.

-Brad



More information about the vtk-developers mailing list