@@ -254,17 +254,15 @@ send them msg = do
254 node = processNode proc
254 node = processNode proc
255 nodeId = localNodeId node
255 nodeId = localNodeId node
256 destNode = (processNodeId them) in do
256 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)
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.
266 liftIO $ traceEvent (localEventBus node)
257 liftIO $ traceEvent (localEventBus node)
267 (MxSent them us (createUnencodedMessage msg))
258 (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)
269-- | /Unsafe/ variant of 'send'. This function makes /no/ attempt to serialize
267-- | /Unsafe/ variant of 'send'. This function makes /no/ attempt to serialize
270-- and (in the case when the destination process resides on the same local
268-- and (in the case when the destination process resides on the same local
@@ -284,9 +282,12 @@ unsafeSend = Unsafe.send
285usend :: Serializable a => ProcessId -> a -> Process ()
283usend :: Serializable a => ProcessId -> a -> Process ()
286usend them msg = do
284usend them msg = do
287− here <- getSelfNode
285+ proc <- ask
288 let there = processNodeId them
286 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
290 then sendLocal them msg
291 then sendLocal them msg
291 else sendCtrlMsg (Just there) $ UnreliableSend (processLocalId them)
292 else sendCtrlMsg (Just there) $ UnreliableSend (processLocalId them)
292 (createMessage msg)
293 (createMessage msg)
@@ -484,15 +485,14 @@ forward msg them = do
484 us = processId proc
485 us = processId proc
485 nid = localNodeId node
486 nid = localNodeId node
486 destNode = (processNodeId them) in do
487 destNode = (processNodeId them) in do
488+ liftIO $ traceEvent (localEventBus node) (MxSent them us msg)
487− case destNode == nid of
489+ if destNode == nid
488− True -> sendCtrlMsg Nothing (LocalSend them msg)
490+ then sendCtrlMsg Nothing (LocalSend them msg)
489− False ->
491+ else liftIO $ sendPayload (processNode proc)
491− sendPayload (processNode proc) (ProcessIdentifier (processId proc)) (ProcessIdentifier them) NoImplicitReconnect (messageToPayload msg)
492+ (ProcessIdentifier (processId proc))
492− -- We do not fire the trace event until after the sending is complete;
493+ (ProcessIdentifier them)
493− -- In this remote case, 'sendMessage' can block in the networking stack.
494+ NoImplicitReconnect
494− liftIO $ traceEvent (localEventBus node)
495+ (messageToPayload msg)
495− (MxSent them us msg)
497-- | Forward a raw 'Message' to the given 'ProcessId'.
497-- | Forward a raw 'Message' to the given 'ProcessId'.
@@ -506,14 +506,10 @@ uforward msg them = do
506 us = processId proc
506 us = processId proc
507 nid = localNodeId node
507 nid = localNodeId node
508 destNode = (processNodeId them) in do
508 destNode = (processNodeId them) in do
509+ liftIO $ traceEvent (localEventBus node) (MxSent them us msg)
509− case destNode == nid of
510+ if destNode == nid
510− True -> sendCtrlMsg Nothing (LocalSend them msg)
511+ then sendCtrlMsg Nothing (LocalSend them msg)
512− sendCtrlMsg (Just destNode) $ UnreliableSend (processLocalId them) msg
512+ else 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)
518-- | Wrap a 'Serializable' value in a 'Message'. Note that 'Message's are
514-- | Wrap a 'Serializable' value in a 'Message'. Note that 'Message's are
519-- 'Serializable' - like the datum they contain - but also note, deserialising
515-- 'Serializable' - like the datum they contain - but also note, deserialising
@@ -1222,8 +1218,12 @@ whereisRemoteAsync nid label = do
1223-- | Named send to a process in the local registry (asynchronous)
1219-- | Named send to a process in the local registry (asynchronous)
1224nsend :: Serializable a => String -> a -> Process ()
1220nsend :: Serializable a => String -> a -> Process ()
1225−nsend label msg =
1221+nsend label msg = do
1223+ let msg' = createUnencodedMessage msg
1224+ liftIO $ traceEvent (localEventBus (processNode proc))
1225+ (MxSentToName label (processId proc) msg')
1226− sendCtrlMsg Nothing (NamedSend label (createUnencodedMessage msg))
1226+ sendCtrlMsg Nothing (NamedSend label msg')
1228-- | Named send to a process in the local registry (asynchronous).
1228-- | Named send to a process in the local registry (asynchronous).
1229-- This function makes /no/ attempt to serialize and (in the case when the
1229-- This function makes /no/ attempt to serialize and (in the case when the
@@ -1235,9 +1235,15 @@ unsafeNSend = Unsafe.nsend
1235-- | Named send to a process in a remote registry (asynchronous)
1235-- | Named send to a process in a remote registry (asynchronous)
1236nsendRemote :: Serializable a => NodeId -> String -> a -> Process ()
1236nsendRemote :: Serializable a => NodeId -> String -> a -> Process ()
1237nsendRemote nid label msg = do
1237nsendRemote nid label msg = do
1238− here <- getSelfNode
1238+ proc <- ask
1239+ let us = processId proc
1240+ let node = processNode proc
1241+ if localNodeId node == nid
1239− if here == nid then nsend label msg
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))
1240− else sendCtrlMsg (Just nid) (NamedSend label (createMessage msg))
1246+ sendCtrlMsg (Just nid) (NamedSend label (createMessage msg))
1242-- | Named send to a process in a remote registry (asynchronous)
1248-- | Named send to a process in a remote registry (asynchronous)
1243-- This function makes /no/ attempt to serialize and (in the case when the
1249-- This function makes /no/ attempt to serialize and (in the case when the