From owner-freebsd-hackers Fri Aug 23 14:08:56 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id OAA13141 for hackers-outgoing; Fri, 23 Aug 1996 14:08:56 -0700 (PDT) Received: from peedub.gj.org (ns045.munich.netsurf.de [194.64.166.45]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id OAA13114 for ; Fri, 23 Aug 1996 14:08:41 -0700 (PDT) Received: from peedub.gj.org (localhost [127.0.0.1]) by peedub.gj.org (8.7.5/8.6.9) with ESMTP id XAA00363; Fri, 23 Aug 1996 23:07:09 GMT Message-Id: <199608232307.XAA00363@peedub.gj.org> X-Mailer: exmh version 1.6.7 5/3/96 To: Nate Williams Cc: freebsd-hackers@freefall.FreeBSD.org Subject: Re: Non-blocking I/O on sockets and closed sockets? Reply-To: Gary Jennejohn In-reply-to: Your message of "Fri, 23 Aug 1996 12:06:14 CST." <199608231806.MAA07694@rocky.mt.sri.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 23 Aug 1996 23:07:09 +0000 From: Gary Jennejohn Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk 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