[Haskell-cafe] Network: buffering troubles

Yves Parès limestrael at gmail.com
Wed Apr 7 11:44:44 EDT 2010


News! (Sorry for the spam, but this problem turns to be a headache)

The problem actually comes from ByteStrings (either lazy or strict).
I reduced my server code to this:

import Network
import System.IO
import qualified Data.ByteString(.Lazy) as L

main = do
  (hdl,_,_) <- listenOn (PortNumber 7777) >>= accept
  hSetBuffering hdl NoBuffering
  inp <- L.hGetContents hdl
  putStrLn . show $ L.take 8 inp

My client hasn't changed, and sends properly the data. So the server
shouldn't hold. Well, even when trying to rawly print the first 8 bytes of
the stream, it does.

But when I use normal Strings, it doesn't hold:

import Network
import System.IO

main = do
  (hdl,_,_) <- listenOn (PortNumber 7777) >>= accept
  hSetBuffering hdl NoBuffering
  inp <- hGetContents hdl
  putStrLn . show $ take 8 inp

I think this behavior is normal for strict ByteStrings, but not for lazy
ones...

-----
Yves Parès

Live long and prosper
-- 
View this message in context: http://old.nabble.com/Network%3A-buffering-troubles-tp28162932p28166941.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list