From owner-freebsd-questions Mon Mar 22 12:27: 5 1999 Delivered-To: freebsd-questions@freebsd.org Received: from sumatra.americantv.com (sumatra.americantv.com [207.170.17.37]) by hub.freebsd.org (Postfix) with ESMTP id C0A9F1521E for ; Mon, 22 Mar 1999 12:27:02 -0800 (PST) (envelope-from jlemon@americantv.com) Received: from right.PCS (right.PCS [148.105.10.31]) by sumatra.americantv.com (8.8.5/8.8.5) with ESMTP id OAA08312; Mon, 22 Mar 1999 14:26:36 -0600 (CST) Received: from free.pcs (free.PCS [148.105.10.51]) by right.PCS (8.6.13/8.6.4) with ESMTP id OAA10478; Mon, 22 Mar 1999 14:26:05 -0600 Received: (from jlemon@localhost) by free.pcs (8.8.6/8.8.5) id OAA09449; Mon, 22 Mar 1999 14:26:04 -0600 (CST) Date: Mon, 22 Mar 1999 14:26:04 -0600 (CST) From: Jonathan Lemon Message-Id: <199903222026.OAA09449@free.pcs> To: rfg@monkeys.com, freebsd-questions@freebsd.org Subject: Re: Is select(2) a liar? X-Newsgroups: local.mail.freebsd-questions In-Reply-To: Organization: Architecture and Operating System Fanatics Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In article you write: >Given a stream (TCP) socket which you have started an asynchronous (non- >blocking) connect for, if a call to select(2) tells you that the socket is >now writable, what conditions (other than an outright rejection of the >connection attempt by the peer you were connecting to) might cause a >subsequent call to getpeername() to return a -1 error result? In other >words, what are the precise conditions under which select() will in fact >``lie'' and say that the socket is writable when in fact it is NEITHER >in a connected state nor in an error state? How about if it's in a closed state? A closed state isn't an error state; an error is flagged only after attempting to write to a closed socket. Here's the definition of sowritable(): (from sys/sys/socketvar.h) #define sowriteable(so) \ ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \ (((so)->so_state&SS_ISCONNECTED) || \ ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \ ((so)->so_state & SS_CANTSENDMORE) || \ (so)->so_error) CANTSENDMORE is set if the socket is the process of disconnecting (or has already disconnected). If you're writing new code, you may want to use poll(), it's cleaner than select() in handling these kind of things (IMHO). -- Jonathan To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message