开发者

Haskell hGetLine and null character

开发者 https://www.devze.com 2023-02-14 00:21 出处:网络
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 ch开发者_如何学运维aracter. What I would like is to grab fro

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 ch开发者_如何学运维aracter. 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消