packages feed

zeromq3-haskell 0.1.1 → 0.1.2

raw patch · 4 files changed

+31/−4 lines, 4 files

Files

README.md view
@@ -5,6 +5,9 @@  This software currently has *beta* status, i.e. it had seen limited testing. +Version 0.1.2 - Add 'sendMulti' and 'receiveMulti'. Rename 'SndMore' to+                'SendMore'.+ Version 0.1.1 - Include better error message when trying to build against                 invalid 0MQ version. 
src/System/ZMQ3.hs view
@@ -73,7 +73,7 @@     Size   , Context   , Socket-  , Flag (SndMore)+  , Flag (SendMore)   , Timeout   , Event (..) @@ -103,7 +103,9 @@   , connect   , send   , send'+  , sendMulti   , receive+  , receiveMulti   , version    , System.ZMQ3.subscribe@@ -169,6 +171,7 @@ ) where  import Prelude hiding (init)+import qualified Prelude as P import Control.Applicative import Control.Exception import Control.Monad (unless, when)@@ -583,6 +586,15 @@     retry "send'" (waitWrite sock) $           c_zmq_sendmsg s (msgPtr m) (combine (DontWait : fls)) +-- | Send a multi-part message.+-- This function applies the 'SendMore' 'Flag' between all message parts.+-- 0MQ guarantees atomic delivery of a multi-part message+-- (cf. zmq_sendmsg for details).+sendMulti :: Sender a => Socket a -> [SB.ByteString] -> IO ()+sendMulti sock msgs = do+    mapM_ (send sock [SendMore]) (P.init msgs)+    send sock [] (last msgs)+ -- | Receive a 'ByteString' from socket (cf. zmq_recvmsg). -- -- /Note/: This function always calls @zmq_recvmsg@ in a non-blocking way,@@ -597,6 +609,18 @@     data_ptr <- c_zmq_msg_data (msgPtr m)     size     <- c_zmq_msg_size (msgPtr m)     SB.packCStringLen (data_ptr, fromIntegral size)++-- Receive a multi-part message.+-- This function collects all message parts send via 'sendMulti'.+receiveMulti :: Receiver a => Socket a -> IO [SB.ByteString]+receiveMulti sock = recvall []+  where+    recvall acc = do+        msg <- receive sock+        moreToReceive sock >>= next (msg:acc)++    next acc True  = recvall acc+    next acc False = return (reverse acc)  -- Convert bit-masked word into Event. toEvent :: Word32 -> Event
src/System/ZMQ3/Internal.hs view
@@ -49,7 +49,7 @@  -- | Flags to apply on send operations (cf. man zmq_send) data Flag = DontWait -- ^ ZMQ_DONTWAIT-          | SndMore  -- ^ ZMQ_SNDMORE+          | SendMore -- ^ ZMQ_SNDMORE   deriving (Eq, Ord, Show)  -- | A 0MQ context representation.@@ -156,7 +156,7 @@  toZMQFlag :: Flag -> ZMQFlag toZMQFlag DontWait = dontWait-toZMQFlag SndMore = sndMore+toZMQFlag SendMore = sndMore  combine :: [Flag] -> CInt combine = fromIntegral . foldr ((.|.) . flagVal . toZMQFlag) 0
zeromq3-haskell.cabal view
@@ -1,5 +1,5 @@ name:               zeromq3-haskell-version:            0.1.1+version:            0.1.2 synopsis:           Bindings to ZeroMQ 3.x category:           System, FFI license:            MIT