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 [EMAIL PROTECTED]
with "unsubscribe freebsd-net" in the body of the message

Reply via email to