git.iko.soy/distributed-process
on master help sign in
Ping example now works
commitd2ec55d98c84a0b3698370d7d95e481d5ca38400 authorEdsko de Vries <edsko@edsko.net> dateThu 7 Jun 2012, 10:19 (14 years ago) parentdc0681b
3 files changed+12−8
distributed-process/src/Control/Distributed/Process.hs+1 distributed-process/src/Control/Distributed/Process/Internal/CQueue.hs+4−4 distributed-process/tests/TestCH.hs+7−4
distributed-process/src/Control/Distributed/Process.hs+1
@@ -193,6 +193,7 @@ handleIncomingMessages node = go [] IntMap.empty
193193 Just proc -> do
194194 let msg = payloadToMessage payload
195195 enqueue (processQueue proc) msg
196+ go halfOpenConns openConns
196197 Nothing -> if cid `elem` halfOpenConns
197198 then do
198199 let pid = NTI.decodeInt32 . BSS.concat $ payload
distributed-process/src/Control/Distributed/Process/Internal/CQueue.hs+4−4
@@ -26,14 +26,14 @@ dequeueMatching (CQueue arrived incoming) matches =
2626 modifyMVar arrived (checkArrived [])
2727 where
2828 checkArrived :: [a] -> [a] -> IO ([a], a)
29− checkArrived xs' [] = checkIncomming xs'
29+ checkArrived xs' [] = checkIncoming xs'
3030 checkArrived xs' (x:xs)
3131 | matches x = return (reverse xs' ++ xs, x)
3232 | otherwise = checkArrived (x:xs') xs
3333
34− checkIncomming :: [a] -> IO ([a], a)
35− checkIncomming xs' = do
34+ checkIncoming :: [a] -> IO ([a], a)
35+ checkIncoming xs' = do
3636 x <- readChan incoming
3737 if matches x
3838 then return (reverse xs', x)
39− else checkIncomming (x:xs')
39+ else checkIncoming (x:xs')
distributed-process/tests/TestCH.hs+7−4
@@ -9,7 +9,6 @@ import Control.Concurrent.MVar ( newEmptyMVar
99 , readMVar
1010 )
1111import Control.Monad (replicateM_)
12−import Control.Monad.IO.Class (liftIO)
1312import Control.Distributed.Process
1413import Network.Transport.TCP (createTransport, defaultTCPParameters)
1514
@@ -44,15 +43,19 @@ testPing = do
4443 localNode <- newLocalNode transport
4544 pingServer <- readMVar serverAddr
4645
46+ let numPings = 10000
47+
4748 runProcess localNode $ do
4849 pid <- getSelfPid
49− replicateM_ 10 $ do
50+ replicateM_ numPings $ do
5051 send pingServer (Pong pid)
51− msg@(Ping _) <- expect
52− liftIO $ print msg
52+ Ping _ <- expect
53+ return ()
5354
55+ putStrLn $ "Client did " ++ show numPings ++ " pings"
5456 putMVar clientDone ()
5557
58+
5659 takeMVar clientDone
5760
5861main :: IO ()