home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!rutgers!noao!rstevens
- From: rstevens@noao.edu (W. Richard Stevens)
- Newsgroups: comp.unix.programmer
- Subject: Re: SIGPIPE Delivery on socket close
- Keywords: SIGPIPE signal TCP socket
- Message-ID: <1992Aug23.121615.626@noao.edu>
- Date: 23 Aug 92 12:16:15 GMT
- References: <1992Aug19.001455.222056@zeus.calpoly.edu> <BtCqCG.DMw@usenet.ucs.indiana.edu>
- Sender: news@noao.edu
- Organization: National Optical Astronomy Observatories, Tucson, AZ, USA
- Lines: 27
- Nntp-Posting-Host: gemini.tuc.noao.edu
-
- In article <BtCqCG.DMw@usenet.ucs.indiana.edu> jackson@daimler.ucs.indiana.edu (Jeff Jackson) writes:
- >
- >In the client, after the server has timed out and closed the socket,
- >I expected to get a SIGPIPE signal the next time I tried a write to
- >the socket. What I am finding is that the first write that I do to
- >the socket completes normally - returning the number of bytes that
- >were written. Sometimes even the second write will appear to succeed.
- >Usually however the second or third write causes the SIGPIPE signal, which
- >is trapped and closes the socket.
- >
- >What needs to be done to get the SIGPIPE signal the FIRST time I write
- >to the socket?
-
- You are encoutnering TCP's half-close. The server's closing of its
- socket causes its TCP to send a FIN. That only closes the data flow
- from the server to the client. As far as the client's TCP is concerned,
- it can still *send* data to the server. Your first write will be OK,
- but the server's TCP will respond with a RST (since the server really
- terminated and didn't do a real half-close), which causes the second
- client write to get SIGPIPE. You can't change this--it's a TCP feature.
-
- What you need to do is call select from the client--then the socket
- will be marked readable in the client when the server terminates and
- your read will receive an EOF. Use that to not write anything else
- to the server.
-
- Rich Stevens (rstevens@noao.edu)
-