@@ -25,6 +25,7 @@ import qualified Data.Map as Map
25
25
, toList
26
26
, partitionWithKey
27
27
, filterWithKey
28
+ , elems
28
29
)
29
30
import Data.Set (Set )
30
31
import qualified Data.Set as Set (empty , insert , delete , member , filter )
@@ -65,6 +66,7 @@ import qualified Network.Transport as NT
65
66
, closeEndPoint
66
67
, ConnectionId
67
68
, Connection
69
+ , close
68
70
)
69
71
import Data.Accessor (Accessor , accessor , (^.) , (^=) , (^:) )
70
72
import qualified Data.Accessor.Container as DAC (mapDefault , mapMaybe )
@@ -214,9 +216,13 @@ forkProcess node proc = modifyMVar (localState node) $ \st -> do
214
216
(runLocalProcess lproc proc >> return DiedNormal )
215
217
(return . DiedException . (show :: SomeException -> String ))
216
218
-- [Unified: Table 4, rules termination and exiting]
217
- modifyMVar_ (localState node) $
218
- return . (localProcessWithId lpid ^= Nothing )
219
- . (localConnections ^: removeConnectionsFrom (ProcessIdentifier pid))
219
+ modifyMVar_ (localState node) $ \ st -> do
220
+ let pid' = ProcessIdentifier pid
221
+ let (affected, unaffected) = Map. partitionWithKey (\ (fr, _to) ! _v -> impliesDeathOf pid' fr) (st ^. localConnections)
222
+ mapM_ NT. close (Map. elems affected)
223
+ return $ (localProcessWithId lpid ^= Nothing )
224
+ . (localConnections ^= unaffected)
225
+ $ st
220
226
writeChan (localCtrlChan node) NCMsg
221
227
{ ctrlMsgSender = ProcessIdentifier pid
222
228
, ctrlMsgSignal = Died (ProcessIdentifier pid) reason
@@ -239,13 +245,6 @@ forkProcess node proc = modifyMVar (localState node) $ \st -> do
239
245
, pid
240
246
)
241
247
242
- -- | Remove connections from 'ident' (typically because 'ident' has terminated)
243
- removeConnectionsFrom :: Identifier
244
- -> Map (Identifier , Identifier ) NT. Connection
245
- -> Map (Identifier , Identifier ) NT. Connection
246
- removeConnectionsFrom ident =
247
- Map. filterWithKey $ \ (fr, _to) _conn -> fr /= ident
248
-
249
248
handleIncomingMessages :: LocalNode -> IO ()
250
249
handleIncomingMessages node = go Set. empty Map. empty Map. empty Set. empty
251
250
where
0 commit comments