{-# LANGUAGE ForeignFunctionInterface, DeriveDataTypeable #-}
module Nanomsg.Binary
(
Pair(..)
, Req(..)
, Rep(..)
, Pub(..)
, Sub(..)
, Surveyor(..)
, Respondent(..)
, Push(..)
, Pull(..)
, Bus(..)
, Socket
, Endpoint
, NNException
, SocketType
, Sender
, Receiver
, socket
, withSocket
, bind
, connect
, send
, recv
, recv'
, subscribe
, unsubscribe
, shutdown
, close
, term
, linger
, setLinger
, sndBuf
, setSndBuf
, rcvBuf
, setRcvBuf
, reconnectInterval
, setReconnectInterval
, reconnectIntervalMax
, setReconnectIntervalMax
, sndPrio
, setSndPrio
, ipv4Only
, setIpv4Only
, requestResendInterval
, setRequestResendInterval
, surveyorDeadline
, setSurveyorDeadline
, tcpNoDelay
, setTcpNoDelay
) where
import Control.Applicative
import Nanomsg hiding (send,recv,recv')
import qualified Nanomsg as NM
import Data.Binary
import Data.ByteString.Lazy
send
:: (Sender s, Binary dat)
=> Socket s
-> dat
-> IO ()
send s d = NM.send s (toStrict . encode $ d)
recv
:: (Receiver s, Binary dat)
=> Socket s
-> IO dat
recv s = decode . fromStrict <$> NM.recv s
recv'
:: (Receiver s, Binary dat)
=> Socket s
-> IO (Maybe dat)
recv' s = fmap (decode . fromStrict) <$> NM.recv' s