vincenthz/hs-connection — pull request #2 by joeyadams (2012-12-17 02:38:31+00:00)
Title: Add connectionGetLine or similar

Per your [suggestion on Reddit][1], I plan to use the connection package for smtp-mail. The implementation receives responses a line at a time. It'd be more convenient and efficient if I could take advantage of the buffering that the connection package already does, rather than do my own buffering, to take only one line and save the leftovers.

To this end, I propose adding something like this:

connectionGetChunk' :: Connection -> (ByteString -> (a, ByteString)) -> IO a

The caller returns the part of the chunk it didn't use, so it will be the next data read. If there wasn't enough data, the caller has to call `connectionGetChunk'` again.

Also, while we're at it: why do we do this?

hWaitForInput h (-1) >> B.hGetNonBlocking h (16 * 1024)

`hWaitForInput` can't be interrupted with an async exception under the threaded RTS (meaning [System.Timeout][2] won't work). Under the hood, it uses a plain `select()` call, rather than taking advantage of the system's scalable polling facility (where available).

[1]: http://www.reddit.com/r/haskell/comments/14vwvs/smtpemail_package_makes_sending_email_a_oneliner/c7h1br4
[2]: http://hackage.haskell.org/packages/archive/base/latest/doc/html/System-Timeout.html