git.iko.soy/distributed-process
on master help sign in
Merge pull request #173 from tweag/usend-hd

Implement unreliable send (usend).

commitfe428ee62c49822414386f262106eac0646669a7 authorTim Watson <watson.timothy@gmail.com> dateWed 18 Feb 2015, 14:21 (12 years ago) parenteccee2a13521a0
4 files changed+27
src/Control/Distributed/Process.hs+2 src/Control/Distributed/Process/Internal/Primitives.hs+19 src/Control/Distributed/Process/Internal/Types.hs+3 src/Control/Distributed/Process/Node.hs+3
src/Control/Distributed/Process.hs+2
@@ -25,6 +25,7 @@ module Control.Distributed.Process
2525 , liftIO -- Reexported for convenience
2626 -- * Basic messaging
2727 , send
28+ , usend
2829 , expect
2930 , expectTimeout
3031 -- * Channels
@@ -196,6 +197,7 @@ import Control.Distributed.Process.Serializable (Serializable)
196197import Control.Distributed.Process.Internal.Primitives
197198 ( -- Basic messaging
198199 send
200+ , usend
199201 , expect
200202 -- Channels
201203 , newChan
src/Control/Distributed/Process/Internal/Primitives.hs+19
@@ -12,6 +12,7 @@
1212module Control.Distributed.Process.Internal.Primitives
1313 ( -- * Basic messaging
1414 send
15+ , usend
1516 , expect
1617 -- * Channels
1718 , newChan
@@ -254,6 +255,24 @@ send them msg = do
254255unsafeSend :: Serializable a => ProcessId -> a -> Process ()
255256unsafeSend = Unsafe.send
256257
258+-- | Send a message unreliably.
259+--
260+-- Unlike 'send', this function is insensitive to 'reconnect'. It will
261+-- try to send the message regardless of the history of connection failures
262+-- between the nodes.
263+--
264+-- Message passing with 'usend' is ordered for a given sender and receiver
265+-- if the messages arrive at all.
266+--
267+usend :: Serializable a => ProcessId -> a -> Process ()
268+usend them msg = do
269+ here <- getSelfNode
270+ let there = processNodeId them
271+ if here == there
272+ then sendLocal them msg
273+ else sendCtrlMsg (Just there) $ UnreliableSend (processLocalId them)
274+ (createMessage msg)
275+
257276-- | Wait for a message of a specific type
258277expect :: forall a. Serializable a => Process a
259278expect = receiveWait [match return]
src/Control/Distributed/Process/Internal/Types.hs+3
@@ -572,6 +572,7 @@ data ProcessSignal =
572572 | WhereIs !String
573573 | Register !String !NodeId !(Maybe ProcessId) !Bool -- Use 'Nothing' to unregister, use True to force reregister
574574 | NamedSend !String !Message
575+ | UnreliableSend !LocalProcessId !Message
575576 | LocalSend !ProcessId !Message
576577 | LocalPortSend !SendPortId !Message
577578 | Kill !ProcessId !String
@@ -627,6 +628,7 @@ instance Binary ProcessSignal where
627628 put (Exit pid reason) = putWord8 10 >> put pid >> put (messageToPayload reason)
628629 put (LocalSend to' msg) = putWord8 11 >> put to' >> put (messageToPayload msg)
629630 put (LocalPortSend sid msg) = putWord8 12 >> put sid >> put (messageToPayload msg)
631+ put (UnreliableSend lpid msg) = putWord8 13 >> put lpid >> put (messageToPayload msg)
630632 put (GetInfo about) = putWord8 30 >> put about
631633 put (SigShutdown) = putWord8 31
632634 put (GetNodeStats nid) = putWord8 32 >> put nid
@@ -646,6 +648,7 @@ instance Binary ProcessSignal where
646648 10 -> Exit <$> get <*> (payloadToMessage <$> get)
647649 11 -> LocalSend <$> get <*> (payloadToMessage <$> get)
648650 12 -> LocalPortSend <$> get <*> (payloadToMessage <$> get)
651+ 13 -> UnreliableSend <$> get <*> (payloadToMessage <$> get)
649652 30 -> GetInfo <$> get
650653 31 -> return SigShutdown
651654 32 -> GetNodeStats <$> get
src/Control/Distributed/Process/Node.hs+3
@@ -693,6 +693,8 @@ nodeController = do
693693 ncEffectWhereIs from label
694694 NCMsg _ (NamedSend label msg') ->
695695 ncEffectNamedSend label msg'
696+ NCMsg _ (UnreliableSend lpid msg') ->
697+ ncEffectLocalSend node (ProcessId (localNodeId node) lpid) msg'
696698 NCMsg _ (LocalSend to msg') ->
697699 ncEffectLocalSend node to msg'
698700 NCMsg _ (LocalPortSend to msg') ->
@@ -1067,6 +1069,7 @@ destNid (Spawn _ _) = Nothing
10671069destNid (Register _ _ _ _) = Nothing
10681070destNid (WhereIs _) = Nothing
10691071destNid (NamedSend _ _) = Nothing
1072+destNid (UnreliableSend _ _) = Nothing
10701073-- We don't need to forward 'Died' signals; if monitoring/linking is setup,
10711074-- then when a local process dies the monitoring/linking machinery will take
10721075-- care of notifying remote nodes