"Interrupted system call", read and socket

  • Follow


Hello,

I have a server application and a client one which communicate with 
sockets and SSH tunneling (ssh -N -f -L8888:localhost:3333 
user@localhost). I have to use ssh tunneling because of firewalls.

My problem is that the read in the client has the "Interrupted system 
call" error even if I put this
  while(-1==(nr=read(DIST,ptr,nl)))
         {
           if(errno!=EINTR)
             break;
         }

and it appears randomly.

If I do not use ssh tunneling, it works.

If someone has an idea ...

Thanks,

Karim.

0
Reply karim 1/9/2004 7:19:20 PM

karim bernardet wrote:

> Hello,
> 
> I have a server application and a client one which communicate with
> sockets and SSH tunneling (ssh -N -f -L8888:localhost:3333
> user@localhost). I have to use ssh tunneling because of firewalls.
> 
> My problem is that the read in the client has the "Interrupted system
> call" error even if I put this
>   while(-1==(nr=read(DIST,ptr,nl)))
>          {
>            if(errno!=EINTR)
>              break;
>          }
> 
> and it appears randomly.
> 
> If I do not use ssh tunneling, it works.
> 
> If someone has an idea ...
> 
> Thanks,
> 
> Karim.

No idea.
Typically, you will receive this error when the syscall blocks and a signal
is delivered.
However why bother, just resume read().
E.g.:

int readn(int fd, void* data, size_t size)
{
        for (;;) {
                ssize_t n = read(fd, data, size);
                if (n == -1) {
                        if (errno == EINTR)
                                continue;  // Resume.

                        return errno;
                }

                if (!(size -= n))
                        return 0;

                data = (char*)data + n;
        }
}

/FAU

0
Reply Frank 1/10/2004 9:29:50 AM


Hello Karim, 

> > I have a server application and a client one which communicate with
> > sockets and SSH tunneling (ssh -N -f -L8888:localhost:3333
> > user@localhost). I have to use ssh tunneling because of firewalls.
> > 
> > My problem is that the read in the client has the "Interrupted system
> > call" error even if I put this
> >   while(-1==(nr=read(DIST,ptr,nl)))
> >          {
> >            if(errno!=EINTR)
> >              break;
> >          }
> > 
> > and it appears randomly.

So basically, you resume the read() and you still get an "Interrupted
system call"?

Whether your loop construct is wrong (doesn't look like to me. Though
I prefer Frank's construct which is somewhat nicier to read)...

Or it's not the read() call that got interrupted... 


Regards,
Loic.
0
Reply loic 1/11/2004 3:22:25 PM

2 Replies
996 Views

(page loaded in 0.103 seconds)

Similiar Articles:













7/23/2012 12:56:35 PM


Reply: