[comp.unix.questions] interrupt driven sockets

pcb@gator.cacs.usl.edu (Peter C. Bahrs) (02/27/90)

>
>I am currently struggling with sockets under SUNOS 3.5. The basic problem is
>trying to implement interrupt driven I/O rather than use the select call
>which I can't use because of other activity within the same process.
>
>The current state of play is that I've succeeded in arranging to have the
>arrival of data at a socket signalled by SIGIO. This was done using the usual
>incantations for setting the owner of the socket to be the process group of
>the process to which the socket belongs, making the socket non-blocking and
>setting its ASYNC flag.
>
>The problem arises because if I write to a socket and get back an EWOULDBLOCK
>error I have no way of knowing, other than polling, when the socket again
>becomes writable. I had hoped that when the state of the socket changed from
>blocked to unblocked that a SIGIO would be generated but from my experiments
>this appears not to be the case.

Well...
I just got through working on this problem, for the time being as I haven't
completely solved it.  My applications used a regular and interrupt socket.
It is my understanding that if an interrupt occurs, some system calls
will return and error (i.e. -1 for read, write, accept,...).  This means
that ?EVERY? system call must be checked as in:
  
   while  (-1 == specific_system_call(...))
      {
      if (errno == EINTR)
         continue;
      else;
      }
    good part here...
This expands in the errno == part to things like ETIMEDOUT, Ewhatever.
So if I am waiting for a read and and interrupt occurs on the other
socket, I will process the other through the handler, return and read
will fail, but I realize it was due to an interrupt, hopefully the one
I just processed??, and retry the read.
Someone please tell me if this is correct.

/*----------- Thanks in advance... --------------------------------------+
| Peter C. Bahrs                                                         |
| The USL-NASA Project                                                   |
| Center For Advanced Computer Studies      INET: pcb@gator.cacs.usl.edu |
| 2 Rex Street                                                           |
| University of Southwestern Louisiana      ...!uunet!dalsqnt!gator!pcb  | 
| Lafayette, LA 70504                                                    |
|------------------------------------------------------------------------|
+-- He who is afraid of asking is ashamed of learning - Fortune Cookie -*/

jhc@iris.brown.edu (James H. Coombs) (02/28/90)

In article <4597@rouge.usl.edu> pcb@gator.cacs.usl.edu (Peter C. Bahrs) 
writes:
> It is my understanding that if an interrupt occurs, some system calls
> will return and error (i.e. -1 for read, write, accept,...).  This means
> that ?EVERY? system call must be checked

Some system calls restart automatically.  In general, you need to check and
restart only for "slow" devices, such as terminals and sockets.  Have to 
run---
check the man page for sigvec() and trace from there.

--Jim

Dr. James H. Coombs
Senior Software Engineer, Research
Institute for Research in Information and Scholarship
Box 1946, Brown University, Providence, RI 02912