Using select on FIFO's

Geoff Clare gwc at root.co.uk
Tue Jun 4 22:50:10 AEST 1991


les at chinet.chi.il.us (Leslie Mikesell) writes:

> I've always just opened the FIFO with O_RDWR
>on the reader side which (a) doesn't block during the open, and (b)

Although this works on most if not all current UNIX systems, it's not
required by POSIX, so applications using this method may not work
on some future systems.  For maximum portability to current and
future systems, I recommend using the following method to open both
sides of a FIFO to do blocking I/O:

	fd_rd = open("FIFO", O_RDONLY|O_NONBLOCK);
	fd_wr = open("FIFO", O_WRONLY);
	flags = fcntl(fd_rd, F_GETFL);
	fcntl(fd_rd, F_SETFL, flags & ~O_NONBLOCK);

with something like the following tucked away in a header:

#ifndef _POSIX_SOURCE
#define O_NONBLOCK O_NDELAY
#endif
-- 
Geoff Clare <gwc at root.co.uk>  (Dumb American mailers: ...!uunet!root.co.uk!gwc)
UniSoft Limited, London, England.   Tel: +44 71 729 3773   Fax: +44 71 729 3273



More information about the Comp.unix.programmer mailing list