On Sunday 07 December 2008 15:02, prhlava wrote: > Hello everyone, > > I am trying to read (repeatedly) from named pipe (fifo) on linux (the > program will be a long running process...). > > The following does not work, but if I remove the (while true , it > does...
Characterize "does not work," if you would. > (def pipe-name "/tmp/my-pipe") > > (def buffer-size (* 1 1024)) > > (while true > (with-open [pipe (new java.io.FileInputStream pipe-name)] > (print pipe) > (let [buffer (make-array Byte/TYPE buffer-size)] > (. pipe read buffer) > (map print buffer)))) > > I am lost here... For one thing, you will need to loop on reading from the pipe. Reads will block while there a writer holds the pipe open but no bytes are in the pipe. Once there are zero writers (and no buffered / unread data remains in the pipe), readers will get an end-of-file indication (zero bytes returned) on every read attempt. > Vlad > > PS: The new java.io.FileInputStream call blocks until the pipe is > closed at the "other" end... That is how pipes work. The kernel cannot signal and end-of-file while a writer has the pipe open, since that writer may at any time decide to writer more data. The attempt to open a named pipe for reading will likewise block until there's a writer. And vice versa: an attempt to open a named pipe for writing will block until there is a reader. Similarly, write attempts will block when the writer overruns the reader and operating system kernel's internal pipe high-water mark is reached. And naturally, read attempts block when there's no available data. There are non-blocking modes that the OS's native descriptor can be placed in. I don't know if there's any support for this in the Java IO libraries. All these things happen in the operating system. Randall Schulz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---