# HG changeset patch # User unc0rr # Date 1299958921 -10800 # Node ID 72d8fb26223d3f2f79c76229e03561641c1fcf68 # Parent a3a09b1076527f34f7e610dd56e77155a3658bb8 - Don't pretend client sent some message from sending thread (fixes crash when client is already deleted by recieveng thread) - Better exception handling in recieving thread diff -r a3a09b107652 -r 72d8fb26223d gameServer/ClientIO.hs --- a/gameServer/ClientIO.hs Fri Mar 11 22:22:28 2011 +0300 +++ b/gameServer/ClientIO.hs Sat Mar 12 22:42:01 2011 +0300 @@ -46,13 +46,9 @@ sendPacket packet = writeChan chan $ ClientMessage (ci, packet) clientRecvLoop :: Socket -> Chan CoreMessage -> ClientIndex -> IO () -clientRecvLoop s chan ci = - do - msg <- (listenLoop s chan ci >> return "Connection closed") `catch` (return . B.pack . show) - clientOff msg +clientRecvLoop s chan ci = Exception.block $ + ((Exception.unblock $ listenLoop s chan ci >> return "Connection closed") `catch` (return . B.pack . show) >>= clientOff) `Exception.finally` - do - clientOff "Connection closed ()" remove where clientOff msg = writeChan chan $ ClientMessage (ci, ["QUIT", msg]) @@ -64,19 +60,17 @@ clientSendLoop s tId cChan chan ci = do answer <- readChan chan Exception.handle - (\(e :: Exception.IOException) -> unless (isQuit answer) $ sendQuit e) $ + (\(e :: Exception.IOException) -> unless (isQuit answer) . killReciever $ show e) $ sendAll s $ B.unlines answer `B.append` B.singleton '\n' if isQuit answer then do Exception.handle (\(_ :: Exception.IOException) -> putStrLn "error on sClose") $ sClose s - Exception.throwTo tId ShutdownThreadException + killReciever "Connection closed" else clientSendLoop s tId cChan chan ci where - sendQuit e = do - print e - writeChan cChan $ ClientMessage (ci, ["QUIT", B.pack $ show e]) + killReciever = Exception.throwTo tId . ShutdownThreadException isQuit ("BYE":_) = True isQuit _ = False diff -r a3a09b107652 -r 72d8fb26223d gameServer/CoreTypes.hs --- a/gameServer/CoreTypes.hs Fri Mar 11 22:22:28 2011 +0300 +++ b/gameServer/CoreTypes.hs Sat Mar 12 22:42:01 2011 +0300 @@ -206,7 +206,9 @@ instance Exception ShutdownException -data ShutdownThreadException = ShutdownThreadException - deriving (Show, Typeable) +data ShutdownThreadException = ShutdownThreadException String + deriving Typeable +instance Show ShutdownThreadException where + show (ShutdownThreadException s) = "kill: " ++ s instance Exception ShutdownThreadException