zeromq3-haskell 0.5 → 0.5.1
raw patch · 4 files changed
+19/−11 lines, 4 files
Files
- src/System/ZMQ3/Base.hsc +4/−1
- src/System/ZMQ3/Error.hs +9/−5
- tests/System/ZMQ3/Test/Properties.hs +4/−4
- zeromq3-haskell.cabal +2/−1
src/System/ZMQ3/Base.hsc view
@@ -229,7 +229,10 @@ foreign import ccall unsafe "zmq.h zmq_socket_monitor" c_zmq_socket_monitor :: ZMQSocket -> CString -> CInt -> IO CInt --- error messages+-- errors++foreign import ccall unsafe "zmq.h zmq_errno"+ c_zmq_errno :: IO CInt foreign import ccall unsafe "zmq.h zmq_strerror" c_zmq_strerror :: CInt -> IO CString
src/System/ZMQ3/Error.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE DeriveDataTypeable #-}+ -- We use our own functions for throwing exceptions in order to get -- the actual error message via 'zmq_strerror'. 0MQ defines additional -- error numbers besides those defined by the operating system, so@@ -7,6 +8,7 @@ module System.ZMQ3.Error where import Control.Monad+import Control.Applicative import Control.Exception import Text.Printf import Data.Typeable (Typeable)@@ -20,8 +22,8 @@ -- | ZMQError encapsulates information about errors, which occur -- when using the native 0MQ API, such as error number and message.-data ZMQError = ZMQError {- errno :: Int -- ^ Error number value.+data ZMQError = ZMQError+ { errno :: Int -- ^ Error number value. , source :: String -- ^ Source where this error originates from. , message :: String -- ^ Actual error message. } deriving (Eq, Ord, Typeable)@@ -34,7 +36,7 @@ throwError :: String -> IO a throwError src = do- (Errno e) <- getErrno+ (Errno e) <- zmqErrno msg <- zmqErrnoMessage e throwIO $ ZMQError (fromIntegral e) src msg @@ -49,7 +51,7 @@ throwIfRetry :: (a -> Bool) -> String -> IO a -> IO a throwIfRetry p src act = do r <- act- if p r then getErrno >>= k else return r+ if p r then zmqErrno >>= k else return r where k e | e == eINTR = throwIfRetry p src act | otherwise = throwError src@@ -75,7 +77,7 @@ throwIfRetryMayBlock :: (a -> Bool) -> String -> IO a -> IO b -> IO a throwIfRetryMayBlock p src f on_block = do r <- f- if p r then getErrno >>= k else return r+ if p r then zmqErrno >>= k else return r where k e | e == eINTR = throwIfRetryMayBlock p src f on_block | e == eWOULDBLOCK || e == eAGAIN = on_block >> throwIfRetryMayBlock p src f on_block@@ -93,3 +95,5 @@ zmqErrnoMessage :: CInt -> IO String zmqErrnoMessage e = c_zmq_strerror e >>= peekCString +zmqErrno :: IO Errno+zmqErrno = Errno <$> c_zmq_errno
tests/System/ZMQ3/Test/Properties.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-orphans #-}+ module System.ZMQ3.Test.Properties where import Test.QuickCheck@@ -8,12 +9,12 @@ import Test.Tools import Control.Applicative+import Control.Concurrent.Async (wait) import Data.Int import Data.Word import Data.Restricted import Data.Maybe (fromJust) import Data.ByteString (ByteString)-import Control.Concurrent import System.ZMQ3.Monadic import System.Posix.Types (Fd(..)) import qualified Data.ByteString as SB@@ -104,12 +105,11 @@ msg' <- run $ runZMQ $ do sender <- socket a receiver <- socket b- sync <- liftIO newEmptyMVar bind receiver "inproc://endpoint"- async $ receive receiver >>= liftIO . putMVar sync+ x <- async $ receive receiver connect sender "inproc://endpoint" send sender [] msg- liftIO $ takeMVar sync+ liftIO $ wait x assert (msg == msg') prop_pub_sub :: (SocketType a, Subscriber b, SocketType b, Sender a, Receiver b) => a -> b -> ByteString -> Property
zeromq3-haskell.cabal view
@@ -1,5 +1,5 @@ name: zeromq3-haskell-version: 0.5+version: 0.5.1 synopsis: Bindings to ZeroMQ 3.x category: System, FFI license: MIT@@ -59,6 +59,7 @@ other-modules: Test.Tools build-depends: zeromq3-haskell , base >= 3 && < 5+ , async , containers , bytestring , transformers