Skip to content

Commit

Permalink
add a comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kohei-Wada committed Jul 1, 2023
1 parent 84eec04 commit 406754d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ newClient Server{..} name s = do
}


-- | Send a message to the specified client.
sendMessage :: Client -> Message -> STM ()
sendMessage Client{..} msg = writeTChan clientSendChan msg


-- | Initialize the server instance.
newServer :: IO Server
newServer = do
cs <- newTVarIO M.empty
Expand All @@ -74,10 +76,12 @@ newServer = do
}


-- | Send a message to all connected clients.
broadcast :: Server -> Message -> STM ()
broadcast Server{..} msg = writeTChan serverChan msg


-- | Check if the given client name is alreay in use.
checkAddClient :: Server -> ClientName -> Socket -> IO (Maybe Client)
checkAddClient server@Server{..} name s = atomically $ do
clientMap <- readTVar clients
Expand All @@ -91,6 +95,7 @@ checkAddClient server@Server{..} name s = atomically $ do
pure (Just client)


-- | Disconnect from the specified client.
removeClient :: Server -> ClientName -> IO ()
removeClient server@Server{..} name = atomically $ do
modifyTVar' clients $ M.delete name
Expand Down Expand Up @@ -166,6 +171,7 @@ handleMessage server client@Client{..} message = do
output m = sendAll clientSock (m <> "\n") >> pure True


-- | Disconnect a client that specified by connected user.
kick :: Server -> ClientName -> ClientName -> STM ()
kick server@Server{..} who by = do
clientMap <- readTVar clients
Expand Down

0 comments on commit 406754d

Please sign in to comment.