git.iko.soy/distributed-process
on master help sign in
Implement unsafeUSend.
222beb5Facundo Domínguez
src/Control/Distributed/Process.hs+2
@@ -40,6 +40,7 @@ module Control.Distributed.Process
40 , mergePortsRR
40 , mergePortsRR
41 -- * Unsafe messaging variants
41 -- * Unsafe messaging variants
42 , unsafeSend
42 , unsafeSend
43+ , unsafeUSend
43 , unsafeSendChan
44 , unsafeSendChan
44 , unsafeNSend
45 , unsafeNSend
45 , unsafeWrapMessage
46 , unsafeWrapMessage
@@ -212,6 +213,7 @@ import Control.Distributed.Process.Internal.Primitives
212 , mergePortsBiased
213 , mergePortsBiased
213 , mergePortsRR
214 , mergePortsRR
214 , unsafeSend
215 , unsafeSend
216+ , unsafeUSend
215 , unsafeSendChan
217 , unsafeSendChan
216 , unsafeNSend
218 , unsafeNSend
217 -- Advanced messaging
219 -- Advanced messaging
src/Control/Distributed/Process/Internal/Primitives.hs+8
@@ -23,6 +23,7 @@ module Control.Distributed.Process.Internal.Primitives
23 , mergePortsRR
23 , mergePortsRR
24 -- * Unsafe messaging variants
24 -- * Unsafe messaging variants
25 , unsafeSend
25 , unsafeSend
26+ , unsafeUSend
26 , unsafeSendChan
27 , unsafeSendChan
27 , unsafeNSend
28 , unsafeNSend
28 -- * Advanced messaging
29 -- * Advanced messaging
@@ -279,6 +280,13 @@ usend them msg = do
279 else sendCtrlMsg (Just there) $ UnreliableSend (processLocalId them)
280 else sendCtrlMsg (Just there) $ UnreliableSend (processLocalId them)
280 (createMessage msg)
281 (createMessage msg)
281
282
283+-- | /Unsafe/ variant of 'usend'. This function makes /no/ attempt to serialize
284+-- the message when the destination process resides on the same local
285+-- node. Therefore, a local receiver would need to be prepared to cope with any
286+-- errors resulting from evaluation of the message.
287+unsafeUSend :: Serializable a => ProcessId -> a -> Process ()
288+unsafeUSend = Unsafe.usend
289+
282-- | Wait for a message of a specific type
290-- | Wait for a message of a specific type
283expect :: forall a. Serializable a => Process a
291expect :: forall a. Serializable a => Process a
284expect = receiveWait [match return]
292expect = receiveWait [match return]
src/Control/Distributed/Process/UnsafePrimitives.hs+21
@@ -45,6 +45,7 @@ module Control.Distributed.Process.UnsafePrimitives
45 send
45 send
46 , sendChan
46 , sendChan
47 , nsend
47 , nsend
48+ , usend
48 , wrapMessage
49 , wrapMessage
49 ) where
50 ) where
50
51
@@ -65,6 +66,7 @@ import Control.Distributed.Process.Internal.Types
65 , ImplicitReconnect(..)
66 , ImplicitReconnect(..)
66 , SendPortId(..)
67 , SendPortId(..)
67 , Message
68 , Message
69+ , createMessage
68 , sendPortProcessId
70 , sendPortProcessId
69 , unsafeCreateUnencodedMessage
71 , unsafeCreateUnencodedMessage
70 )
72 )
@@ -96,6 +98,25 @@ send them msg = do
96 unsafeSendLocal pid msg' =
98 unsafeSendLocal pid msg' =
97 sendCtrlMsg Nothing $ LocalSend pid (unsafeCreateUnencodedMessage msg')
99 sendCtrlMsg Nothing $ LocalSend pid (unsafeCreateUnencodedMessage msg')
98
100
101+-- | Send a message unreliably.
102+--
103+-- Unlike 'send', this function is insensitive to 'reconnect'. It will
104+-- try to send the message regardless of the history of connection failures
105+-- between the nodes.
106+--
107+-- Message passing with 'usend' is ordered for a given sender and receiver
108+-- if the messages arrive at all.
109+--
110+usend :: Serializable a => ProcessId -> a -> Process ()
111+usend them msg = do
112+ proc <- ask
113+ let there = processNodeId them
114+ if localNodeId (processNode proc) == there
115+ then sendCtrlMsg Nothing $
116+ LocalSend them (unsafeCreateUnencodedMessage msg)
117+ else sendCtrlMsg (Just there) $ UnreliableSend (processLocalId them)
118+ (createMessage msg)
119+
99-- | Send a message on a typed channel
120-- | Send a message on a typed channel
100sendChan :: Serializable a => SendPort a -> a -> Process ()
121sendChan :: Serializable a => SendPort a -> a -> Process ()
101sendChan (SendPort cid) msg = do
122sendChan (SendPort cid) msg = do