41 |
41 |
42 sendPacket packet = writeChan chan $ ClientMessage (ci, packet) |
42 sendPacket packet = writeChan chan $ ClientMessage (ci, packet) |
43 |
43 |
44 clientRecvLoop :: Socket -> Chan CoreMessage -> Chan [B.ByteString] -> ClientIndex -> (forall a. IO a -> IO a) -> IO () |
44 clientRecvLoop :: Socket -> Chan CoreMessage -> Chan [B.ByteString] -> ClientIndex -> (forall a. IO a -> IO a) -> IO () |
45 clientRecvLoop s chan clChan ci restore = |
45 clientRecvLoop s chan clChan ci restore = |
46 myThreadId >>= |
46 (myThreadId >>= |
47 \t -> (restore $ forkIO (clientSendLoop s t clChan ci) >> |
47 \t -> (restore $ forkIO (clientSendLoop s t clChan ci) >> |
48 listenLoop s chan ci >> return "Connection closed") |
48 listenLoop s chan ci >> return "Connection closed") |
|
49 `Exception.catch` (\(e :: ShutdownThreadException) -> return . B.pack . show $ e) |
49 `Exception.catch` (\(e :: Exception.IOException) -> return . B.pack . show $ e) |
50 `Exception.catch` (\(e :: Exception.IOException) -> return . B.pack . show $ e) |
50 `Exception.catch` (\(e :: ShutdownThreadException) -> return . B.pack . show $ e) |
|
51 `Exception.catch` (\(e :: Exception.SomeException) -> return . B.pack . show $ e) |
51 `Exception.catch` (\(e :: Exception.SomeException) -> return . B.pack . show $ e) |
52 >>= clientOff >> remove |
52 >>= clientOff) `Exception.finally` remove |
53 where |
53 where |
54 clientOff msg = writeChan chan $ ClientMessage (ci, ["QUIT", msg]) |
54 clientOff msg = writeChan chan $ ClientMessage (ci, ["QUIT", msg]) |
55 remove = writeChan chan $ Remove ci |
55 remove = do |
|
56 clientOff "Client is in some weird state" |
|
57 writeChan chan $ Remove ci |
56 |
58 |
57 |
59 |
58 |
60 |
59 clientSendLoop :: Socket -> ThreadId -> Chan [B.ByteString] -> ClientIndex -> IO () |
61 clientSendLoop :: Socket -> ThreadId -> Chan [B.ByteString] -> ClientIndex -> IO () |
60 clientSendLoop s tId chan ci = do |
62 clientSendLoop s tId chan ci = do |