[Haskell-cafe] Re: Network parsing and parsec

John Goerzen jgoerzen at complete.org
Tue Sep 20 10:50:02 EDT 2005


On Tue, Sep 20, 2005 at 03:17:11PM +0100, Keean Schupke wrote:
>    -- For a line buffer, we just get the first chunk of data to arrive,
>    -- and don't wait for the whole buffer to be full (but we *do* wait
>    -- until some data arrives).  This isn't really line buffering, but it
>    -- appears to be what GHC has done for a long time, and I suspect it
>    -- is more useful than line buffering in most cases.
> 
> So for a disc buffer I would expect 1 complete buffer to be returned 
> most of the time, for
> a network read, I guess one packet (MTUs) worth should be expected...

Hmm, and checking my code, it appears that I did use line buffering for
my FTP client.  However, I am *sure* that I did run into some deadlock
issues relating to buffering at some point.  Sigh.

So this is good and should work nicely with protocols such as SMTP and
FTP.

The other thing is that the Handle is not the most convenient way to
work with a socket.  As I mentioned, two Handles for a single socket
must be opened, which is inconvenient and annoying, not to mention leads
to some confusing semantics.  You also have to be *very* careful to
never consume more than you need.

On the flip side, Parsec is really nice.  I wonder how easy it would be
to make it parse [Word8] instead of String?  Or even a FastPackedString?
(And how easy it would be to get that instead of a String from
hGetContents)?

-- John


More information about the Haskell-Cafe mailing list