diff options
author | jim@bo <jim@bo> | 2018-06-22 04:11:18 -0400 |
---|---|---|
committer | jim@bo <jim@bo> | 2018-06-22 04:11:18 -0400 |
commit | 2ffb6b2b7f5d4c935770689a3afe763cb537d750 (patch) | |
tree | 9c236f0f529fab5acf9f32af1dd61105be7337c9 /src/Network | |
parent | ca844a01c1fd996eab830457271306e95651a174 (diff) |
fix thread cleanup bug
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/Tox/Crypto/Handlers.hs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs index 03207e06..bd421ea3 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs | |||
@@ -779,12 +779,14 @@ runUponHandshake netCryptoSession0 addr pktoq = do | |||
779 | dput XNetCrypto $ "Dequeued::" ++ show (bufferData cd) ++ " now running hook..." | 779 | dput XNetCrypto $ "Dequeued::" ++ show (bufferData cd) ++ " now running hook..." |
780 | void $ runCryptoHook netCryptoSession0 (bufferData cd) | 780 | void $ runCryptoHook netCryptoSession0 (bufferData cd) |
781 | loop | 781 | loop |
782 | atomically $ writeTVar (ncDequeueThread netCryptoSession0) (Just threadid) | ||
782 | dput XNetCrypto $ "runUponHandshake: " ++ show threadid ++ " = NetCryptoDequeue." ++ show (key2id remotePublicKey) ++ sidStr | 783 | dput XNetCrypto $ "runUponHandshake: " ++ show threadid ++ " = NetCryptoDequeue." ++ show (key2id remotePublicKey) ++ sidStr |
784 | |||
783 | -- launch request thread | 785 | -- launch request thread |
784 | -- (In terms of data dependency, this thread could be launched prior to handshake) | 786 | -- (In terms of data dependency, this thread could be launched prior to handshake) |
785 | threadid <- forkIO $ do | 787 | reqthreadId <- forkIO $ do |
786 | tid <- myThreadId | 788 | tid <- myThreadId |
787 | atomically $ writeTVar (ncDequeueThread netCryptoSession0) (Just tid) | 789 | atomically $ writeTVar (ncRequestThread netCryptoSession0) (Just tid) |
788 | labelThread tid ("NetCryptoRequest." ++ show (key2id remotePublicKey) ++ sidStr) | 790 | labelThread tid ("NetCryptoRequest." ++ show (key2id remotePublicKey) ++ sidStr) |
789 | fix $ \loop -> do | 791 | fix $ \loop -> do |
790 | atomically (readTVar (ncRequestInterval netCryptoSession0)) >>= threadDelay . (* 1000) | 792 | atomically (readTVar (ncRequestInterval netCryptoSession0)) >>= threadDelay . (* 1000) |
@@ -798,7 +800,9 @@ runUponHandshake netCryptoSession0 addr pktoq = do | |||
798 | PQ.OGSuccess -> return () | 800 | PQ.OGSuccess -> return () |
799 | _ -> retry | 801 | _ -> retry |
800 | loop | 802 | loop |
803 | atomically $ writeTVar (ncRequestThread netCryptoSession0) (Just reqthreadId) | ||
801 | dput XNetCrypto $ "runUponHandshake: " ++ show threadid ++ " = NetCryptoRequest." ++ show (key2id remotePublicKey) ++ sidStr | 804 | dput XNetCrypto $ "runUponHandshake: " ++ show threadid ++ " = NetCryptoRequest." ++ show (key2id remotePublicKey) ++ sidStr |
805 | |||
802 | -- launch dequeueOutgoing thread | 806 | -- launch dequeueOutgoing thread |
803 | threadidOutgoing <- forkIO $ do | 807 | threadidOutgoing <- forkIO $ do |
804 | tid <- myThreadId | 808 | tid <- myThreadId |
@@ -809,10 +813,13 @@ runUponHandshake netCryptoSession0 addr pktoq = do | |||
809 | dput XNetCrypto "NetCryptoDequeueOutgoing thread... Sending encrypted Packet" | 813 | dput XNetCrypto "NetCryptoDequeueOutgoing thread... Sending encrypted Packet" |
810 | sendSessionPacket sessions addr pkt | 814 | sendSessionPacket sessions addr pkt |
811 | loop | 815 | loop |
816 | atomically $ writeTVar (ncDequeueOutGoingThread netCryptoSession0) (Just threadidOutgoing) | ||
812 | dput XNetCrypto $ "runUponHandshake: " ++ show threadidOutgoing ++ " = NetCryptoDequeueOutgoing." ++ show (key2id remotePublicKey) ++ sidStr | 817 | dput XNetCrypto $ "runUponHandshake: " ++ show threadidOutgoing ++ " = NetCryptoDequeueOutgoing." ++ show (key2id remotePublicKey) ++ sidStr |
818 | |||
813 | -- launch ping Machine thread | 819 | -- launch ping Machine thread |
814 | pingMachine <- forkPingMachineDynamic ("NetCrypto." ++ show (key2id remotePublicKey) ++ sidStr) (ncIdleEvent netCryptoSession0) (ncTimeOut netCryptoSession0) | 820 | pingMachine <- forkPingMachineDynamic ("NetCrypto." ++ show (key2id remotePublicKey) ++ sidStr) (ncIdleEvent netCryptoSession0) (ncTimeOut netCryptoSession0) |
815 | atomically $ writeTVar (ncPingMachine netCryptoSession0) (Just pingMachine) | 821 | atomically $ writeTVar (ncPingMachine netCryptoSession0) (Just pingMachine) |
822 | |||
816 | -- launch ping thread | 823 | -- launch ping thread |
817 | pingThreadId <- forkIO $ do | 824 | pingThreadId <- forkIO $ do |
818 | tid <- myThreadId | 825 | tid <- myThreadId |
@@ -827,10 +834,11 @@ runUponHandshake netCryptoSession0 addr pktoq = do | |||
827 | Right _ -> return () | 834 | Right _ -> return () |
828 | loop | 835 | loop |
829 | atomically $ writeTVar (ncPingThread netCryptoSession0) (Just pingThreadId) | 836 | atomically $ writeTVar (ncPingThread netCryptoSession0) (Just pingThreadId) |
837 | |||
830 | -- launch IdleEvent thread | 838 | -- launch IdleEvent thread |
831 | idleThreadId <- forkIO $ do | 839 | idleThreadId <- forkIO $ do |
832 | tid <- myThreadId | 840 | tid <- myThreadId |
833 | atomically $ writeTVar (ncPingThread netCryptoSession0) (Just tid) | 841 | atomically $ writeTVar (ncIdleEventThread netCryptoSession0) (Just tid) |
834 | labelThread tid ("NetCryptoIdleEvent." ++ show (key2id remotePublicKey) ++ sidStr) | 842 | labelThread tid ("NetCryptoIdleEvent." ++ show (key2id remotePublicKey) ++ sidStr) |
835 | event <- atomically $ pingWait pingMachine | 843 | event <- atomically $ pingWait pingMachine |
836 | case event of | 844 | case event of |