@@ -45,6 +45,8 @@ module Control.Distributed.Process.UnsafePrimitives
4545 send
4646 , sendChan
4747 , nsend
48+ , nsendRemote
49+ , usend
4850 , wrapMessage
4951 ) where
5052
@@ -56,6 +58,7 @@ import Control.Distributed.Process.Internal.Messaging
5658
5759import Control.Distributed.Process.Internal.Types
5860 ( ProcessId(..)
61+ , NodeId(..)
5962 , LocalNode(..)
6063 , LocalProcess(..)
6164 , Process(..)
@@ -65,6 +68,7 @@ import Control.Distributed.Process.Internal.Types
6568 , ImplicitReconnect(..)
6669 , SendPortId(..)
6770 , Message
71+ , createMessage
6872 , sendPortProcessId
6973 , unsafeCreateUnencodedMessage
7074 )
@@ -78,6 +82,14 @@ nsend :: Serializable a => String -> a -> Process ()
7882nsend label msg =
7983 sendCtrlMsg Nothing (NamedSend label (unsafeCreateUnencodedMessage msg))
8084
85+-- | Named send to a process in a remote registry (asynchronous)
86+nsendRemote :: Serializable a => NodeId -> String -> a -> Process ()
87+nsendRemote nid label msg = do
88+ proc <- ask
89+ if localNodeId (processNode proc) == nid
90+ then nsend label msg
91+ else sendCtrlMsg (Just nid) (NamedSend label (createMessage msg))
92+
8193-- | Send a message
8294send :: Serializable a => ProcessId -> a -> Process ()
8395send them msg = do
@@ -96,6 +108,25 @@ send them msg = do
96108 unsafeSendLocal pid msg' =
97109 sendCtrlMsg Nothing $ LocalSend pid (unsafeCreateUnencodedMessage msg')
98110
111+-- | Send a message unreliably.
112+--
113+-- Unlike 'send', this function is insensitive to 'reconnect'. It will
114+-- try to send the message regardless of the history of connection failures
115+-- between the nodes.
116+--
117+-- Message passing with 'usend' is ordered for a given sender and receiver
118+-- if the messages arrive at all.
119+--
120+usend :: Serializable a => ProcessId -> a -> Process ()
121+usend them msg = do
122+ proc <- ask
123+ let there = processNodeId them
124+ if localNodeId (processNode proc) == there
125+ then sendCtrlMsg Nothing $
126+ LocalSend them (unsafeCreateUnencodedMessage msg)
127+ else sendCtrlMsg (Just there) $ UnreliableSend (processLocalId them)
128+ (createMessage msg)
129+
99130-- | Send a message on a typed channel
100131sendChan :: Serializable a => SendPort a -> a -> Process ()
101132sendChan (SendPort cid) msg = do