This commit is contained in:
nek0 2024-10-31 21:01:53 +01:00
parent 5e4c7ca992
commit 71a760e054
4 changed files with 7 additions and 11 deletions

View file

@ -123,7 +123,6 @@ receiveMessage sock queue st = do
maybe maybe
(putStrLn $ "received garbled data: " <> B8.unpack (B8.fromStrict rawMsg)) (putStrLn $ "received garbled data: " <> B8.unpack (B8.fromStrict rawMsg))
(\jsonMsg -> do (\jsonMsg -> do
print jsonMsg
STM.atomically $ STM.writeTQueue queue jsonMsg STM.atomically $ STM.writeTQueue queue jsonMsg
) )
mJsonMsg mJsonMsg

View file

@ -120,7 +120,6 @@ handleMessages = do
liftIO $ do liftIO $ do
msgs <- STM.atomically $ msgs <- STM.atomically $
STM.flushTQueue queue STM.flushTQueue queue
do mapM_
mapM_ (handleMessage serverState readerContainer)
(handleMessage serverState readerContainer) msgs
msgs

View file

@ -37,7 +37,7 @@ receiveMessage sockContainer queue clientList = do
try $ recvBuf sock ptr maxBufferLength try $ recvBuf sock ptr maxBufferLength
bufferLength <- case eBufferLength of bufferLength <- case eBufferLength of
Left (e :: IOException) -> do Left (e :: IOException) -> do
putStrLn ("Socket vanished, cleaning up after " <> show e) -- putStrLn ("Socket vanished, cleaning up after " <> show e)
dropClient clientList sock dropClient clientList sock
pure 0 pure 0
Right len -> pure len Right len -> pure len

View file

@ -62,11 +62,10 @@ sendMessageQueue
-> STM.TQueue ServerMessage -> STM.TQueue ServerMessage
-> IO () -> IO ()
sendMessageQueue sockContainer queue = do sendMessageQueue sockContainer queue = do
sock <- STM.atomically $ STM.takeTMVar sockContainer sock <- STM.atomically $ STM.readTMVar sockContainer
msgs <- STM.atomically $ STM.flushTQueue queue msgs <- STM.atomically $ STM.flushTQueue queue
mapM_ mapM_
(\msg -> do (\msg -> do
print msg
let msgJson = A.encode msg let msgJson = A.encode msg
msgVector = VS.fromList $ B.unpack $ B.toStrict ('<' `B8.cons` (msgJson `B8.snoc` '>')) msgVector = VS.fromList $ B.unpack $ B.toStrict ('<' `B8.cons` (msgJson `B8.snoc` '>'))
VS.unsafeWith VS.unsafeWith
@ -81,7 +80,6 @@ sendMessageQueue sockContainer queue = do
) )
) )
msgs msgs
STM.atomically $ STM.putTMVar sockContainer sock
sendPings :: Game () sendPings :: Game ()
sendPings = do sendPings = do
@ -104,7 +102,7 @@ sendPings = do
put stateContainer put stateContainer
else do else do
random <- liftIO nextRandom random <- liftIO nextRandom
let newPong = (lastPongTime, random) let newPong = (now, random)
liftIO $ queueMessage liftIO $ queueMessage
( Ping random ( Ping random
) )
@ -133,7 +131,7 @@ dropClient clientList sock = do
void $ STM.swapTMVar clientList reducedClients void $ STM.swapTMVar clientList reducedClients
pure mclient pure mclient
maybe maybe
(putStrLn $ "closing unknown socket: " <> show sock) (pure ()) -- putStrLn $ "closing unknown socket: " <> show sock)
(\client -> do (\client -> do
putStrLn $ "dropping client: " <> show (fromJust $ ccUUID client) putStrLn $ "dropping client: " <> show (fromJust $ ccUUID client)
killThread (ccListener client) killThread (ccListener client)