[darcs-devel] http pipelining

Stefan O'Rear stefanor at cox.net
Mon Dec 17 22:05:32 UTC 2007

On Mon, Dec 17, 2007 at 12:23:33PM -0500, David Roundy wrote:
> In either case, the sanest pure interface that I can imagine would involve
> *darcs* seeing itself as doing parallel downloads, while the HTTP library
> (whichever is used) queues these parallel downloads into an HTTP pipeline.
> Otherwise we'd be reduced to moving things into the IO monad that don't
> belong there, which would be rather ugly indeed.  Or alternatively, we
> could restrict pipeline to special cases (e.g. darcs get), and use the
> existing mechanism the rest of the time.  But it'd be nicer to have a nice
> interface that optimizes all network access.

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
  return $ C $ unsafePerformIO $ getData c


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.osuosl.org/pipermail/darcs-devel/attachments/20071217/a21b9200/attachment.pgp 

More information about the darcs-devel mailing list