Re: How to handle Broken Pipe

Vu Nguyen writes:
> While testing my server which is based on the Mini Server, I ran into =
> this problem:  If I issue a request for a document from the browser and, =
> then hit the 'Stop' button while the document being transferred then I =
> have a broken pipe.  This occurs in HTWriter_write (HTStream * me, CONST =
> char * buf, int len)
> 
> below is the line which adds the error into the request's error list
> 
> HTRequest_addSystemError(request,  ERR_FATAL, socerrno, NO, "NETWRITE");
> 
> which generates:
> 
> Error Add... number:  44        Severity: 1     Parameter: `NETWRITE: =
> Broken pipe'      Where: `NETWRITE'
> 
> Why didn't SetSignal() do what it supposed to do?

On client side, the SetSignal() is only required on Solaris and some other 
SVR4-like systems which has a broken TCP stack. The problem occurs as soon as 
you try to use non-blocking sockets. If you have a non-blocking socket and try 
to connect to a valid host but on a non-supported port number, for example 
7777 where nothing is waiting, then you get SIG_PIPE back and your application 
dies. On many BSD-like TCP stacks you get "Invalid argument" which is also an 
error. The right response is of course "Connection refused" which both manage 
to handle if you use blocking sockets.

In the case above, however, the situation's different as you're the server and 
the client has pre-maturely closed the connection. In this case you will get a 
"broken pipe" in which case you will have to handle the signel. As you can 
see, this is already done by SetSignal() as the server doesn't die but just 
registers the broken pipe and continues.


-- 

Henrik Frystyk Nielsen, <frystyk@w3.org>
World-Wide Web Consortium, MIT/LCS NE43-356
545 Technology Square, Cambridge MA 02139, USA

Received on Monday, 26 February 1996 10:43:14 UTC