[MPlayer-dev-eng] Re: kernel: to do_select(pipe) or not to do

Linus Torvalds torvalds at osdl.org
Mon Nov 22 05:55:40 CET 2004



On Mon, 22 Nov 2004, Ivan Kalvachev wrote:
> 
> BTW there is another way to set nonblocking pipe, this time using
> O_NDELAY, I could find any particular documentation stating the
> difference between both methods (probably that on O_NDELAY write()
> will return 0 instead of -1 error). I was wondering how portables are
> these flags.

O_NONBLOCK is the modern way of doing things, and everybody supports it 
these days. The error code for a failure is EAGAIN. This is what you 
basically should use if you plan to do anything with a system from the 
current century.

If you have to support old systems (from the 80's), you may also hit
O_NDELAY (basically same thing) and additionally check for the EWOULDBLOCK
error code. Under SYSV I think it would return 0 (which is normally EOF), 
to make things _really_ confusing.

Basically, don't use anything but O_NONBLOCK, and if you want to be 
defensive, you can do something like

	#ifndef O_NONBLOCK
	#define O_NONBLOCK O_NDELAY
	#endif

	.. use O_NONBLOCK ..

and also make sure that anything that checks EAGAIN also checks for 
EWOULDBLOCK.

		Linus




More information about the MPlayer-dev-eng mailing list