Date: Wed, 20 Nov 2002 11:06:32 -0800 From: jayanth <jayanth@yahoo-inc.com> To: freebsd-net@freebsd.org Subject: file descriptor flags and socket flags out of sync ? Message-ID: <20021120110632.A62938@yahoo-inc.com>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021120110632.A62938>