55 where |
55 where |
56 clientOff msg = mapM_ (writeChan chan) [ClientMessage (ci, ["QUIT", msg]), Remove ci] |
56 clientOff msg = mapM_ (writeChan chan) [ClientMessage (ci, ["QUIT", msg]), Remove ci] |
57 |
57 |
58 |
58 |
59 |
59 |
60 clientSendLoop :: Socket -> Chan CoreMessage -> Chan [B.ByteString] -> ClientIndex -> IO() |
60 clientSendLoop :: Socket -> Chan [B.ByteString] -> ClientIndex -> IO () |
61 clientSendLoop s coreChan chan ci = do |
61 clientSendLoop s chan ci = do |
62 answer <- readChan chan |
62 answer <- readChan chan |
63 Exception.handle |
63 Exception.handle |
64 (\(e :: Exception.IOException) -> when (not $ isQuit answer) $ sendQuit e) $ do |
64 (\(e :: Exception.IOException) -> when (not $ isQuit answer) $ sendQuit e) $ do |
65 sendAll s $ (B.unlines answer) `B.append` (B.singleton '\n') |
65 sendAll s $ (B.unlines answer) `B.append` (B.singleton '\n') |
66 |
66 |
67 if (isQuit answer) then |
67 if (isQuit answer) then |
68 Exception.handle (\(_ :: Exception.IOException) -> putStrLn "error on sClose") $ sClose s |
68 Exception.handle (\(_ :: Exception.IOException) -> putStrLn "error on sClose") $ sClose s |
69 else |
69 else |
70 clientSendLoop s coreChan chan ci |
70 clientSendLoop s chan ci |
71 |
71 |
72 where |
72 where |
73 --sendQuit e = writeChan coreChan $ ClientMessage (ci, ["QUIT", B.pack $ show e]) |
73 --sendQuit e = writeChan coreChan $ ClientMessage (ci, ["QUIT", B.pack $ show e]) |
74 sendQuit e = putStrLn $ show e |
74 sendQuit e = putStrLn $ show e |
75 isQuit ("BYE":xs) = True |
75 isQuit ("BYE":xs) = True |