git.iko.soy/distributed-process
on master help sign in
Replace SendEnd/SourceEnd ReceiveEnd/TargetEnd.
commit9c55ac5204b8def89a5811d21dac05ef2a1fbda0 authorNicolas Wu <nick@well-typed.com> dateWed 11 Jan 2012, 13:17 (15 years ago) parent7370446
6 files changed+148−148
distributed-process/src/Control/Distributed/Process.hs+11−11 examples/DemoTCP.hs+35−35 examples/DemoTransport.hs+35−35 network-transport/src/Network/Transport.hs+41−41 network-transport/src/Network/Transport/MVar.hs+12−12 network-transport/src/Network/Transport/TCP.hs+14−14
distributed-process/src/Control/Distributed/Process.hs+11−11
@@ -45,12 +45,12 @@ import Debug.Trace
4545-- Cloud Haskell layer
4646--
4747
48−data NodeId = NodeId -- !Trans.SendEnd !Trans.SendEnd
48+data NodeId = NodeId -- !Trans.SourceEnd !Trans.SourceEnd
4949
50−data ProcessId = ProcessId !Trans.SendEnd !NodeId !LocalProcessId
50+data ProcessId = ProcessId !Trans.SourceEnd !NodeId !LocalProcessId
5151type LocalProcessId = Int
5252
53−newtype SendPort a = SendPort Trans.SendEnd
53+newtype SourcePort a = SourcePort Trans.SourceEnd
5454
5555newtype Process a = Process { unProcess :: ProcessState -> IO a }
5656
@@ -81,7 +81,7 @@ getSelfPid = prPid <$> getProcessState
8181--
8282data ProcessState = ProcessState {
8383 prPid :: !ProcessId,
84− prChan :: !Trans.ReceiveEnd,
84+ prChan :: !Trans.TargetEnd,
8585 prQueue :: !(CQueue Message),
8686 prNode :: !LocalNode
8787 }
@@ -124,10 +124,10 @@ runProcess node proc = do
124124-- returns the ProcessId when the new process has been created.
125125forkProcess :: LocalNode -> Process () -> IO ProcessId
126126forkProcess node (Process action) = do
127− (sendAddr, chan) <- Trans.newConnection (ndTransport node)
128− sendEnd <- Trans.connect sendAddr
127+ (sourceAddr, chan) <- Trans.newConnection (ndTransport node)
128+ sourceEnd <- Trans.connect sourceAddr
129129 processTable@(ProcessTable lpid _) <- takeMVar (ndProcessTable node)
130− let pid = ProcessId sendEnd NodeId lpid
130+ let pid = ProcessId sourceEnd NodeId lpid
131131 _ <- forkIO $ do
132132 tid <- myThreadId
133133 putMVar (ndProcessTable node) (insertProcess tid processTable)
@@ -142,7 +142,7 @@ forkProcess node (Process action) = do
142142 let pte = ProcessTableEntry tid
143143 in ProcessTable (nextPid+1) (IntMap.insert nextPid pte table)
144144
145− receiverPump :: Trans.ReceiveEnd -> CQueue Message -> IO ()
145+ receiverPump :: Trans.TargetEnd -> CQueue Message -> IO ()
146146 receiverPump chan queue = forever $ do
147147 msgBlobs <- Trans.receive chan
148148 readBlobs (concatMap BS.unpack msgBlobs)
@@ -179,9 +179,9 @@ spawnLocal proc = do
179179send :: Serializable a -> ProcessId -> a -> Process ()
180180expect :: Serializable a -> Process a
181181
182−newChan :: Serializable a => Process (SendPort a, ReceivePort a)
183−sendChan :: Serializable a => SendPort a -> a -> Process ()
184−receiveChan :: Serializable a => ReceivePort a -> Process a
182+newChan :: Serializable a => Process (SourcePort a, TargetPort a)
183+sendChan :: Serializable a => SourcePort a -> a -> Process ()
184+receiveChan :: Serializable a => TargetPort a -> Process a
185185
186186spawn :: NodeId -> Closure (Process ()) -> Process ProcessId
187187terminate :: ProcessM a
examples/DemoTCP.hs+35−35
@@ -25,7 +25,7 @@ type ChanId = Int
2525-- ./DemoTCP 127.0.0.1 8082
2626--
2727-- Once the connection is established, the slaves will provide the master
28−-- with their SendAddr. The master then decodes this, and sends a message
28+-- with their SourceAddr. The master then decodes this, and sends a message
2929-- back. After processing this message, the slaves respond to the master,
3030-- which then outputs some data.
3131main :: IO ()
@@ -34,71 +34,71 @@ main = do
3434 case args of
3535 -- Master:
3636 -- The master only provides the host, service, and slaves to expect.
37− [host, service, sendAddrFilePath, number] -> do
37+ [host, service, sourceAddrFilePath, number] -> do
3838 let numSlaves = read number
3939 transport <- mkTransport $ TCPConfig defaultHints host service
40− (clientSendEnds, masterReceiveEnd) <- demoMaster transport sendAddrFilePath numSlaves
40+ (clientSourceEnds, masterTargetEnd) <- demoMaster transport sourceAddrFilePath numSlaves
4141 zipWithM_
42− (\clientSendEnd clientId -> send clientSendEnd [BS.pack . show $ clientId])
43− clientSendEnds [0 .. numSlaves-1]
42+ (\clientSourceEnd clientId -> send clientSourceEnd [BS.pack . show $ clientId])
43+ clientSourceEnds [0 .. numSlaves-1]
4444 replicateM_ numSlaves $ do
45− [clientMessage] <- receive masterReceiveEnd
45+ [clientMessage] <- receive masterTargetEnd
4646 print clientMessage
4747
4848 -- Slave:
4949 -- Each slave provides its own host and service, as well as details of
5050 -- the master it wishes to connect to.
51− [host, service, sendAddrFilePath] -> do
51+ [host, service, sourceAddrFilePath] -> do
5252 transport <- mkTransport $ TCPConfig defaultHints host service
53− (masterSendEnd, slaveReceiveEnd) <- demoSlave transport sendAddrFilePath
54− [clientId] <- receive slaveReceiveEnd
53+ (masterSourceEnd, slaveTargetEnd) <- demoSlave transport sourceAddrFilePath
54+ [clientId] <- receive slaveTargetEnd
5555 putStrLn $ "slave: received clientId: " ++ show clientId
5656 let message = "Connected to slave: " ++ BS.unpack clientId
5757
58− send masterSendEnd [BS.pack message]
58+ send masterSourceEnd [BS.pack message]
5959 putStrLn "slave: sent message to master"
6060
6161 _ -> error "Unexpected arguments"
6262
6363demoMaster :: Transport -- ^ Transport
64− -> FilePath -- ^ File to write SendAddr
64+ -> FilePath -- ^ File to write SourceAddr
6565 -> Int -- ^ Number of slaves to expect
66− -> IO ([SendEnd], ReceiveEnd)
67−demoMaster transport sendAddrFilePath numSlaves = do
66+ -> IO ([SourceEnd], TargetEnd)
67+demoMaster transport sourceAddrFilePath numSlaves = do
6868 -- Establish an initial transport
69− (sendAddr, receiveEnd) <- newConnection transport
69+ (sourceAddr, targetEnd) <- newConnection transport
7070
71− -- Write a file containing the sendAddr
72− putStrLn $ "master: writing sendAddr file:" ++ (show . serialize $ sendAddr)
73− BS.writeFile sendAddrFilePath $ serialize sendAddr
71+ -- Write a file containing the sourceAddr
72+ putStrLn $ "master: writing sourceAddr file:" ++ (show . serialize $ sourceAddr)
73+ BS.writeFile sourceAddrFilePath $ serialize sourceAddr
7474
75− -- Deserialize each of the sendEnds received by the slaves
76− sendEnds <- replicateM numSlaves $ do
77− [bytes] <- receive receiveEnd
75+ -- Deserialize each of the sourceEnds received by the slaves
76+ sourceEnds <- replicateM numSlaves $ do
77+ [bytes] <- receive targetEnd
7878 putStrLn "master: received connection."
7979 case deserialize transport bytes of
8080 Nothing -> fail "Garbage message from slave!"
81− Just sendAddr -> connect sendAddr
82− return (sendEnds, receiveEnd)
81+ Just sourceAddr -> connect sourceAddr
82+ return (sourceEnds, targetEnd)
8383
8484demoSlave :: Transport -- ^ Transport
85− -> FilePath -- ^ File to read SendAddr
86− -> IO (SendEnd, ReceiveEnd)
87−demoSlave transport masterSendAddrFilePath = do
85+ -> FilePath -- ^ File to read SourceAddr
86+ -> IO (SourceEnd, TargetEnd)
87+demoSlave transport masterSourceAddrFilePath = do
8888 -- Create a new connection on the transport
89− (sendAddr, receiveEnd) <- newConnection transport
89+ (sourceAddr, targetEnd) <- newConnection transport
9090
9191 -- Establish connection with the master
92− bytes <- BS.readFile masterSendAddrFilePath
92+ bytes <- BS.readFile masterSourceAddrFilePath
9393 case deserialize transport bytes of
94− Just masterSendAddr -> do
95− putStrLn $ "slave: connecting to sendAddr: " ++ (show . serialize $ masterSendAddr)
96− masterSendEnd <- connect masterSendAddr
94+ Just masterSourceAddr -> do
95+ putStrLn $ "slave: connecting to sourceAddr: " ++ (show . serialize $ masterSourceAddr)
96+ masterSourceEnd <- connect masterSourceAddr
9797
98− -- Send the serialized address of this slave
99− send masterSendEnd [serialize sendAddr]
100− putStrLn "slave: sent sendAddr"
101− return (masterSendEnd, receiveEnd)
98+ -- Source the serialized address of this slave
99+ send masterSourceEnd [serialize sourceAddr]
100+ putStrLn "slave: sent sourceAddr"
101+ return (masterSourceEnd, targetEnd)
102102
103− Nothing -> error "slave: Unable to deserialize master SendAddr!"
103+ Nothing -> error "slave: Unable to deserialize master SourceAddr!"
104104
examples/DemoTransport.hs+35−35
@@ -20,14 +20,14 @@ demo0 :: IO ()
2020demo0 = do
2121 trans <- mkTransport $ TCPConfig undefined "127.0.0.1" "8080"
2222
23− (sendAddr, receiveEnd) <- newConnection trans
23+ (sourceAddr, targetEnd) <- newConnection trans
2424
25− forkIO $ logServer "logServer" receiveEnd
25+ forkIO $ logServer "logServer" targetEnd
2626 threadDelay 100000
2727
28− sendEnd <- connect sendAddr
28+ sourceEnd <- connect sourceAddr
2929
30− mapM_ (\n -> send sendEnd [BS.pack ("hello " ++ show n)]) [1 .. 10]
30+ mapM_ (\n -> send sourceEnd [BS.pack ("hello " ++ show n)]) [1 .. 10]
3131 threadDelay 100000
3232
3333-- | Check endpoint serialization and deserialization.
@@ -36,19 +36,19 @@ demo1 = do
3636 -- trans <- mkTransport
3737 trans <- mkTransport $ TCPConfig undefined "127.0.0.1" "8080"
3838
39− (sendAddr, receiveEnd) <- newConnection trans
39+ (sourceAddr, targetEnd) <- newConnection trans
4040
41− forkIO $ logServer "logServer" receiveEnd
41+ forkIO $ logServer "logServer" targetEnd
4242 threadDelay 100000
4343
44− sendEnd <- connect sendAddr
44+ sourceEnd <- connect sourceAddr
4545
4646 -- This use of Just is slightly naughty
47− let Just sendAddr' = deserialize trans (serialize sendAddr)
48− sendEnd' <- connect sendAddr'
47+ let Just sourceAddr' = deserialize trans (serialize sourceAddr)
48+ sourceEnd' <- connect sourceAddr'
4949
50− send sendEnd [BS.pack "hello 1"]
51− send sendEnd' [BS.pack "hello 2"]
50+ send sourceEnd [BS.pack "hello 1"]
51+ send sourceEnd' [BS.pack "hello 2"]
5252 threadDelay 100000
5353
5454-- | Check that messages can be sent before receive is set up.
@@ -57,13 +57,13 @@ demo2 = do
5757 -- trans <- mkTransport
5858 trans <- mkTransport $ TCPConfig undefined "127.0.0.1" "8080"
5959
60− (sendAddr, receiveEnd) <- newConnection trans
60+ (sourceAddr, targetEnd) <- newConnection trans
6161
62− sendEnd <- connect sendAddr
63− forkIO $ send sendEnd [BS.pack "hello 1"]
62+ sourceEnd <- connect sourceAddr
63+ forkIO $ send sourceEnd [BS.pack "hello 1"]
6464 threadDelay 100000
6565
66− forkIO $ logServer "logServer" receiveEnd
66+ forkIO $ logServer "logServer" targetEnd
6767 return ()
6868
6969-- | Check that two different transports can be created.
@@ -72,17 +72,17 @@ demo3 = do
7272 trans1 <- mkTransport $ TCPConfig undefined "127.0.0.1" "8080"
7373 trans2 <- mkTransport $ TCPConfig undefined "127.0.0.1" "8081"
7474
75− (sendAddr1, receiveEnd1) <- newConnection trans1
76− (sendAddr2, receiveEnd2) <- newConnection trans2
75+ (sourceAddr1, targetEnd1) <- newConnection trans1
76+ (sourceAddr2, targetEnd2) <- newConnection trans2
7777
78− forkIO $ logServer "logServer1" receiveEnd1
79− forkIO $ logServer "logServer2" receiveEnd2
78+ forkIO $ logServer "logServer1" targetEnd1
79+ forkIO $ logServer "logServer2" targetEnd2
8080
81− sendEnd1 <- connect sendAddr1
82− sendEnd2 <- connect sendAddr2
81+ sourceEnd1 <- connect sourceAddr1
82+ sourceEnd2 <- connect sourceAddr2
8383
84− send sendEnd1 [BS.pack "hello1"]
85− send sendEnd2 [BS.pack "hello2"]
84+ send sourceEnd1 [BS.pack "hello1"]
85+ send sourceEnd2 [BS.pack "hello2"]
8686
8787-- | Check that two different connections on the same transport can be created.
8888demo4 :: IO ()
@@ -90,19 +90,19 @@ demo4 = do
9090 trans <- mkTransport $ TCPConfig undefined "127.0.0.1" "8080"
9191 -- trans <- Network.Transport.MVar.mkTransport
9292
93− (sendAddr1, receiveEnd1) <- newConnection trans
94− (sendAddr2, receiveEnd2) <- newConnection trans
93+ (sourceAddr1, targetEnd1) <- newConnection trans
94+ (sourceAddr2, targetEnd2) <- newConnection trans
9595
96− forkIO $ logServer "logServer1" receiveEnd1
97− forkIO $ logServer "logServer2" receiveEnd2
96+ forkIO $ logServer "logServer1" targetEnd1
97+ forkIO $ logServer "logServer2" targetEnd2
9898
99− sendEnd1 <- connect sendAddr1
100− sendEnd2 <- connect sendAddr2
99+ sourceEnd1 <- connect sourceAddr1
100+ sourceEnd2 <- connect sourceAddr2
101101
102− send sendEnd1 [BS.pack "hello1"]
103− send sendEnd2 [BS.pack "hello2"]
102+ send sourceEnd1 [BS.pack "hello1"]
103+ send sourceEnd2 [BS.pack "hello2"]
104104
105−logServer :: String -> ReceiveEnd -> IO ()
106−logServer name receiveEnd = forever $ do
107− x <- receive receiveEnd
108− trace (name ++ ": " ++ show x) $ return ()
105+logServer :: String -> TargetEnd -> IO ()
106+logServer name targetEnd = forever $ do
107+ x <- receive targetEnd
108+ trace (name ++ ": " ++ show x) $ return ()
network-transport/src/Network/Transport.hs+41−41
@@ -1,96 +1,96 @@
11module Network.Transport
22 ( Hints (..)
3− , ReceiveEnd (..)
4− , SendAddr (..)
5− , SendEnd (..)
6− , SendHints (..)
3+ , TargetEnd (..)
4+ , SourceAddr (..)
5+ , SourceEnd (..)
6+ , SourceHints (..)
77 , Transport (..)
88 , connect
99 , defaultHints
10− , defaultSendHints
10+ , defaultSourceHints
1111 , newConnection
1212 , newMulticast
1313 ) where
1414
1515import Data.ByteString.Char8 (ByteString)
1616
17−-- | The `Hints` and `SendHints` provide hints to the underlying transport
17+-- | The `Hints` and `SourceHints` provide hints to the underlying transport
1818-- about the kind of connection that is required. This might include details
1919-- such as whether the connection is eager or buffered, and the buffer size.
2020data Hints = Hints
21−data SendHints = SendHints
21+data SourceHints = SourceHints
2222
2323-- | A `Transport` encapsulates the functions required to establish many-to-one
2424-- and one-to-many connections between clients and servers.
25−-- The `newConnectionWith` function creates a `ReceiveEnd` that listens to
26−-- messages sent using the corresponding `SendAddr`. This connection is
25+-- The `newConnectionWith` function creates a `TargetEnd` that listens to
26+-- messages sent using the corresponding `SourceAddr`. This connection is
2727-- established using a `Hints` value, which provides information about the
2828-- connection topology.
29−-- Each `SendAddr` can be serialised into a `ByteString`, and the `deserialize`
30−-- function converts this back into a `SendAddr`.
29+-- Each `SourceAddr` can be serialised into a `ByteString`, and the `deserialize`
30+-- function converts this back into a `SourceAddr`.
3131-- Note that these connections provide reliable and ordered messages.
3232data Transport = Transport
33− { newConnectionWith :: Hints -> IO (SendAddr, ReceiveEnd)
34− , newMulticastWith :: Hints -> IO (MulticastSendEnd, MulticastReceiveAddr)
35− , deserialize :: ByteString -> Maybe SendAddr
33+ { newConnectionWith :: Hints -> IO (SourceAddr, TargetEnd)
34+ , newMulticastWith :: Hints -> IO (MulticastSourceEnd, MulticastTargetAddr)
35+ , deserialize :: ByteString -> Maybe SourceAddr
3636 }
3737
3838-- | This is a convenience function that creates a new connection on a transport
3939-- using the default hints.
40−newConnection :: Transport -> IO (SendAddr, ReceiveEnd)
40+newConnection :: Transport -> IO (SourceAddr, TargetEnd)
4141newConnection transport = newConnectionWith transport defaultHints
4242
43−newMulticast :: Transport -> IO (MulticastSendEnd, MulticastReceiveAddr)
43+newMulticast :: Transport -> IO (MulticastSourceEnd, MulticastTargetAddr)
4444newMulticast transport = newMulticastWith transport defaultHints
4545
4646-- | The default `Hints` for establishing a new transport connection.
4747defaultHints :: Hints
4848defaultHints = Hints
4949
50−-- | A `SendAddr` is an address that corresponds to a listening `ReceiveEnd`
51−-- initially created using `newConnection`. A `SendAddr` can be shared between
50+-- | A `SourceAddr` is an address that corresponds to a listening `TargetEnd`
51+-- initially created using `newConnection`. A `SourceAddr` can be shared between
5252-- clients by using `serialize`, and passing the resulting `ByteString`.
53−-- Given a `SendAddr`, the `connectWith` function creates a `SendEnd` which
53+-- Given a `SourceAddr`, the `connectWith` function creates a `SourceEnd` which
5454-- can be used to send messages.
55−data SendAddr = SendAddr
56− { connectWith :: SendHints -> IO SendEnd
55+data SourceAddr = SourceAddr
56+ { connectWith :: SourceHints -> IO SourceEnd
5757 , serialize :: ByteString
5858 }
5959
60−-- | This is a convenience function that connects with a given `SendAddr` using
60+-- | This is a convenience function that connects with a given `SourceAddr` using
6161-- the default hints for sending.
62−connect :: SendAddr -> IO SendEnd
63−connect sendAddr = connectWith sendAddr defaultSendHints
62+connect :: SourceAddr -> IO SourceEnd
63+connect sourceAddr = connectWith sourceAddr defaultSourceHints
6464
65−-- | The default `SendHints` for establishing a `SendEnd`.
66−defaultSendHints :: SendHints
67−defaultSendHints = SendHints
65+-- | The default `SourceHints` for establishing a `SourceEnd`.
66+defaultSourceHints :: SourceHints
67+defaultSourceHints = SourceHints
6868
69−-- | A `SendEnd` provides a `send` function that allows vectored messages
70−-- to be sent to the corresponding `ReceiveEnd`.
71−newtype SendEnd = SendEnd
69+-- | A `SourceEnd` provides a `send` function that allows vectored messages
70+-- to be sent to the corresponding `TargetEnd`.
71+newtype SourceEnd = SourceEnd
7272 { send :: [ByteString] -> IO ()
7373 }
7474
75−-- | A `ReceiveEnd` provides a `receive` function that allows messages
76−-- to be received from the corresponding `SendEnd`s.
77−newtype ReceiveEnd = ReceiveEnd
75+-- | A `TargetEnd` provides a `receive` function that allows messages
76+-- to be received from the corresponding `SourceEnd`s.
77+newtype TargetEnd = TargetEnd
7878 { receive :: IO [ByteString]
7979 }
8080
81−newtype MulticastSendEnd = MulticastSendEnd
82− { multicastSend :: ByteString -> IO ()
81+newtype MulticastSourceEnd = MulticastSourceEnd
82+ { multicastSource :: ByteString -> IO ()
8383 }
8484
85−newtype MulticastReceiveAddr = MulticastReceiveAddr
86− { multicastConnect :: IO MulticastReceiveEnd
85+newtype MulticastTargetAddr = MulticastTargetAddr
86+ { multicastConnect :: IO MulticastTargetEnd
8787 }
8888
89−newtype MulticastReceiveEnd = MulticastReceiveEnd
89+newtype MulticastTargetEnd = MulticastTargetEnd
9090 { multicastReceive :: IO ByteString
9191 }
9292
93−-- TODO: Other SendEnds that might be of use:
94−-- data UnorderedSendEnd -- reliable, unordered
95−-- data UnreliableSendEnd -- unreliable, unordered
93+-- TODO: Other SourceEnds that might be of use:
94+-- data UnorderedSourceEnd -- reliable, unordered
95+-- data UnreliableSourceEnd -- unreliable, unordered
9696
network-transport/src/Network/Transport/MVar.hs+12−12
@@ -22,35 +22,35 @@ mkTransport = do
2222 { newConnectionWith = \_ -> do
2323 (i, m) <- takeMVar channels
2424 receiveChan <- newEmptyMVar
25− let sendAddr = i
25+ let sourceAddr = i
2626 !i' = i+1
2727 !m' = IntMap.insert i receiveChan m
2828 putMVar channels (i', m')
29− return (mkSendAddr channels sendAddr, mkReceiveEnd receiveChan)
29+ return (mkSourceAddr channels sourceAddr, mkTargetEnd receiveChan)
3030 , newMulticastWith = undefined
3131 , deserialize = \bs ->
3232 case BS.readInt bs of
33− Nothing -> error "dummyBackend.deserializeSendEnd: cannot parse"
34− Just (n,_) -> Just . mkSendAddr channels $ n
33+ Nothing -> error "dummyBackend.deserializeSourceEnd: cannot parse"
34+ Just (n,_) -> Just . mkSourceAddr channels $ n
3535 }
3636 where
37− mkSendAddr :: Chans -> Int -> SendAddr
38− mkSendAddr channels addr = SendAddr
39− { connectWith = \_ -> mkSendEnd channels addr
37+ mkSourceAddr :: Chans -> Int -> SourceAddr
38+ mkSourceAddr channels addr = SourceAddr
39+ { connectWith = \_ -> mkSourceEnd channels addr
4040 , serialize = BS.pack (show addr)
4141 }
4242
43− mkSendEnd :: Chans -> Int -> IO SendEnd
44− mkSendEnd channels addr = do
43+ mkSourceEnd :: Chans -> Int -> IO SourceEnd
44+ mkSourceEnd channels addr = do
4545 (_, m) <- readMVar channels
4646 case IntMap.lookup addr m of
4747 Nothing -> fail "dummyBackend.send: bad send address"
48− Just chan -> return SendEnd
48+ Just chan -> return SourceEnd
4949 { send = realSend chan
5050 }
5151
52− mkReceiveEnd :: MVar [ByteString] -> ReceiveEnd
53− mkReceiveEnd chan = ReceiveEnd
52+ mkTargetEnd :: MVar [ByteString] -> TargetEnd
53+ mkTargetEnd chan = TargetEnd
5454 { receive = takeMVar chan
5555 }
5656
network-transport/src/Network/Transport/TCP.hs+14−14
@@ -31,8 +31,8 @@ type ChanId = Int
3131data TCPConfig = TCPConfig Hints HostName ServiceName
3232
3333-- | This creates a TCP connection between a server and a number of
34−-- clients. Behind the scenes, the server hostname is passed as the SendAddr
35−-- and when a connection is made, messages sent down the SendEnd go
34+-- clients. Behind the scenes, the server hostname is passed as the SourceAddr
35+-- and when a connection is made, messages sent down the SourceEnd go
3636-- via a socket made for the client that connected.
3737-- Messages are all queued using an unbounded Chan.
3838mkTransport :: TCPConfig -> IO Transport
@@ -55,37 +55,37 @@ mkTransport (TCPConfig _hints host service) = withSocketsDo $ do
5555 (chanId, chanMap) <- takeMVar channels
5656 chan <- newChan
5757 putMVar channels (chanId + 1, IntMap.insert chanId chan chanMap)
58− return (mkSendAddr host service chanId, mkReceiveEnd chan)
58+ return (mkSourceAddr host service chanId, mkTargetEnd chan)
5959 , newMulticastWith = undefined
6060 , deserialize = \bs ->
6161 case readMay . BS.unpack $ bs of
6262 Nothing -> error "deserialize: cannot parse"
63− Just (host, service, chanId) -> Just $ mkSendAddr host service chanId
63+ Just (host, service, chanId) -> Just $ mkSourceAddr host service chanId
6464 }
6565
6666 where
67− mkSendAddr :: HostName -> ServiceName -> ChanId -> SendAddr
68− mkSendAddr host service chanId = SendAddr
69− { connectWith = \_ -> mkSendEnd host service chanId
67+ mkSourceAddr :: HostName -> ServiceName -> ChanId -> SourceAddr
68+ mkSourceAddr host service chanId = SourceAddr
69+ { connectWith = \_ -> mkSourceEnd host service chanId
7070 , serialize = BS.pack . show $ (host, service, chanId)
7171 }
7272
73− mkSendEnd :: HostName -> ServiceName -> ChanId -> IO SendEnd
74− mkSendEnd host service chanId = withSocketsDo $ do
73+ mkSourceEnd :: HostName -> ServiceName -> ChanId -> IO SourceEnd
74+ mkSourceEnd host service chanId = withSocketsDo $ do
7575 serverAddrs <- getAddrInfo Nothing (Just host) (Just service)
7676 let serverAddr = case serverAddrs of
77− [] -> error "mkSendEnd: getAddrInfo returned []"
77+ [] -> error "mkSourceEnd: getAddrInfo returned []"
7878 as -> head as
7979 sock <- socket (addrFamily serverAddr) Stream defaultProtocol
80− setSocketOption sock KeepAlive 1
80+ setSocketOption sock ReuseAddr 1
8181 N.connect sock (addrAddress serverAddr)
8282 NBS.sendAll sock $ BS.pack . show $ chanId
83− return $ SendEnd
83+ return $ SourceEnd
8484 { Network.Transport.send = \bss -> NBS.sendMany sock bss
8585 }
8686
87− mkReceiveEnd :: Chan ByteString -> ReceiveEnd
88− mkReceiveEnd chan = ReceiveEnd
87+ mkTargetEnd :: Chan ByteString -> TargetEnd
88+ mkTargetEnd chan = TargetEnd
8989 { -- for now we will implement this as a Chan
9090 receive = do
9191 bs <- readChan chan