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

?

Stefan

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to