@@ -226,6 +226,7 @@ import Control.Distributed.Process.Internal.Messaging
227import Control.Distributed.Process.Management.Internal.Types
227import Control.Distributed.Process.Management.Internal.Types
228 ( MxEvent(..)
228 ( MxEvent(..)
230import Control.Distributed.Process.Management.Internal.Trace.Types
231import Control.Distributed.Process.Management.Internal.Trace.Types
231 ( traceEvent
232 ( traceEvent
@@ -256,14 +257,16 @@ send them msg = do
256 case destNode == nodeId of
257 case destNode == nodeId of
257 True -> sendLocal them msg
258 True -> sendLocal them msg
258 False -> liftIO $ sendMessage (processNode proc)
259 False -> liftIO $ sendMessage (processNode proc)
259− (ProcessIdentifier (processId proc))
260+ (ProcessIdentifier (processId proc))
260− (ProcessIdentifier them)
261+ (ProcessIdentifier them)
261− NoImplicitReconnect
262+ NoImplicitReconnect
263− -- We do not fire the trace event until after the sending is complete;
264+ -- see note [trace MxSent]
264− -- In the remote case, 'sendMessage' can block in the networking stack.
265 liftIO $ traceEvent (localEventBus node)
265 liftIO $ traceEvent (localEventBus node)
266+ MxSent { whichProcess = us
267+ , whereTo = ProcId them
266− (MxSent them us (createUnencodedMessage msg))
268+ , message = (createUnencodedMessage msg)
268-- | /Unsafe/ variant of 'send'. This function makes /no/ attempt to serialize
271-- | /Unsafe/ variant of 'send'. This function makes /no/ attempt to serialize
269-- and (in the case when the destination process resides on the same local
272-- and (in the case when the destination process resides on the same local
@@ -283,12 +286,22 @@ unsafeSend = Unsafe.send
284usend :: Serializable a => ProcessId -> a -> Process ()
287usend :: Serializable a => ProcessId -> a -> Process ()
285usend them msg = do
288usend them msg = do
286− here <- getSelfNode
289+ proc <- ask
290+ let us = processId proc
291+ node = processNode proc
292+ nodeId = localNodeId node
287− let there = processNodeId them
293+ let destNodeId = processNodeId them
288− if here == there
294+ if nodeId == destNodeId
289 then sendLocal them msg
295 then sendLocal them msg
296+ else do -- see note [trace MxSent]
297+ let evBus = localEventBus node
298+ let msg' = createMessage msg
290− else sendCtrlMsg (Just there) $ UnreliableSend (processLocalId them)
299+ sendCtrlMsg (Just destNodeId) $ UnreliableSend (processLocalId them) msg'
291− (createMessage msg)
300+ liftIO $ traceEvent evBus $ MxSent { whichProcess = us
301+ , whereTo = ProcId them
293-- | /Unsafe/ variant of 'usend'. This function makes /no/ attempt to serialize
306-- | /Unsafe/ variant of 'usend'. This function makes /no/ attempt to serialize
294-- the message when the destination process resides on the same local
307-- the message when the destination process resides on the same local
@@ -487,10 +500,12 @@ forward msg them = do
487 (ProcessIdentifier them)
500 (ProcessIdentifier them)
488 NoImplicitReconnect
501 NoImplicitReconnect
489 (messageToPayload msg)
502 (messageToPayload msg)
490− -- We do not fire the trace event until after the sending is complete;
503+
491− -- In the remote case, 'sendMessage' can block in the networking stack.
492 liftIO $ traceEvent (localEventBus node)
504 liftIO $ traceEvent (localEventBus node)
493− (MxSent them us msg)
505+ MxSent { whichProcess = us
506+ , whereTo = ProcId them
495-- | Forward a raw 'Message' to the given 'ProcessId'.
510-- | Forward a raw 'Message' to the given 'ProcessId'.
@@ -511,7 +526,10 @@ uforward msg them = do
511 -- We do not fire the trace event until after the sending is complete;
526 -- We do not fire the trace event until after the sending is complete;
512 -- In the remote case, 'sendCtrlMsg' can block in the networking stack.
527 -- In the remote case, 'sendCtrlMsg' can block in the networking stack.
513 liftIO $ traceEvent (localEventBus node)
528 liftIO $ traceEvent (localEventBus node)
514− (MxSent them us msg)
529+ MxSent { whichProcess = us
530+ , whereTo = ProcId them
516-- | Wrap a 'Serializable' value in a 'Message'. Note that 'Message's are
534-- | Wrap a 'Serializable' value in a 'Message'. Note that 'Message's are
517-- 'Serializable' - like the datum they contain - but also note, deserialising
535-- 'Serializable' - like the datum they contain - but also note, deserialising
@@ -1220,8 +1238,20 @@ whereisRemoteAsync nid label = do
1221-- | Named send to a process in the local registry (asynchronous)
1239-- | Named send to a process in the local registry (asynchronous)
1222nsend :: Serializable a => String -> a -> Process ()
1240nsend :: Serializable a => String -> a -> Process ()
1223−nsend label msg =
1241+nsend label msg = do
1243+ let us = processId proc
1244+ node = processNode proc
1245+ msg' = createMessage msg -- NB: using UnencodedMessage here causes chaos... :/
1224− sendCtrlMsg Nothing (NamedSend label (createUnencodedMessage msg))
1247+ sendCtrlMsg Nothing (NamedSend label msg')
1249+ -- see note [trace MxSent]
1250+ liftIO $ traceEvent (localEventBus node)
1251+ MxSent { whichProcess = us
1252+ , whereTo = ProcName label
1226-- | Named send to a process in the local registry (asynchronous).
1256-- | Named send to a process in the local registry (asynchronous).
1227-- This function makes /no/ attempt to serialize and (in the case when the
1257-- This function makes /no/ attempt to serialize and (in the case when the
@@ -1233,9 +1263,19 @@ unsafeNSend = Unsafe.nsend
1233-- | Named send to a process in a remote registry (asynchronous)
1263-- | Named send to a process in a remote registry (asynchronous)
1234nsendRemote :: Serializable a => NodeId -> String -> a -> Process ()
1264nsendRemote :: Serializable a => NodeId -> String -> a -> Process ()
1235nsendRemote nid label msg = do
1265nsendRemote nid label msg = do
1267+ let us = processId proc
1268+ node = processNode proc
1236 here <- getSelfNode
1269 here <- getSelfNode
1237 if here == nid then nsend label msg
1270 if here == nid then nsend label msg
1271+ else do let msg' = createMessage msg
1238− else sendCtrlMsg (Just nid) (NamedSend label (createMessage msg))
1272+ sendCtrlMsg (Just nid) (NamedSend label msg')
1273+ -- see note [trace MxSent]
1274+ liftIO $ traceEvent (localEventBus node)
1275+ MxSent { whichProcess = us
1276+ , whereTo = ProcName label
1240-- | Named send to a process in a remote registry (asynchronous)
1280-- | Named send to a process in a remote registry (asynchronous)
1241-- This function makes /no/ attempt to serialize and (in the case when the
1281-- This function makes /no/ attempt to serialize and (in the case when the
@@ -1306,8 +1346,18 @@ reconnectPort them = do
1306--------------------------------------------------------------------------------
1346--------------------------------------------------------------------------------
1308sendLocal :: (Serializable a) => ProcessId -> a -> Process ()
1348sendLocal :: (Serializable a) => ProcessId -> a -> Process ()
1309−sendLocal to msg =
1349+sendLocal to msg = do
1351+ let us = processId proc
1352+ node = processNode proc
1353+ msg' = createUnencodedMessage msg
1310− sendCtrlMsg Nothing $ LocalSend to (createUnencodedMessage msg)
1355+ sendCtrlMsg Nothing $ LocalSend to msg'
1356+ liftIO $ traceEvent (localEventBus node)
1357+ MxSent { whichProcess = us
1358+ , whereTo = ProcId to
1312sendChanLocal :: (Serializable a) => SendPortId -> a -> Process ()
1362sendChanLocal :: (Serializable a) => SendPortId -> a -> Process ()
1313sendChanLocal spId msg =
1363sendChanLocal spId msg =