From 3581bb6d887728441d161765392a0d96ae8ccf19 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sun, 26 Jan 2020 03:51:45 -0500 Subject: Remove timed-out sessions from aggregate map. --- dht/src/Network/Tox/AggregateSession.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dht/src/Network/Tox/AggregateSession.hs b/dht/src/Network/Tox/AggregateSession.hs index 44bbf9b9..c657f4d9 100644 --- a/dht/src/Network/Tox/AggregateSession.hs +++ b/dht/src/Network/Tox/AggregateSession.hs @@ -269,12 +269,12 @@ addSession c s = do forkSession c s $ \progress -> do status0 <- aggregateStatus c writeTVar (singleStatus con) progress - emap' <- do - emap <- readTVar (contactEstablished c) - return $ case progress of - Established -> IntMap.insert (sSessionID s) () emap - _ -> IntMap.delete (sSessionID s) emap - writeTVar (contactEstablished c) emap' + let sid = sSessionID s + modifyTVar' (contactEstablished c) $ case progress of + Established -> IntMap.insert sid () + _ -> IntMap.delete sid + when (progress == Dormant) $ + modifyTVar' (contactSession c) (IntMap.delete sid) status <- aggregateStatus c when (status /= status0) $ notifyState c c s status mapM_ (delSession c) closed -- cgit v1.2.3