Stefan O'Rear wrote:
How about something like:
data Cookie = C { getData :: L.ByteString }
fetchURL :: URI -> Cookie -- sends request when forced, reads
responce when deeply forced
{- sample implementation, ignores the existance of multiple servers and
the Connection: close header -}
sock = unsafePerformIO ...
queue fun = newChan >>= \q -> forkIO (forever (readChan q >>= fun)) >>
return q
writer = unsafePeformIO $ queue $ \ req -> writeRequest sock req
reader = unsafePeformIO $ queue $ \ var ->
readRequest sock (\ bit -> writeChan var (Just bit)) >>
writeChan var Nothing
fetchURL url = unsafePerformIO $ do
c <- newChan
writeChan writer (fetch url)
writeChan reader c
A single queue seems nicer, given that you would otherwise need some
locking to prevent races between multiple threads (I know this doesn't
apply to darcs, but still).
return $ C $ unsafePerformIO $ getData c
Cheers,
Simon
_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc