File: remote_lat.hs

package info (click to toggle)
haskell-zeromq4-haskell 0.8.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 216 kB
  • sloc: haskell: 1,932; makefile: 21
file content (36 lines) | stat: -rwxr-xr-x 981 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Control.Monad
import System.IO
import System.Exit
import System.Environment
import Data.Time.Clock
import System.ZMQ4.Monadic
import qualified Data.ByteString as SB

main :: IO ()
main = do
    args <- getArgs
    when (length args /= 3) $ do
        hPutStrLn stderr usage
        exitFailure
    let connTo  = args !! 0
        size    = read $ args !! 1
        rounds  = read $ args !! 2
        message = SB.replicate size 0x65
    runZMQ $ do
        s <- socket Req
        connect s connTo
        start <- liftIO $ getCurrentTime
        loop s rounds message
        end <- liftIO $ getCurrentTime
        liftIO $ print (diffUTCTime end start)
  where
    loop s r msg = unless (r <= 0) $ do
        send s [] msg
        msg' <- receive s
        when (SB.length msg' /= SB.length msg) $
            error "message of incorrect size received"
        loop s (r - 1) msg

usage :: String
usage = "usage: remote_lat <connect-to> <message-size> <roundtrip-count>"