Posix library ,Concurrent Haskell and Haskell IO sub-system
Rafael Martinez Torres
Thu, 10 Jul 2003 10:53:13 +0200 (CEST)
I use the Posix library since I have to communicate via a pipe with
another UNIX process.
Therefore I have to use
fdRead :: Fd -> ByteCount -> IO (String,ByteCount)
The problem is that "fdRead" , as a non Haskell-IO sub-system function,
to block the entire STG system. The rest of the other threads are blocked
BTW, "String" stands for non-printable bytes I can be sent for a system,
'\0' included ?
1 .- Polling. Sleep and ask.
You have to use the setFdOption fd NonblockingRead True
fdReadNonBlockingSTG :: Fd -> Int -> IO (String,ByteCount)
fdReadNonBlockingSTG mypipe nobytes =
(string,nobytesread) -> fdRead mypipe nobytes
if (nobytesread == -1)
fdReadNonBlockingSTG mypipe nobytes
else return (string,nobytesread)
myprogram :: IO ()
setFdOption mypipe NonBlockingRead True
(a,b) <- fdReadNonBlockingSTG mypipe 2
Problem: As you see, "1000" es an arbitrary constant maybe too short, may
be too long and this affects throughput.
2.- Desired approach
Ideally I would like to use the
threadWaitRead :: Int -> IO()
from Concurrent Haskell
-- setFdOption mypipe NonBlockingRead True -- should be called?
threadWaitRead (fdToInt mypipe)
(string,nobytes) <- fdRead mypipe 2
A ) is the GHC-RTS ready to dispatch the signal send by the O.S on a
"Posix Fd" and make "threadWaitRead" to run as expected ?
The Posix library doc warns:
intToFd :: Int -> Fd -- use with care
fdToInt :: Fd -> Int -- ditto
B) Other approaches, like Handles... Is it possible to convert a Fd into a
Handle or bypassing it to the RTS another way ?...