With the below function is based on the 0MQ Haskell bindings. I get an error at runtime. The error says getIntOpt: interrupted (Interrupted system call) and the program stops.
It probably has to do something with command line options that I use and then discard because of criterion?
Edit: found out that I get the error also when I leave my own code with cmdArgs away.
There is actually a much more interesting problem behind. See last paragraph here. But I have still no clue how to deal with it effectively.
sendReceive :: B.ByteString -> IO ()
sendReceive datastring = withContext 1 $ \context -> do
withSocket context Req $ \requester -> do
--putStrLn "Connecting ..."
connect requester "tcp://192.168.35.84:5559"
let tryOnePing (!c, !f) i = do
send requester datastring []
--putStrLn "Sent ..."
r <- receive requester []
--putStrLn "Received ..."
return $ case B.unpack r of
datastring -> (c+1, f)
_ -> (c, f+1)
(c,f) <- foldM tryOnePing (0,0) [1 .. 1000]
-- c and f are not used in this example
return ()
main = do
n <- cmdArgsRun strlen
let datastring = B.pack (take (byte n) $ randomRs ('a','z') (mkStdGen 3))
putStrLn "Starting..."
withArgs [] $ defaultMain [bench "sendReceive" $ whnfIO (sendReceive datastring)]
The bindings use the FFI helper function
throwErrnoIfMinus1_, which throws an error fromerrnoif the wrapped function returns-1. The new zeromq library expects the caller to properly handlerEINTR, which isn’t happening here.You could ask the library maintainer to use
throwErrnoIfMinus1Retry_, which retries the wrapped function automatically if it returns-1anderrnois set toEINTR.It looks like you can catch the
IOException, but I don’t know how to get at the value oferrno, even though it is stored within it (unless you want to importGHC.IO.Exception, which seems a it shady to me).