1{-# LANGUAGE BangPatterns #-}
2{-# LANGUAGE DeriveDataTypeable #-}
4import System.Environment
6import Control.Applicative
7import Control.Distributed.Process
8import Control.Distributed.Process.Node
9import Network.Transport.TCP (createTransport, defaultTCPParameters, defaultTCPAddr)
11import qualified Data.ByteString.Lazy as BSL
14data SizedList a = SizedList { size :: Int , elems :: [a] }
17instance Binary a => Binary (SizedList a) where
18 put (SizedList sz xs) = put sz >> mapM_ put xs
22 return (SizedList sz xs)
24-- Copied from Data.Binary
25getMany :: Binary a => Int -> Get [a]
28 go xs 0 = return $! reverse xs
30 x `seq` go (x:xs) (i-1)
33nats :: Int -> SizedList Int
34nats = \n -> SizedList n (aux n)
37 aux n = n : aux (n - 1)
42 go :: Int -> Process ()
45 [ match $ \xs -> go (n + size (xs :: SizedList Int))
46 , match $ \them -> send them n >> go 0
49count :: (Int, Int) -> ProcessId -> Process ()
50count (packets, sz) them = do
52 replicateM_ packets $ send them (nats sz)
55 liftIO $ print (packets * sz, n' == packets * sz)
57initialProcess :: String -> Process ()
58initialProcess "SERVER" = do
60 liftIO $ BSL.writeFile "counter.pid" (encode us)
62initialProcess "CLIENT" = do
64 them <- liftIO $ decode <$> BSL.readFile "counter.pid"
69 [role, host, port] <- getArgs
70 trans <- createTransport (defaultTCPAddr host port) defaultTCPParameters
72 Right transport -> do node <- newLocalNode transport initRemoteTable
73 runProcess node $ initialProcess role
74 Left other -> error $ show other
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list