From 7bf97fac186cccd7394be0e00b424c475abd90a5 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Fri, 24 Dec 2021 19:31:39 +0000 Subject: [PATCH] add sessionId and blockSize to the client record used internally (#241) --- src/Simplex/Messaging/Client.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Simplex/Messaging/Client.hs b/src/Simplex/Messaging/Client.hs index db0ffefcc..c5723907f 100644 --- a/src/Simplex/Messaging/Client.hs +++ b/src/Simplex/Messaging/Client.hs @@ -166,8 +166,8 @@ getSMPClient smpServer cfg@SMPClientConfig {qSize, tcpTimeout, smpPing, smpBlock async $ runTransportClient (host smpServer) port' (keyHash smpServer) (client t c thVar) `finally` atomically (putTMVar thVar $ Left SMPNetworkError) - bSize <- tcpTimeout `timeout` atomically (takeTMVar thVar) - pure $ case bSize of + th_ <- tcpTimeout `timeout` atomically (takeTMVar thVar) + pure $ case th_ of Just (Right THandle {sessionId, blockSize}) -> Right c {action, sessionId, blockSize} Just (Left e) -> Left e @@ -183,11 +183,12 @@ getSMPClient smpServer cfg@SMPClientConfig {qSize, tcpTimeout, smpPing, smpBlock client _ c thVar h = runExceptT (clientHandshake h smpBlockSize) >>= \case Left e -> atomically . putTMVar thVar . Left $ SMPTransportError e - Right th -> do + Right th@THandle {sessionId, blockSize} -> do atomically $ do writeTVar (connected c) True putTMVar thVar $ Right th - raceAny_ [send c th, process c, receive c th, ping c] + let c' = c {sessionId, blockSize} :: SMPClient + raceAny_ [send c' th, process c', receive c' th, ping c'] `finally` disconnected send :: Transport c => SMPClient -> THandle c -> IO ()