git.iko.soy/distributed-process
on master help sign in
Properly remove whereisRemote (fix previous commit)
63bfd19Edsko de Vries
distributed-process/src/Control/Distributed/Process.hs−2
@@ -77,7 +77,6 @@ module Control.Distributed.Process
77 , nsend
77 , nsend
78 , registerRemote
78 , registerRemote
79 , unregisterRemote
79 , unregisterRemote
80− , whereisRemote
81 , whereisRemoteAsync
80 , whereisRemoteAsync
82 , nsendRemote
81 , nsendRemote
83 , WhereIsReply(..)
82 , WhereIsReply(..)
@@ -197,7 +196,6 @@ import Control.Distributed.Process.Internal.Primitives
197 , nsend
196 , nsend
198 , registerRemote
197 , registerRemote
199 , unregisterRemote
198 , unregisterRemote
200− , whereisRemote
201 , whereisRemoteAsync
199 , whereisRemoteAsync
202 , nsendRemote
200 , nsendRemote
203 -- Closures
201 -- Closures
distributed-process/src/Control/Distributed/Process/Internal/Primitives.hs−1
@@ -38,7 +38,6 @@ module Control.Distributed.Process.Internal.Primitives
38 , nsend
38 , nsend
39 , registerRemote
39 , registerRemote
40 , unregisterRemote
40 , unregisterRemote
41− , whereisRemote
42 , whereisRemoteAsync
41 , whereisRemoteAsync
43 , nsendRemote
42 , nsendRemote
44 -- * Closures
43 -- * Closures
distributed-process/src/Control/Distributed/Process/Internal/Types.hs+17
@@ -10,6 +10,8 @@ module Control.Distributed.Process.Internal.Types
10 , ProcessId(..)
10 , ProcessId(..)
11 , Identifier(..)
11 , Identifier(..)
12 , nodeOf
12 , nodeOf
13+ , firstNonReservedProcessId
14+ , nullProcessId
13 -- * Local nodes and processes
15 -- * Local nodes and processes
14 , LocalNode(..)
16 , LocalNode(..)
15 , LocalNodeState(..)
17 , LocalNodeState(..)
@@ -148,6 +150,21 @@ nodeOf (NodeIdentifier nid) = nid
148nodeOf (ProcessIdentifier pid) = processNodeId pid
150nodeOf (ProcessIdentifier pid) = processNodeId pid
149nodeOf (SendPortIdentifier cid) = processNodeId (sendPortProcessId cid)
151nodeOf (SendPortIdentifier cid) = processNodeId (sendPortProcessId cid)
150
152
153+--------------------------------------------------------------------------------
154+-- Special PIDs --
155+--------------------------------------------------------------------------------
156+
157+firstNonReservedProcessId :: Int32
158+firstNonReservedProcessId = 1
159+
160+nullProcessId :: NodeId -> ProcessId
161+nullProcessId nid =
162+ ProcessId { processNodeId = nid
163+ , processLocalId = LocalProcessId { lpidUnique = 0
164+ , lpidCounter = 0
165+ }
166+ }
167+
151--------------------------------------------------------------------------------
168--------------------------------------------------------------------------------
152-- Local nodes and processes --
169-- Local nodes and processes --
153--------------------------------------------------------------------------------
170--------------------------------------------------------------------------------
distributed-process/src/Control/Distributed/Process/Node.hs+3−2
@@ -116,6 +116,7 @@ import Control.Distributed.Process.Internal.Types
116 , payloadToMessage
116 , payloadToMessage
117 , createMessage
117 , createMessage
118 , runLocalProcess
118 , runLocalProcess
119+ , firstNonReservedProcessId
119 )
120 )
120import Control.Distributed.Process.Serializable (Serializable)
121import Control.Distributed.Process.Serializable (Serializable)
121import Control.Distributed.Process.Internal.Messaging
122import Control.Distributed.Process.Internal.Messaging
@@ -151,7 +152,7 @@ createBareLocalNode endPoint rtable = do
151 unq <- randomIO
152 unq <- randomIO
152 state <- newMVar LocalNodeState
153 state <- newMVar LocalNodeState
153 { _localProcesses = Map.empty
154 { _localProcesses = Map.empty
154− , _localPidCounter = 0
155+ , _localPidCounter = firstNonReservedProcessId
155 , _localPidUnique = unq
156 , _localPidUnique = unq
156 , _localConnections = Map.empty
157 , _localConnections = Map.empty
157 }
158 }
@@ -235,7 +236,7 @@ forkProcess node proc = modifyMVar (localState node) startProcess
235 then do
236 then do
236 newUnique <- randomIO
237 newUnique <- randomIO
237 return ( (localProcessWithId lpid ^= Just lproc)
238 return ( (localProcessWithId lpid ^= Just lproc)
238− . (localPidCounter ^= 0)
239+ . (localPidCounter ^= firstNonReservedProcessId)
239 . (localPidUnique ^= newUnique)
240 . (localPidUnique ^= newUnique)
240 $ st
241 $ st
241 , pid
242 , pid
distributed-process/tests/TestCH.hs+8−1
@@ -48,6 +48,13 @@ ping = do
48 send partner (Ping self)
48 send partner (Ping self)
49 ping
49 ping
50
50
51+-- | Quick and dirty synchronous version of whereisRemoteAsync
52+whereisRemote :: NodeId -> String -> Process (Maybe ProcessId)
53+whereisRemote nid string = do
54+ whereisRemoteAsync nid string
55+ WhereIsReply _ mPid <- expect
56+ return mPid
57+
51-- | Basic ping test
58-- | Basic ping test
52testPing :: NT.Transport -> IO ()
59testPing :: NT.Transport -> IO ()
53testPing transport = do
60testPing transport = do
@@ -549,7 +556,7 @@ testRegistry transport = do
549 Ping pid' <- expect
556 Ping pid' <- expect
550 True <- return $ pingServer == pid'
557 True <- return $ pingServer == pid'
551 return ()
558 return ()
552−
559+
553testRemoteRegistry :: NT.Transport -> IO ()
560testRemoteRegistry :: NT.Transport -> IO ()
554testRemoteRegistry transport = do
561testRemoteRegistry transport = do
555 node1 <- newLocalNode transport initRemoteTable
562 node1 <- newLocalNode transport initRemoteTable