@@ -254,17 +254,15 @@ send them msg = do
254254 node = processNode proc
255255 nodeId = localNodeId node
256256 destNode = (processNodeId them) in do
257− case destNode == nodeId of
258− True -> sendLocal them msg
259− False -> liftIO $ sendMessage (processNode proc)
260− (ProcessIdentifier (processId proc))
261− (ProcessIdentifier them)
262− NoImplicitReconnect
263− msg
264− -- We do not fire the trace event until after the sending is complete;
265− -- In the remote case, 'sendMessage' can block in the networking stack.
266257 liftIO $ traceEvent (localEventBus node)
267258 (MxSent them us (createUnencodedMessage msg))
259+ if destNode == nodeId
260+ then sendLocal them msg
261+ else liftIO $ sendMessage (processNode proc)
262+ (ProcessIdentifier (processId proc))
263+ (ProcessIdentifier them)
264+ NoImplicitReconnect
265+ msg
268266
269267-- | /Unsafe/ variant of 'send'. This function makes /no/ attempt to serialize
270268-- and (in the case when the destination process resides on the same local
@@ -284,9 +282,12 @@ unsafeSend = Unsafe.send
284282--
285283usend :: Serializable a => ProcessId -> a -> Process ()
286284usend them msg = do
287− here <- getSelfNode
285+ proc <- ask
288286 let there = processNodeId them
289− if here == there
287+ let (us, node) = (processId proc, processNode proc)
288+ let msg' = wrapMessage msg
289+ liftIO $ traceEvent (localEventBus node) (MxSent them us msg')
290+ if localNodeId (processNode proc) == there
290291 then sendLocal them msg
291292 else sendCtrlMsg (Just there) $ UnreliableSend (processLocalId them)
292293 (createMessage msg)
@@ -484,15 +485,14 @@ forward msg them = do
484485 us = processId proc
485486 nid = localNodeId node
486487 destNode = (processNodeId them) in do
487− case destNode == nid of
488− True -> sendCtrlMsg Nothing (LocalSend them msg)
489− False ->
490− liftIO $ do
491− sendPayload (processNode proc) (ProcessIdentifier (processId proc)) (ProcessIdentifier them) NoImplicitReconnect (messageToPayload msg)
492− -- We do not fire the trace event until after the sending is complete;
493− -- In this remote case, 'sendMessage' can block in the networking stack.
494− liftIO $ traceEvent (localEventBus node)
495− (MxSent them us msg)
488+ liftIO $ traceEvent (localEventBus node) (MxSent them us msg)
489+ if destNode == nid
490+ then sendCtrlMsg Nothing (LocalSend them msg)
491+ else liftIO $ sendPayload (processNode proc)
492+ (ProcessIdentifier (processId proc))
493+ (ProcessIdentifier them)
494+ NoImplicitReconnect
495+ (messageToPayload msg)
496496
497497-- | Forward a raw 'Message' to the given 'ProcessId'.
498498--
@@ -506,14 +506,10 @@ uforward msg them = do
506506 us = processId proc
507507 nid = localNodeId node
508508 destNode = (processNodeId them) in do
509− case destNode == nid of
510− True -> sendCtrlMsg Nothing (LocalSend them msg)
511− False -> do
512− sendCtrlMsg (Just destNode) $ UnreliableSend (processLocalId them) msg
513− -- We do not fire the trace event until after the sending is complete;
514− -- In the remote case, 'sendCtrlMsg' can block in the networking stack.
515− liftIO $ traceEvent (localEventBus node)
516− (MxSent them us msg)
509+ liftIO $ traceEvent (localEventBus node) (MxSent them us msg)
510+ if destNode == nid
511+ then sendCtrlMsg Nothing (LocalSend them msg)
512+ else sendCtrlMsg (Just destNode) $ UnreliableSend (processLocalId them) msg
517513
518514-- | Wrap a 'Serializable' value in a 'Message'. Note that 'Message's are
519515-- 'Serializable' - like the datum they contain - but also note, deserialising
@@ -1222,8 +1218,12 @@ whereisRemoteAsync nid label = do
12221218
12231219-- | Named send to a process in the local registry (asynchronous)
12241220nsend :: Serializable a => String -> a -> Process ()
1225−nsend label msg =
1226− sendCtrlMsg Nothing (NamedSend label (createUnencodedMessage msg))
1221+nsend label msg = do
1222+ proc <- ask
1223+ let msg' = createUnencodedMessage msg
1224+ liftIO $ traceEvent (localEventBus (processNode proc))
1225+ (MxSentToName label (processId proc) msg')
1226+ sendCtrlMsg Nothing (NamedSend label msg')
12271227
12281228-- | Named send to a process in the local registry (asynchronous).
12291229-- This function makes /no/ attempt to serialize and (in the case when the
@@ -1235,9 +1235,15 @@ unsafeNSend = Unsafe.nsend
12351235-- | Named send to a process in a remote registry (asynchronous)
12361236nsendRemote :: Serializable a => NodeId -> String -> a -> Process ()
12371237nsendRemote nid label msg = do
1238− here <- getSelfNode
1239− if here == nid then nsend label msg
1240− else sendCtrlMsg (Just nid) (NamedSend label (createMessage msg))
1238+ proc <- ask
1239+ let us = processId proc
1240+ let node = processNode proc
1241+ if localNodeId node == nid
1242+ then nsend label msg
1243+ else let lbl = label ++ "@" ++ show nid in do
1244+ liftIO $ traceEvent (localEventBus node)
1245+ (MxSentToName lbl us (wrapMessage msg))
1246+ sendCtrlMsg (Just nid) (NamedSend label (createMessage msg))
12411247
12421248-- | Named send to a process in a remote registry (asynchronous)
12431249-- This function makes /no/ attempt to serialize and (in the case when the