git.iko.soy/distributed-process
on master help sign in
Allow 0 sized messages.
commitbb650cd79ef44553bc128ee32e90aa98158cad9f authorNicolas Wu <nick@well-typed.com> dateMon 30 Jan 2012, 14:46 (15 years ago) parent9af622f
3 files changed+15−15
benchmarks/PingTCP.hs+7−7 benchmarks/PingTransport.hs+5−5 network-transport/src/Network/Transport/TCP.hs+3−3
benchmarks/PingTCP.hs+7−7
@@ -68,21 +68,21 @@ main = do
6868 -- benchmark the pings
6969 withArgs args' $ defaultMain [ benchPing sock pings ]
7070
71−-- | Each `ping` sends a single `Int64`, and expects to receive one
71+-- | Each `ping` sends a single byte, and expects to receive one
7272-- back in return.
73−ping :: Socket -> Int64 -> IO Int64
74−ping sock n = do
75− NBS.send sock $ encode n
76− bs <- NBS.recv sock 8
73+ping :: Socket -> IO Word8
74+ping sock = do
75+ NBS.send sock $ encode (0 :: Word8)
76+ bs <- NBS.recv sock 1
7777 return $ decode bs
7878
7979pong :: Socket -> IO ()
8080pong sock = do
81− bs <- NBS.recv sock 8
81+ bs <- NBS.recv sock 1
8282 NBS.sendAll sock bs
8383 return ()
8484
8585benchPing :: Socket -> Int64 -> Benchmark
8686benchPing sock n = bench "TCP Ping" $
87− nfIO (mapM_ (ping sock) [1 .. n])
87+ nfIO (replicateM_ (fromIntegral n) (ping sock))
8888
benchmarks/PingTransport.hs+5−5
@@ -3,7 +3,7 @@ module Main where
33import Network.Transport
44import Network.Transport.TCP (mkTransport, TCPConfig (..))
55
6−import Control.Monad (forever)
6+import Control.Monad (forever, replicateM_)
77import Criterion.Main (Benchmark, bench, defaultMain, nfIO)
88import Data.Binary
99import Data.Maybe (fromJust)
@@ -77,9 +77,9 @@ pong targetEndPing sourceEndPong = do
7777-- | The effect of `ping sourceEndPing targetEndPong n` is to send the number
7878-- `n` using `sourceEndPing`, and to then receive the a number from
7979-- `targetEndPong`, which is then returned.
80−ping :: SourceEnd -> TargetEnd -> Int64 -> IO Int64
81−ping sourceEndPing targetEndPong n = do
82− send sourceEndPing [encode n]
80+ping :: SourceEnd -> TargetEnd -> IO Int64
81+ping sourceEndPing targetEndPong = do
82+ send sourceEndPing [BS.empty]
8383 [bs] <- receive targetEndPong
8484 return $ decode bs
8585
@@ -88,5 +88,5 @@ ping sourceEndPing targetEndPong n = do
8888-- taken is benchmarked.
8989benchPing :: SourceEnd -> TargetEnd -> Int64 -> Benchmark
9090benchPing sourceEndPing targetEndPong n = bench "Transport Ping" $
91− nfIO (mapM_ (ping sourceEndPing targetEndPong) [1 .. n])
91+ nfIO (replicateM_ (fromIntegral n) (ping sourceEndPing targetEndPong))
9292
network-transport/src/Network/Transport/TCP.hs+3−3
@@ -100,11 +100,11 @@ mkSourceEnd host service chanId = withSocketsDo $ do
100100 return SourceEnd
101101 { send = \bss -> do
102102 let size = fromIntegral (sum . map BS.length $ bss) :: Int64
103− if size <= fromIntegral (maxBound :: Word8)
103+ if size < 255
104104 then
105105 NBS.sendAll sock (B.encode (fromIntegral size :: Word8))
106106 else do
107− NBS.sendAll sock (B.encode (0 :: Word8))
107+ NBS.sendAll sock (B.encode (255 :: Word8))
108108 NBS.sendAll sock (B.encode size)
109109 mapM_ (NBS.sendAll sock) bss
110110 , closeSourceEnd = sClose sock
@@ -163,7 +163,7 @@ procMessages chans chanId chan sock = do
163163 Nothing -> closeSocket
164164 Just sizeBS -> do
165165 let size = fromIntegral (B.decode sizeBS :: Word8)
166− if size == 0
166+ if size == 255
167167 then do
168168 mSizeBS' <- recvExact sock 8
169169 case mSizeBS' of