[server] Send partial updates when possible

This commit is contained in:
Joscha 2020-02-12 10:58:39 +00:00
parent 45a6d1934e
commit b2b34d551a
2 changed files with 51 additions and 14 deletions

View file

@ -17,12 +17,16 @@ import Forest.Util
{- Thread that sends updates to the client -}
sendUpdatesThread :: WS.Connection -> Chan Node -> Node -> IO ()
sendUpdatesThread conn nodeChan _ = do
node' <- readChan nodeChan
-- TODO Don't send the whole node every time
putStrLn $ "Sending full node update with " ++ show node'
sendPacket conn $ ServerUpdate (Path []) node'
sendUpdatesThread conn nodeChan node'
sendUpdatesThread conn nodeChan nodeA = do
nodeB <- readChan nodeChan
case diffNodes nodeA nodeB of
Nothing -> do
putStrLn "Sending no update because the node didn't change"
sendUpdatesThread conn nodeChan nodeA
Just (path, nextNode) -> do
putStrLn $ "Sending partial update for path " ++ show path ++ ": " ++ show nextNode
sendPacket conn $ ServerUpdate path nextNode
sendUpdatesThread conn nodeChan nodeB
{- Main server application that receives and processes client packets -}