Reputation: 355
I have a socket server that waits for input from a connection via hGetLine. This works great when messages are sent with a trailing newline character. What I would like is to grab from the buffer whenever a newline or null character is received--Setting the handle's buffer mode to NoBuffering doesn't effect this, hGetLine still hangs until a \n shows up. Is there a simple way to accommodate both newline and null terminators?
Upvotes: 4
Views: 566
Reputation: 3096
You can probably spin your own solution using either hGetChar or hGetBufSome. I think you'd get better through-put with hGetBufSome. However, it looks like hGetBufSome is not implemented for Data.Text so you are probably stuck in System.IO.
http://hackage.haskell.org/packages/archive/base/latest/doc/html/System-IO.html#v:hGetBufSome
Good luck
Upvotes: 1