Talk:IPC via named pipe

From Rosetta Code
Revision as of 11:44, 30 September 2011 by rosettacode>Ledrug (tricky indeed)

This is tricky! The “in” reader side is normal asynchronous IO (the pipe becomes readable when there's data available) but the “out” writer side is very awkward because you can't open the writer side of a FIFO if there is no reader there. You've either got to use a blocking open() — which might or might not work with a threaded solution — or deal with the failure to open() it in non-blocking mode by polling regularly. Tricky stuff! –Donal Fellows 09:38, 30 September 2011 (UTC)

Actually I don't think O_WRONLY|O_NONBLOCK on a fifo will ever succeed on a POSIX system. On Linux, you can O_RDWR open a fifo, and it will not block (because the program itself is the reader then), but then you can't select it for write readiness because it always returns immediately with success. Luckily here one thread blocking on open will not hold up the entire process, so it's relatively easy to deal with. --Ledrug 11:44, 30 September 2011 (UTC)