zeromq-haskell 0.1.2 → 0.2
raw patch · 4 files changed
+31/−8 lines, 4 files
Files
- README +2/−1
- src/System/ZMQ.hs +25/−3
- src/System/ZMQ/Base.hsc +2/−2
- zeromq-haskell.cabal +2/−2
README view
@@ -3,7 +3,7 @@ · Current status -Version 0.1 - This software currently has *alpha* status, i.e. it had+Version 0.2 - This software currently has *alpha* status, i.e. it had only seen very limited testing and changes to its API might happen. This software was developed and tested on Linux 2.6.31 with GHC-6.12.1@@ -30,6 +30,7 @@ - bind - connect - send+- send' - flush - receive - poll
src/System/ZMQ.hs view
@@ -43,6 +43,7 @@ bind, connect, send,+ send', flush, receive, @@ -52,6 +53,7 @@ import Prelude hiding (init) import Control.Applicative+import Control.Monad (foldM_) import Control.Exception import Data.Int import Data.Maybe@@ -62,6 +64,7 @@ import Foreign.C.String import Foreign.C.Types (CInt, CShort) import qualified Data.ByteString as SB+import qualified Data.ByteString.Lazy as LB import qualified Data.ByteString.Unsafe as UB import System.Posix.Types (Fd(..)) @@ -336,11 +339,18 @@ connect (Socket s) str = throwErrnoIfMinus1_ "connect" $ withCString str (c_zmq_connect s) --- | Send the given 'ByteString' over the socket (zmq_send).+-- | Send the given 'SB.ByteString' over the socket (zmq_send). send :: Socket a -> SB.ByteString -> [Flag] -> IO () send (Socket s) val fls = bracket (messageOf val) messageClose $ \m -> throwErrnoIfMinus1_ "send" $ c_zmq_send s (msgPtr m) (combine fls) +-- | Send the given 'LB.ByteString' over the socket (zmq_send).+-- This is operationally identical to @send socket (Strict.concat+-- (Lazy.toChunks lbs)) flags@ but may be more efficient.+send' :: Socket a -> LB.ByteString -> [Flag] -> IO ()+send' (Socket s) val fls = bracket (messageOfLazy val) messageClose $ \m ->+ throwErrnoIfMinus1_ "send'" $ c_zmq_send s (msgPtr m) (combine fls)+ -- | Flush the given socket (useful for 'send's with 'NoFlush'). flush :: Socket a -> IO () flush = throwErrnoIfMinus1_ "flush" . c_zmq_flush . sock@@ -348,7 +358,7 @@ -- | Receive a 'ByteString' from socket (zmq_recv). receive :: Socket a -> [Flag] -> IO (SB.ByteString) receive (Socket s) fls = bracket messageInit messageClose $ \m -> do- throwErrnoIfMinus1_ "receive" $ c_zmq_recv s (msgPtr m) (combine fls)+ throwErrnoIfMinus1Retry_ "receive" $ c_zmq_recv s (msgPtr m) (combine fls) data_ptr <- c_zmq_msg_data (msgPtr m) size <- c_zmq_msg_size (msgPtr m) SB.packCStringLen (data_ptr, fromIntegral size)@@ -360,7 +370,7 @@ let len = length fds ps = map createZMQPoll fds withArray ps $ \ptr -> do- throwErrnoIfMinus1_ "poll" $+ throwErrnoIfMinus1Retry_ "poll" $ c_zmq_poll ptr (fromIntegral len) (fromIntegral to) ps' <- peekArray len ptr createPoll ps' []@@ -405,6 +415,18 @@ data_ptr <- c_zmq_msg_data (msgPtr msg) copyBytes data_ptr cstr len return msg++messageOfLazy :: LB.ByteString -> IO Message+messageOfLazy lbs = do+ msg <- messageInitSize (fromIntegral len)+ data_ptr <- c_zmq_msg_data (msgPtr msg)+ let fn offset bs = UB.unsafeUseAsCStringLen bs $ \(cstr, str_len) -> do+ copyBytes (data_ptr `plusPtr` offset) cstr str_len+ return (offset + str_len)+ foldM_ fn 0 (LB.toChunks lbs)+ return msg+ where+ len = LB.length lbs messageClose :: Message -> IO () messageClose (Message ptr) = do
src/System/ZMQ/Base.hsc view
@@ -155,11 +155,11 @@ foreign import ccall unsafe "zmq.h zmq_flush" c_zmq_flush :: ZMQSocket -> IO CInt -foreign import ccall unsafe "zmq.h zmq_recv"+foreign import ccall safe "zmq.h zmq_recv" c_zmq_recv :: ZMQSocket -> ZMQMsgPtr -> CInt -> IO CInt -- poll -foreign import ccall unsafe "zmq.h zmq_poll"+foreign import ccall safe "zmq.h zmq_poll" c_zmq_poll :: ZMQPollPtr -> CInt -> CLong -> IO CInt
zeromq-haskell.cabal view
@@ -1,5 +1,5 @@ name: zeromq-haskell-version: 0.1.2+version: 0.2 synopsis: bindings to zeromq description: Bindings to zeromq (http://zeromq.org) category: System, FFI@@ -7,7 +7,7 @@ license-file: LICENSE author: Toralf Wittner maintainer: toralf.wittner@gmail.com-copyright: Copyright (c) 2010 Toralf Wittner+copyright: Copyright (c) 2010 Toralf Wittner, David Himmelstrup homepage: http://github.com/twittner/zeromq-haskell/ stability: experimental tested-With: GHC == 6.12.1