From: Christoph B. <ic...@ch...> - 2010-01-03 16:22:59
|
"Brandon S. Allbery KF8NH" <al...@ec...> 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?) Unfortunatly I have another problem. Maybe it's more a glib, poll() or unix problem, but maybe someone has a hint for me. I'm waiting for a named pipe. A shell skript can write to the pipe to control my program. The shell skript simply does an echo cmd > /tmp/namedpipe main = ... inputAdd fd [IOIn] priorityDefault (controlMe fd app) controlMe fd app = do (s, l) <- fdRead fd 1024 `catch` \ _ -> return ("", 0) when (l > 0) $ writeIORef (skipVar app) True return (s /= "quit") It works - but after the first command my program uses 100% CPU. strace shows, that the epoll()-call returns with revents=POLLHUP. poll([{fd=6, events=POLLIN}, {fd=9, events=POLLIN}], 2, 88) = 1 ([{fd=9, revents=POLLHUP}]) Is there a solution to this problem? My only idea is to close/reopen my named pipe. Thanks |