gameServer/ClientIO.hs
changeset 5989 23407ecb1826
parent 5077 7915668502a6
child 7252 74a92f39703b
equal deleted inserted replaced
5988:d08565e2a7d7 5989:23407ecb1826
    56 
    56 
    57 
    57 
    58 clientSendLoop :: Socket -> ThreadId -> Chan [B.ByteString] -> ClientIndex -> IO ()
    58 clientSendLoop :: Socket -> ThreadId -> Chan [B.ByteString] -> ClientIndex -> IO ()
    59 clientSendLoop s tId chan ci = do
    59 clientSendLoop s tId chan ci = do
    60     answer <- readChan chan
    60     answer <- readChan chan
       
    61 
       
    62     when (isQuit answer) $
       
    63         killReciever . B.unpack $ quitMessage answer
       
    64 
    61     Exception.handle
    65     Exception.handle
    62         (\(e :: Exception.IOException) -> unless (isQuit answer) . killReciever $ show e) $
    66         (\(e :: Exception.IOException) -> unless (isQuit answer) . killReciever $ show e) $
    63             sendAll s $ B.unlines answer `B.snoc` '\n'
    67             sendAll s $ B.unlines answer `B.snoc` '\n'
    64 
    68 
    65     if isQuit answer then
    69     if isQuit answer then
    66         do
    70         do
    67         Exception.handle (\(_ :: Exception.IOException) -> putStrLn "error on sClose") $ sClose s
    71         Exception.handle (\(_ :: Exception.IOException) -> putStrLn "error on sClose") $ sClose s
    68         killReciever . B.unpack $ quitMessage answer
       
    69         else
    72         else
    70         clientSendLoop s tId chan ci
    73         clientSendLoop s tId chan ci
    71 
    74 
    72     where
    75     where
    73         killReciever = Exception.throwTo tId . ShutdownThreadException
    76         killReciever = Exception.throwTo tId . ShutdownThreadException