From owner-freebsd-net Wed Nov 20 11: 6:49 2002 Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D72A937B401 for ; Wed, 20 Nov 2002 11:06:47 -0800 (PST) Received: from mrout3.yahoo.com (mrout3.yahoo.com [216.145.54.173]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8C8FE43E8A for ; Wed, 20 Nov 2002 11:06:47 -0800 (PST) (envelope-from jayanth@yahoo-inc.com) Received: from milk.yahoo.com (milk.yahoo.com [216.145.52.137]) by mrout3.yahoo.com (8.11.6/8.11.6/y.out) with ESMTP id gAKJ6W918954 for ; Wed, 20 Nov 2002 11:06:32 -0800 (PST) Received: (from root@localhost) by milk.yahoo.com (8.11.0/8.11.0) id gAKJ6Wt63573 for freebsd-net@freebsd.org; Wed, 20 Nov 2002 11:06:32 -0800 (PST) (envelope-from jayanth) Date: Wed, 20 Nov 2002 11:06:32 -0800 From: jayanth To: freebsd-net@freebsd.org Subject: file descriptor flags and socket flags out of sync ? Message-ID: <20021120110632.A62938@yahoo-inc.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2i Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org Some developers here have encountered a scenario where the file descriptor flags and the socket flags seem to be out of sync. if an application does: listen(listenfd) while (!done) { select() <-------------------- new connection arrives before fcntl() fcntl(listenfd,O_NONBLOCK) newfd = accept(listenfd,...) fnctl(listenfd,0) /* make socket blocking */ if (newfd & O_NONBLOCK) /* fd is O_NONBLOCK, but socket is blocking */ } At this point socket is blocking because the state of the new socket = state of the listen socket only during the connection setup phase, not during the accept phase. However, the filedescriptor flags are copied during the accept phase. So at this point the filedescriptor flags are nonblocking but the socket is actually blocking. Agreed, that the solution is to have the application set NONBLOCK before the listen() call, but it seems incorrect to have the newfd's flags and socket state be out of sync. Copying the state of the socket during the accept might lead to a slightly different behaviour, but will solve this particular problem. thanks, jayanth To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message