[Haskell-cafe] Re: Network parsing and parsec

Peter Simons simons at cryp.to
Thu Sep 15 12:37:19 EDT 2005

John Goerzen writes:

 > With networking, you must be careful not to attempt to
 > read more data than the server hands back, or else you'll
 > block. [...] With a protocol such as IMAP, there is no
 > way to know until a server response is being parsed, how
 > many lines (or bytes) of data to read.

The approach I recommend is to run a scanner (tokenizer)
before the actual parser.

IMAP, like most other RFC protocols, is line-based; so you
can use a very simple scanner to read a CRLF-terminated line
efficiently (using non-blocking I/O, for example), which you
can then feed into the parser just fine because you know
that it has to contain a complete request (response) that
you can handle.


More information about the Haskell-Cafe mailing list