public
Created

zeromq3-haskell-0.1.3 on GHC 7.4.1

  • Download Gist
.gitignore
1 2
cabal-dev/
dist/
README.md
Markdown

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.

client.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
{-# 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
server.hs
Haskell
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 37 38 39
{-# 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!"
test.cabal
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
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.