So I have some code like
(let ((file (open cur-fifo :if-does-not-exist :create)))
(format t "~A~%" (read-line file nil))
(close file))
Which as far as I can tell works fine, except that this will block indefinitely if no data was written to cur-fifo. I want the read to time out and return NIL if no data could be read in ~0.1 sec or so.
Running on SBCL 1.1.18, on 64-bit Gentoo Linux
FIFO model
When you
open
afifo
special device (for reading), the system call blocks unless eitherO_ASYNC
toopen(2)
- which you might not be able to do in your implementation unless you use a low level packagesb-posix
When you successfully opened the fifo, your
read(2)
call will block until your counterparty (that opened the fifo for writing, which could be the same lisp process) writes something there.Common Lisp
What you are looking for is
listen
(see alsowith-open-file
):Debugging
Please note that special device handling is not necessarily equally well supported by all CL vendors. If the above does not work, please do some experiments with the REPL: open the
fifo
, see whatlisten
returns, write something there, see whatlisten
reports now, &c.If
listen
still returnsnil
even though you already wrote something into the pipe, this might mean that your CL does not recognize the file as a special device. You might have to pass some implementation-specific arguments toopen
, e.g.,:buffering nil
or something (try(describe 'open)
).