[Haskell-beginners] RWH Ch. 27 TCP Server Example
aditya.siram at gmail.com
Mon Apr 13 19:05:34 EDT 2009
I am trying to understand the TCP Syslog Server example  from RWH.
Specifically my question is on this piece of code:
-- | Process incoming messages
procMessages :: MVar () -> Socket -> SockAddr -> IO ()
procMessages lock connsock clientaddr =
do connhdl <- socketToHandle connsock ReadMode
hSetBuffering connhdl LineBuffering
messages <- hGetContents connhdl
mapM_ (handle lock clientaddr) (lines messages)
handle lock clientaddr
"syslogtcpserver.hs: client disconnected"
How does control stay on "mapM_ (handle lock clientaddr) (lines
messages)" ? It would seem that the server would handle one message
and immediately close the handle and end - but it doesn't. I'm
guessing this has something to do with laziness, but I don't see how
to apply it.
More information about the Beginners