On Jan 3, 2010, at 11:18 , Christoph Bauer wrote:
> "Brandon S. Allbery KF8NH" <allbery@...> writes:
>> On Jan 2, 2010, at 07:33 , Christoph Bauer wrote:
>>> how do I use inputAdd from System.Glib.Mainloop? FD is an Int.
>>> (This isn't visible in the documentation.)
>>> Fortunatly I need this for Linux, so I could create an ffi-call
>>> to open(), but I guess I missed something.
>> After studying the internals a bit, I ended up with:
>> fdFD :: Fd -> Int
>> fdFD (Fd fd) = fromEnum fd
>> (Fd being System.Posix.IO.Fd)
> Thanks. I the meantime I found a similar approach. (But instead of
> fromEnum is replaced by fromIntegral. Is there a difference?)
Not in this context. I think I developed that habit when there were
fewer Integral instances floating around.
> I'm waiting for a named pipe. A shell skript can write to the
> It works - but after the first command my program uses 100% CPU.
Yep. Unix named pipes/FIFOs are somewhat annoying that way. The
usual way to use them is to open them read-write in the reader (thus
avoiding the EOF when the last writer closes it; named pipes emulate
pipes, not sockets), but then you need some way to recognize that a
writer is done. In your case, that's reading a newline.
If you have a case where there isn't an obvious end-of-data indication
from a writer and detecting end-of-data matters, you probably want an
AF_UNIX/AF_LOCAL socket instead of a FIFO.
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@...
system administrator [openafs,heimdal,too many hats] allbery@...
electrical and computer engineering, carnegie mellon university KF8NH