gameServer/ClientIO.hs
changeset 3566 772a46ef8288
parent 3501 a3159a410e5c
child 3671 a94d1dc4a8d9
equal deleted inserted replaced
3565:bc3410104894 3566:772a46ef8288
    30                     else
    30                     else
    31                     if B.null bsPacket then 
    31                     if B.null bsPacket then 
    32                         Left bufTail
    32                         Left bufTail
    33                         else
    33                         else
    34                         Right (B.splitWith (== '\n') bsPacket, bufTail)
    34                         Right (B.splitWith (== '\n') bsPacket, bufTail)
    35                    
    35 
    36 
    36 
    37 listenLoop :: Socket -> Chan CoreMessage -> ClientIndex -> IO ()
    37 listenLoop :: Socket -> Chan CoreMessage -> ClientIndex -> IO ()
    38 listenLoop sock chan ci = recieveWithBufferLoop B.empty
    38 listenLoop sock chan ci = recieveWithBufferLoop B.empty
    39     where
    39     where
    40         recieveWithBufferLoop recvBuf = do
    40         recieveWithBufferLoop recvBuf = do
    51 clientRecvLoop :: Socket -> Chan CoreMessage -> ClientIndex -> IO ()
    51 clientRecvLoop :: Socket -> Chan CoreMessage -> ClientIndex -> IO ()
    52 clientRecvLoop s chan ci = do
    52 clientRecvLoop s chan ci = do
    53     msg <- (listenLoop s chan ci >> return "Connection closed") `catch` (return . B.pack . show)
    53     msg <- (listenLoop s chan ci >> return "Connection closed") `catch` (return . B.pack . show)
    54     clientOff msg
    54     clientOff msg
    55     where 
    55     where 
    56         clientOff msg = writeChan chan $ ClientMessage (ci, ["QUIT", msg])
    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 CoreMessage -> Chan [B.ByteString] -> ClientIndex -> IO()
    61 clientSendLoop s coreChan chan ci = do
    61 clientSendLoop s coreChan chan ci = do