Date: Fri, 23 Aug 1996 23:07:09 +0000 From: Gary Jennejohn <garyj@munich.netsurf.de> To: Nate Williams <nate@mt.sri.com> Cc: freebsd-hackers@freefall.FreeBSD.org Subject: Re: Non-blocking I/O on sockets and closed sockets? Message-ID: <199608232307.XAA00363@peedub.gj.org> In-Reply-To: Your message of "Fri, 23 Aug 1996 12:06:14 CST." <199608231806.MAA07694@rocky.mt.sri.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Nate Williams writes: >Will read() return a negative error code on a socket if the socket is >closed/dead? I've looked in Steven's and in the obvious manpages, but >nothing jumps out at me. > if select says the socket is ready for reading and you read 0 bytes then that indicates that the peer has closed his end. I've used that test many times with ASYNC sockets and it hasn't failed me yet. Another pssibility is to have a SIGPIPE handler; a read from a closed socket should result in a SIGPIPE. In my experience, that isn't nearly as reliable as the "read returns 0" test. >Here's the code snippet which should explain what goes on. >(error checking removed) > snippet deleted --- Gary Jennejohn Home - Gary.Jennejohn@munich.netsurf.de Work - gjennejohn@frt.dec.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199608232307.XAA00363>