[comp.unix.programmer] question about non-blocking I/O and SIGPIPE

sundar@ai.mit.edu (Sundar Narasimhan) (03/25/91)

Hi: I have a server that is writing data on a socket to a client.
The socket has been marked for non-blocking I/O using the FIONBIO
ioctl. Now, what I need to know is exactly under what conditions
will a SIGPIPE be generated on the server. 

I've read the man pages, but this info is not found anywhere. 
They say that write() will return -1 and errno will be set to
EWOULDBLOCK when the buffers are full. write() can return a 
value less than the bc passed to it, in case the operation would
block, in which case, the manual says the write should be tried
again. (I'm reading this on a Sparc (Sun OS 4.1.1) and my code
is to run on a Pyramid SysV Unix -- which makes it even more 
confusing since FIONBIO works differently under SysV).

I know all this sounds kinda vague but I'll be happy to explain
it in more detail -- you see I have this server that's dying with
SIGPIPE's and I'd like to know how to fix it right (instead of just
patching it).

leh@atlantis.cis.ufl.edu (Les Hill) (03/26/91)

In article <14318@life.ai.mit.edu>, sundar@ai.mit.edu (Sundar Narasimhan) writes:
|> I've read the man pages, but this info is not found anywhere. 
...asks why he is dying on a SIGPIPE...

You may have indeed read the man pages, you did NOT read them carefully.
The SunOS man page for write(2v) under the ERRORS heading clearly answers your question (look at EPIPE.)

-- 
Extraordinary crimes against the people and the state have to be avenged by
agents extraordinary.  Two such people are John Steed -- top professional, and
his partner, Emma Peel -- talented amateur; otherwise known as "The Avengers."
UUCP: ...!gatech!uflorida!leh    BITNET: vishnu@UFPINE    INTERNET: leh@ufl.edu

sundar@ai.mit.edu (Sundar Narasimhan) (03/26/91)

In article <27643@uflorida.cis.ufl.EDU>, leh@atlantis.cis.ufl.edu (Les Hill) writes:
|> In article <14318@life.ai.mit.edu>, sundar@ai.mit.edu (Sundar Narasimhan) writes:
|> |> I've read the man pages, but this info is not found anywhere. 
|> ...asks why he is dying on a SIGPIPE...
|> 
|> You may have indeed read the man pages, you did NOT read them carefully.
|> The SunOS man page for write(2v) under the ERRORS heading clearly answers your question (look at EPIPE.)
Ok. Maybe I wasn't clear enough in my message. I did read the stuff about
EPIPE but I'm trying to reconcile my understanding of EINTR/EPIPE and 
the sequence of events as they occur when you do a write(). 

Supposing you do a write(fd, buf, 20); Which of the foll. is correct?
	*  If the process on the other side dies DURING the write,
	   (i.e. say after 10 bytes were written), then write will
	   return -1 and errno will be set to EPIPE. SIGPIPE will 
	   be delivered AFTER write() returns.
	* SIGPIPE may be raised DURING the write, causing it to notice
           this, return -1 with errno set to EINTR.
	
Is it also true that with non-blocking I/O set, write returning 0 should
be handled exactly identical to the case when write returns any other
value < bc?