@@ -306,8 +306,8 @@ data NCState = NCState
306newtype NC a = NC { unNC :: StateT NCState (MessageT IO) a }
306newtype NC a = NC { unNC :: StateT NCState (MessageT IO) a }
307 deriving (Functor, Monad, MonadIO, MonadState NCState)
307 deriving (Functor, Monad, MonadIO, MonadState NCState)
309−lift :: MessageT IO a -> NC a
309+ncMsg :: MessageT IO a -> NC a
310−lift = NC . Trans.lift
310+ncMsg = NC . Trans.lift
312initNCState :: NCState
312initNCState :: NCState
313initNCState = NCState { _links = Map.empty
313initNCState = NCState { _links = Map.empty
@@ -321,14 +321,14 @@ initNCState = NCState { _links = Map.empty
321-- [Unified: Table 7]
321-- [Unified: Table 7]
322nodeController :: NC ()
322nodeController :: NC ()
323nodeController = do
323nodeController = do
324− node <- lift getLocalNode
324+ node <- ncMsg getLocalNode
325 forever $ do
325 forever $ do
326 msg <- liftIO $ readChan (localCtrlChan node)
326 msg <- liftIO $ readChan (localCtrlChan node)
328 -- [Unified: Table 7, rule nc_forward]
328 -- [Unified: Table 7, rule nc_forward]
329 case destNid (ctrlMsgSignal msg) of
329 case destNid (ctrlMsgSignal msg) of
330 Just nid' | nid' /= localNodeId node ->
330 Just nid' | nid' /= localNodeId node ->
331− lift $ sendBinary (NodeIdentifier nid') msg
331+ ncMsg $ sendBinary (NodeIdentifier nid') msg
333 return ()
333 return ()
@@ -356,7 +356,7 @@ ncEffectMonitor :: ProcessId -- ^ Who's watching?
356 -> Maybe MonitorRef -- ^ 'Nothing' to link
356 -> Maybe MonitorRef -- ^ 'Nothing' to link
358ncEffectMonitor from them mRef = do
358ncEffectMonitor from them mRef = do
359− node <- lift getLocalNode
359+ node <- ncMsg getLocalNode
360 shouldLink <-
360 shouldLink <-
361 if not (isLocal node them)
361 if not (isLocal node them)
362 then return True
362 then return True
@@ -370,7 +370,7 @@ ncEffectMonitor from them mRef = do
370 (False, True) -> -- [Unified: second rule]
370 (False, True) -> -- [Unified: second rule]
371 notifyDied from them DiedNoProc mRef
371 notifyDied from them DiedNoProc mRef
372 (False, False) -> -- [Unified: third rule]
372 (False, False) -> -- [Unified: third rule]
373− lift $ sendBinary (NodeIdentifier $ processNodeId from) NCMsg
373+ ncMsg $ sendBinary (NodeIdentifier $ processNodeId from) NCMsg
374 { ctrlMsgSender = NodeIdentifier (localNodeId node)
374 { ctrlMsgSender = NodeIdentifier (localNodeId node)
375 , ctrlMsgSignal = Died (ProcessIdentifier them) DiedNoProc
375 , ctrlMsgSignal = Died (ProcessIdentifier them) DiedNoProc
@@ -378,21 +378,21 @@ ncEffectMonitor from them mRef = do
378-- [Unified: Table 11]
378-- [Unified: Table 11]
379ncEffectUnlink :: ProcessId -> ProcessId -> NC ()
379ncEffectUnlink :: ProcessId -> ProcessId -> NC ()
380ncEffectUnlink from them = do
380ncEffectUnlink from them = do
381− node <- lift getLocalNode
381+ node <- ncMsg getLocalNode
382 when (isLocal node from) $ postMessage from $ DidUnlink them
382 when (isLocal node from) $ postMessage from $ DidUnlink them
383 modify $ linksForProcess them ^: Set.delete from
383 modify $ linksForProcess them ^: Set.delete from
385-- [Unified: Table 11]
385-- [Unified: Table 11]
386ncEffectUnmonitor :: ProcessId -> MonitorRef -> NC ()
386ncEffectUnmonitor :: ProcessId -> MonitorRef -> NC ()
387ncEffectUnmonitor from ref = do
387ncEffectUnmonitor from ref = do
388− node <- lift getLocalNode
388+ node <- ncMsg getLocalNode
389 when (isLocal node from) $ postMessage from $ DidUnmonitor ref
389 when (isLocal node from) $ postMessage from $ DidUnmonitor ref
390 modify $ monitorsFor (monitorRefPid ref) from ^: Set.delete ref
390 modify $ monitorsFor (monitorRefPid ref) from ^: Set.delete ref
392-- [Unified: Table 12, bottom rule]
392-- [Unified: Table 12, bottom rule]
393ncEffectNodeDied :: NodeId -> DiedReason -> NC ()
393ncEffectNodeDied :: NodeId -> DiedReason -> NC ()
394ncEffectNodeDied nid reason = do
394ncEffectNodeDied nid reason = do
395− node <- lift getLocalNode
395+ node <- ncMsg getLocalNode
396 lnks <- gets (^. linksForNode nid)
396 lnks <- gets (^. linksForNode nid)
397 mons <- gets (^. monitorsForNode nid)
397 mons <- gets (^. monitorsForNode nid)
@@ -434,9 +434,9 @@ ncEffectSpawn pid cProc ref = do
434 mProc <- unClosure cProc
434 mProc <- unClosure cProc
435 case mProc of
435 case mProc of
436 Just proc -> do
436 Just proc -> do
437− node <- lift getLocalNode
437+ node <- ncMsg getLocalNode
438 pid' <- liftIO $ forkProcess node proc
438 pid' <- liftIO $ forkProcess node proc
439− lift $ sendMessage (ProcessIdentifier pid) (DidSpawn ref pid')
439+ ncMsg $ sendMessage (ProcessIdentifier pid) (DidSpawn ref pid')
440 Nothing ->
440 Nothing ->
441 -- TODO: what should we do when unClosure returns Nothing?
441 -- TODO: what should we do when unClosure returns Nothing?
442 liftIO . putStrLn $ "Error: closure " ++ show cProc ++ " not found"
442 liftIO . putStrLn $ "Error: closure " ++ show cProc ++ " not found"
@@ -452,7 +452,7 @@ notifyDied :: ProcessId -- ^ Who to notify?
452 -> Maybe MonitorRef -- ^ 'Nothing' for linking
452 -> Maybe MonitorRef -- ^ 'Nothing' for linking
454notifyDied dest src reason mRef = do
454notifyDied dest src reason mRef = do
455− node <- lift getLocalNode
455+ node <- ncMsg getLocalNode
456 case (isLocal node dest, mRef) of
456 case (isLocal node dest, mRef) of
457 (True, Just ref) ->
457 (True, Just ref) ->
458 postMessage dest $ MonitorNotification ref src reason
458 postMessage dest $ MonitorNotification ref src reason
@@ -461,7 +461,7 @@ notifyDied dest src reason mRef = do
461 (False, _) ->
461 (False, _) ->
462 -- TODO: why the change in sender? How does that affect 'reconnect' semantics?
462 -- TODO: why the change in sender? How does that affect 'reconnect' semantics?
463 -- (see [Unified: Table 10]
463 -- (see [Unified: Table 10]
464− lift $ sendBinary (NodeIdentifier $ processNodeId dest) NCMsg
464+ ncMsg $ sendBinary (NodeIdentifier $ processNodeId dest) NCMsg
465 { ctrlMsgSender = NodeIdentifier (localNodeId node)
465 { ctrlMsgSender = NodeIdentifier (localNodeId node)
466 , ctrlMsgSignal = Died (ProcessIdentifier src) reason
466 , ctrlMsgSignal = Died (ProcessIdentifier src) reason
@@ -494,7 +494,7 @@ isLocal nid pid = processNodeId pid == localNodeId nid
494-- TODO: Duplication with onClosure in Process
494-- TODO: Duplication with onClosure in Process
495unClosure :: Typeable a => Closure a -> NC (Maybe a)
495unClosure :: Typeable a => Closure a -> NC (Maybe a)
496unClosure (Closure (Static label) env) = do
496unClosure (Closure (Static label) env) = do
497− rtable <- remoteTable <$> lift getLocalNode
497+ rtable <- remoteTable <$> ncMsg getLocalNode
498 case resolveClosure rtable label env of
498 case resolveClosure rtable label env of
499 Nothing -> return Nothing
499 Nothing -> return Nothing
500 Just dyn -> return (fromDynamic dyn)
500 Just dyn -> return (fromDynamic dyn)
@@ -513,7 +513,7 @@ throwException pid e = withLocalProc pid $ \p ->
514withLocalProc :: ProcessId -> (LocalProcess -> IO ()) -> NC ()
514withLocalProc :: ProcessId -> (LocalProcess -> IO ()) -> NC ()
515withLocalProc pid p = do
515withLocalProc pid p = do
516− node <- lift getLocalNode
516+ node <- ncMsg getLocalNode
517 liftIO $ do
517 liftIO $ do
518 -- By [Unified: table 6, rule missing_process] messages to dead processes
518 -- By [Unified: table 6, rule missing_process] messages to dead processes
519 -- can silently be dropped
519 -- can silently be dropped