git.iko.soy/distributed-process
on master help sign in
Implement unreliable send (usend).
d126187Facundo Domínguez
src/Control/Distributed/Process.hs+2
@@ -25,6 +25,7 @@ module Control.Distributed.Process
25 , liftIO -- Reexported for convenience
25 , liftIO -- Reexported for convenience
26 -- * Basic messaging
26 -- * Basic messaging
27 , send
27 , send
28+ , usend
28 , expect
29 , expect
29 , expectTimeout
30 , expectTimeout
30 -- * Channels
31 -- * Channels
@@ -195,6 +196,7 @@ import Control.Distributed.Process.Serializable (Serializable)
195import Control.Distributed.Process.Internal.Primitives
196import Control.Distributed.Process.Internal.Primitives
196 ( -- Basic messaging
197 ( -- Basic messaging
197 send
198 send
199+ , usend
198 , expect
200 , expect
199 -- Channels
201 -- Channels
200 , newChan
202 , newChan
src/Control/Distributed/Process/Internal/Primitives.hs+15
@@ -12,6 +12,7 @@
12module Control.Distributed.Process.Internal.Primitives
12module Control.Distributed.Process.Internal.Primitives
13 ( -- * Basic messaging
13 ( -- * Basic messaging
14 send
14 send
15+ , usend
15 , expect
16 , expect
16 -- * Channels
17 -- * Channels
17 , newChan
18 , newChan
@@ -254,6 +255,20 @@ send them msg = do
254unsafeSend :: Serializable a => ProcessId -> a -> Process ()
255unsafeSend :: Serializable a => ProcessId -> a -> Process ()
255unsafeSend = Unsafe.send
256unsafeSend = Unsafe.send
256
257
258+-- | Send a message without any reliability or ordering guarantees.
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+usend :: Serializable a => ProcessId -> a -> Process ()
264+usend them msg = do
265+ here <- getSelfNode
266+ let there = processNodeId them
267+ if here == there
268+ then sendLocal them msg
269+ else sendCtrlMsg (Just there) $ UnreliableSend (processLocalId them)
270+ (createMessage msg)
271+
257-- | Wait for a message of a specific type
272-- | Wait for a message of a specific type
258expect :: forall a. Serializable a => Process a
273expect :: forall a. Serializable a => Process a
259expect = receiveWait [match return]
274expect = receiveWait [match return]
src/Control/Distributed/Process/Internal/Types.hs+3
@@ -571,6 +571,7 @@ data ProcessSignal =
571 | WhereIs !String
571 | WhereIs !String
572 | Register !String !NodeId !(Maybe ProcessId) !Bool -- Use 'Nothing' to unregister, use True to force reregister
572 | Register !String !NodeId !(Maybe ProcessId) !Bool -- Use 'Nothing' to unregister, use True to force reregister
573 | NamedSend !String !Message
573 | NamedSend !String !Message
574+ | UnreliableSend !LocalProcessId !Message
574 | LocalSend !ProcessId !Message
575 | LocalSend !ProcessId !Message
575 | LocalPortSend !SendPortId !Message
576 | LocalPortSend !SendPortId !Message
576 | Kill !ProcessId !String
577 | Kill !ProcessId !String
@@ -626,6 +627,7 @@ instance Binary ProcessSignal where
626 put (Exit pid reason) = putWord8 10 >> put pid >> put (messageToPayload reason)
627 put (Exit pid reason) = putWord8 10 >> put pid >> put (messageToPayload reason)
627 put (LocalSend to' msg) = putWord8 11 >> put to' >> put (messageToPayload msg)
628 put (LocalSend to' msg) = putWord8 11 >> put to' >> put (messageToPayload msg)
628 put (LocalPortSend sid msg) = putWord8 12 >> put sid >> put (messageToPayload msg)
629 put (LocalPortSend sid msg) = putWord8 12 >> put sid >> put (messageToPayload msg)
630+ put (UnreliableSend lpid msg) = putWord8 13 >> put lpid >> put (messageToPayload msg)
629 put (GetInfo about) = putWord8 30 >> put about
631 put (GetInfo about) = putWord8 30 >> put about
630 put (SigShutdown) = putWord8 31
632 put (SigShutdown) = putWord8 31
631 put (GetNodeStats nid) = putWord8 32 >> put nid
633 put (GetNodeStats nid) = putWord8 32 >> put nid
@@ -645,6 +647,7 @@ instance Binary ProcessSignal where
645 10 -> Exit <$> get <*> (payloadToMessage <$> get)
647 10 -> Exit <$> get <*> (payloadToMessage <$> get)
646 11 -> LocalSend <$> get <*> (payloadToMessage <$> get)
648 11 -> LocalSend <$> get <*> (payloadToMessage <$> get)
647 12 -> LocalPortSend <$> get <*> (payloadToMessage <$> get)
649 12 -> LocalPortSend <$> get <*> (payloadToMessage <$> get)
650+ 13 -> UnreliableSend <$> get <*> (payloadToMessage <$> get)
648 30 -> GetInfo <$> get
651 30 -> GetInfo <$> get
649 31 -> return SigShutdown
652 31 -> return SigShutdown
650 32 -> GetNodeStats <$> get
653 32 -> GetNodeStats <$> get
src/Control/Distributed/Process/Node.hs+3
@@ -688,6 +688,8 @@ nodeController = do
688 ncEffectWhereIs from label
688 ncEffectWhereIs from label
689 NCMsg _ (NamedSend label msg') ->
689 NCMsg _ (NamedSend label msg') ->
690 ncEffectNamedSend label msg'
690 ncEffectNamedSend label msg'
691+ NCMsg _ (UnreliableSend lpid msg') ->
692+ ncEffectLocalSend node (ProcessId (localNodeId node) lpid) msg'
691 NCMsg _ (LocalSend to msg') ->
693 NCMsg _ (LocalSend to msg') ->
692 ncEffectLocalSend node to msg'
694 ncEffectLocalSend node to msg'
693 NCMsg _ (LocalPortSend to msg') ->
695 NCMsg _ (LocalPortSend to msg') ->
@@ -1062,6 +1064,7 @@ destNid (Spawn _ _) = Nothing
1062destNid (Register _ _ _ _) = Nothing
1064destNid (Register _ _ _ _) = Nothing
1063destNid (WhereIs _) = Nothing
1065destNid (WhereIs _) = Nothing
1064destNid (NamedSend _ _) = Nothing
1066destNid (NamedSend _ _) = Nothing
1067+destNid (UnreliableSend _ _) = Nothing
1065-- We don't need to forward 'Died' signals; if monitoring/linking is setup,
1068-- We don't need to forward 'Died' signals; if monitoring/linking is setup,
1066-- then when a local process dies the monitoring/linking machinery will take
1069-- then when a local process dies the monitoring/linking machinery will take
1067-- care of notifying remote nodes
1070-- care of notifying remote nodes