From a7cc1e718b87240ef83e2c4abfd4f2efdd6a7e87 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sat, 11 Jan 2020 21:28:13 -0500 Subject: Simplified AggregateSession status reporting. --- dht/src/Network/Tox/AggregateSession.hs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/dht/src/Network/Tox/AggregateSession.hs b/dht/src/Network/Tox/AggregateSession.hs index faf512d0..9a784291 100644 --- a/dht/src/Network/Tox/AggregateSession.hs +++ b/dht/src/Network/Tox/AggregateSession.hs @@ -243,23 +243,19 @@ addSession c s = do return (result,Just con,s0) mapM_ (sClose . singleSession) replaced - forM_ mcon $ \con -> + forM_ (mcon :: Maybe SingleCon) $ \con -> forkSession c s $ \progress -> do + status0 <- aggregateStatus c writeTVar (singleStatus con) progress - emap <- readTVar (contactEstablished c) - emap' <- case progress of - Established -> do - when (IntMap.null emap) $ notifyState c c s Established - return $ IntMap.insert (sSessionID s) () emap - _ -> do - let emap' = IntMap.delete (sSessionID s) emap - when (IntMap.null emap' && not (IntMap.null emap)) $ do - imap <- readTVar (contactSession c) - notifyState c c s - $ if IntMap.null imap then Dormant - else InProgress AwaitingSessionPacket - return emap' + 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' + status <- aggregateStatus c + when (status /= status0) $ notifyState c c s status + return result -- | Information returned from 'delSession'. -- cgit v1.2.3