On Tuesday 28 April 2015 07:33:39 Light, John J wrote:
> Thank you, Thiago, for pointing that out.
> 
> I will add that many robust, well-written C/C++ programs don't set
> O_NONBLOCK yet never block, through careful use of select.

That is true, though I still advise using O_NONBLOCK.

The one case that you may want O_NONBLOCK despite careful use of select is an 
API "I've been told to send this packet without blocking, can I do it now?", 
like the use of send/sendto/sendmsg.

You have to query whether the socket can take the packet now. One way is to do 
select/poll for writing, with a zero timeout, and see if you get the 
permission to write, then write. But that's two system calls. With O_NONBLOCK, 
you can simply write and handle the EWOULDBLOCK error if it couldn't send -- 
one system call.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

Reply via email to