Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
zeromq3-haskell-0.1.3 on GHC 7.4.1
cabal-dev/
dist/

Compiled as-is with GHC 7.4.1, this code runs as expected. However, if the -threaded option is added to both ghc-options lines in test.cabal, both executables die with

*** Exception: ZMQError { errno = 38, source = "getIntOpt", message =
"Socket operation on non-socket" }

The same error is raised if the main functions from server.hs and client.hs are run side-by-side in two ghci sessions.

This code runs as expected in all three cases when compiled under GHC 7.0.4.

Progress: Under 7.4.1, if -threaded -rtsopts is added to both ghc-options lines, and the executables are run with +RTS -VO -RTS, the code runs as expected. The -V0 flag disables the RTS clock.

{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Concurrent (threadDelay)
import Data.Text (append, pack)
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
import System.ZMQ3
-- hello world zeromq example client
main :: IO ()
main = withContext 1 $ \c -> withSocket c Req act
act :: (Receiver a, Sender a) => Socket a -> IO ()
act sock = do
connect sock "tcp://localhost:5555"
flip mapM_ ([1..10] :: [Int]) $ \i -> do
let msg = pack $ show i
send sock [] (encodeUtf8 msg)
putStrLn $ show $ "Sent " `append` msg
receive sock >>= putStrLn . show . ("Received " `append`) . decodeUtf8
threadDelay 1000000
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Prelude hiding (init)
import Control.Exception (bracket)
import Control.Monad (forever)
import Data.Text (append)
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
import System.ZMQ3
-- hello world zeromq example server
-- works
--main :: IO ()
--main = withContext 1 $ \c -> withSocket c Rep act
-- works
--main :: IO ()
--main = bracket (init 1) term $ \c -> bracket (socket c Rep) close act
-- doesn't work
main :: IO ()
main = do
c <- init 1
s <- socket c Rep
act s
close s
term c
act :: (Receiver a, Sender a) => Socket a -> IO ()
act sock = do
bind sock "tcp://*:5555"
forever $ do
receive sock >>= putStrLn . show . ("Received " `append`) . decodeUtf8
send sock [] $ encodeUtf8 msg
putStrLn $ show $ "Sent " `append` msg
where
msg = "Hello!"
name: test
version: 0.0.0
cabal-version: >= 1.6
build-type: Simple
executable server
main-is: server.hs
ghc-options: -Wall
build-depends:
base >= 4 && < 5,
text >= 0.11 && < 0.12,
zeromq3-haskell == 0.1.3
executable server_t
main-is: server.hs
ghc-options: -Wall -threaded
build-depends:
base >= 4 && < 5,
text >= 0.11 && < 0.12,
zeromq3-haskell == 0.1.3
executable client
main-is: client.hs
ghc-options: -Wall
build-depends:
base >= 4 && < 5,
text >= 0.11 && < 0.12,
zeromq3-haskell == 0.1.3
executable client_t
main-is: client.hs
ghc-options: -Wall -threaded
build-depends:
base >= 4 && < 5,
text >= 0.11 && < 0.12,
zeromq3-haskell == 0.1.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.