gameServer/ClientIO.hs
changeset 5077 7915668502a6
parent 5059 68a5415ca8ea
child 5989 23407ecb1826
--- a/gameServer/ClientIO.hs	Tue Mar 29 20:10:56 2011 -0400
+++ b/gameServer/ClientIO.hs	Sat Apr 02 20:01:20 2011 +0400
@@ -1,4 +1,4 @@
-{-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-}
+{-# LANGUAGE ScopedTypeVariables, OverloadedStrings, Rank2Types #-}
 module ClientIO where
 
 import qualified Control.Exception as Exception
@@ -30,7 +30,7 @@
             return (B.splitWith (== '\n') packet : packets)
 
 listenLoop :: Socket -> Chan CoreMessage -> ClientIndex -> IO ()
-listenLoop sock chan ci = Exception.unblock $ recieveWithBufferLoop B.empty
+listenLoop sock chan ci = recieveWithBufferLoop B.empty
     where
         recieveWithBufferLoop recvBuf = do
             recvBS <- recv sock 4096
@@ -41,11 +41,11 @@
 
         sendPacket packet = writeChan chan $ ClientMessage (ci, packet)
 
-clientRecvLoop :: Socket -> Chan CoreMessage -> Chan [B.ByteString] -> ClientIndex -> IO ()
-clientRecvLoop s chan clChan ci =
+clientRecvLoop :: Socket -> Chan CoreMessage -> Chan [B.ByteString] -> ClientIndex -> (forall a. IO a -> IO a) -> IO ()
+clientRecvLoop s chan clChan ci restore =
     myThreadId >>=
-    \t -> forkIO (clientSendLoop s t clChan ci) >>
-    (listenLoop s chan ci >> return "Connection closed")
+    \t -> (restore $ forkIO (clientSendLoop s t clChan ci) >>
+        listenLoop s chan ci >> return "Connection closed")
         `Exception.catch` (\(e :: Exception.IOException) -> return . B.pack . show $ e)
         `Exception.catch` (\(e :: ShutdownThreadException) -> return . B.pack . show $ e)
         >>= clientOff >> remove