Skip to content

Commit 10c6034

Browse files
Merge pull request haskell-distributed#262 from haskell-distributed/fd/nsendRemote-skips-transport
Have nsendRemote skip the transport for local communication.
2 parents 6deb13d + 17c06e6 commit 10c6034

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/Control/Distributed/Process/Internal/Primitives.hs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,8 +1112,10 @@ registerImpl force label pid = do
11121112
--
11131113
-- See comments in 'whereisRemoteAsync'
11141114
registerRemoteAsync :: NodeId -> String -> ProcessId -> Process ()
1115-
registerRemoteAsync nid label pid =
1116-
sendCtrlMsg (Just nid) (Register label nid (Just pid) False)
1115+
registerRemoteAsync nid label pid = do
1116+
here <- getSelfNode
1117+
sendCtrlMsg (if nid == here then Nothing else Just nid)
1118+
(Register label nid (Just pid) False)
11171119

11181120
reregisterRemoteAsync :: NodeId -> String -> ProcessId -> Process ()
11191121
reregisterRemoteAsync nid label pid =
@@ -1165,8 +1167,9 @@ whereis label = do
11651167
-- use 'monitorNode' and take appropriate action when you receive a
11661168
-- 'NodeMonitorNotification').
11671169
whereisRemoteAsync :: NodeId -> String -> Process ()
1168-
whereisRemoteAsync nid label =
1169-
sendCtrlMsg (Just nid) (WhereIs label)
1170+
whereisRemoteAsync nid label = do
1171+
here <- getSelfNode
1172+
sendCtrlMsg (if nid == here then Nothing else Just nid) (WhereIs label)
11701173

11711174
-- | Named send to a process in the local registry (asynchronous)
11721175
nsend :: Serializable a => String -> a -> Process ()
@@ -1182,8 +1185,10 @@ unsafeNSend = Unsafe.nsend
11821185

11831186
-- | Named send to a process in a remote registry (asynchronous)
11841187
nsendRemote :: Serializable a => NodeId -> String -> a -> Process ()
1185-
nsendRemote nid label msg =
1186-
sendCtrlMsg (Just nid) (NamedSend label (createMessage msg))
1188+
nsendRemote nid label msg = do
1189+
here <- getSelfNode
1190+
if here == nid then nsend label msg
1191+
else sendCtrlMsg (Just nid) (NamedSend label (createMessage msg))
11871192

11881193
-- | Named send to a process in a remote registry (asynchronous)
11891194
-- This function makes /no/ attempt to serialize and (in the case when the

0 commit comments

Comments
 (0)