[darcs-devel] http pipelining
Simon Marlow
simonmarhaskell at gmail.com
Tue Dec 18 09:51:02 UTC 2007
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
More information about the darcs-devel
mailing list