pipes-network 0.4.0.2 → 0.5.0.0
raw patch · 4 files changed
+6/−338 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Control.Proxy.TCP.Safe.Sync: Receive :: Int -> Request t
- Control.Proxy.TCP.Safe.Sync: Received :: ByteString -> Response
- Control.Proxy.TCP.Safe.Sync: Send :: t -> Request t
- Control.Proxy.TCP.Safe.Sync: Sent :: Response
- Control.Proxy.TCP.Safe.Sync: data Request t
- Control.Proxy.TCP.Safe.Sync: data Response
- Control.Proxy.TCP.Safe.Sync: socketSyncProxy :: Proxy p => Maybe Int -> Socket -> Request a' -> (ExceptionP p) a' ByteString (Request a') Response SafeIO ()
- Control.Proxy.TCP.Safe.Sync: socketSyncServer :: Proxy p => Maybe Int -> Socket -> Request ByteString -> Server (ExceptionP p) (Request ByteString) Response SafeIO ()
- Control.Proxy.TCP.Safe.Sync: syncDelimit :: (Monad m, Proxy p) => Int -> ByteString -> b' -> p (Request b') Response b' ByteString m r
- Control.Proxy.TCP.Sync: Receive :: Int -> Request t
- Control.Proxy.TCP.Sync: Received :: ByteString -> Response
- Control.Proxy.TCP.Sync: Send :: t -> Request t
- Control.Proxy.TCP.Sync: Sent :: Response
- Control.Proxy.TCP.Sync: data Request t
- Control.Proxy.TCP.Sync: data Response
- Control.Proxy.TCP.Sync: instance Eq Response
- Control.Proxy.TCP.Sync: instance Eq t => Eq (Request t)
- Control.Proxy.TCP.Sync: instance Read Response
- Control.Proxy.TCP.Sync: instance Read t => Read (Request t)
- Control.Proxy.TCP.Sync: instance Show Response
- Control.Proxy.TCP.Sync: instance Show t => Show (Request t)
- Control.Proxy.TCP.Sync: socketSyncProxy :: Proxy p => Socket -> Request a' -> p a' ByteString (Request a') Response IO ()
- Control.Proxy.TCP.Sync: socketSyncProxyTimeout :: Proxy p => Int -> Socket -> Request a' -> (EitherP Timeout p) a' ByteString (Request a') Response IO ()
- Control.Proxy.TCP.Sync: socketSyncServer :: Proxy p => Socket -> Request ByteString -> Server p (Request ByteString) Response IO ()
- Control.Proxy.TCP.Sync: socketSyncServerTimeout :: Proxy p => Int -> Socket -> Request ByteString -> Server (EitherP Timeout p) (Request ByteString) Response IO ()
- Control.Proxy.TCP.Sync: syncDelimit :: (Monad m, Proxy p) => Int -> ByteString -> b' -> p (Request b') Response b' ByteString m r
Files
- NEWS +5/−0
- pipes-network.cabal +1/−3
- src/Control/Proxy/TCP/Safe/Sync.hs +0/−127
- src/Control/Proxy/TCP/Sync.hs +0/−208
NEWS view
@@ -1,3 +1,8 @@+# Version 0.5.0.0++ * Removed `Control.Proxy.TCP.Sync` and `Control.Proxy.TCP.Safe.Sync`.++ # Version 0.4.0.1 * FIX: `acceptFork` now properly closes the connection socket, even in
pipes-network.cabal view
@@ -1,5 +1,5 @@ name: pipes-network-version: 0.4.0.2+version: 0.5.0.0 license: BSD3 license-file: LICENSE copyright: Copyright (c) Renzo Carbonara 2012-2013, Paolo Capriotti 2012-2012.@@ -46,9 +46,7 @@ transformers (>=0.2 && <0.4) exposed-modules: Control.Proxy.TCP- Control.Proxy.TCP.Sync Control.Proxy.TCP.Safe- Control.Proxy.TCP.Safe.Sync other-modules: Control.Proxy.Network.Internal ghc-options: -Wall -fno-warn-unused-do-bind
− src/Control/Proxy/TCP/Safe/Sync.hs
@@ -1,127 +0,0 @@--- | This module exports 'P.Proxy's that allow implementing synchronous RPC-like--- communication with a remote end by using a simple protocol on their--- downstream interface.------ As opposed to the similar proxies found in "Control.Proxy.TCP.Sync",--- these use the exception handling facilities provided by 'P.ExceptionP'.------ You may prefer the more general proxies from--- "Control.Proxy.TCP.Safe".--module Control.Proxy.TCP.Safe.Sync (- -- * Socket proxies- socketSyncServer,- socketSyncProxy,- -- * RPC support- syncDelimit,- -- * Protocol- Request(..),- Response(..),- ) where--import qualified Control.Proxy as P-import Control.Proxy.TCP.Sync (Request(..), Response(..),- syncDelimit)-import Control.Proxy.Network.Internal-import qualified Control.Proxy.Safe as P-import qualified Data.ByteString as B-import Data.Monoid-import qualified Network.Socket as NS-import System.Timeout (timeout)----- | 'P.Server' able to send and receive bytes through a 'NS.Socket'.------ If downstream requests @'Send' bytes@, then such @bytes@ are sent to the--- remote end and then this proxy responds 'Sent' downstream.------ If downstream requests @'Receive' num@, then at most @num@ bytes are received--- from the remote end. This proxy then responds downstream such received--- bytes as @'Received' bytes@. Less than the specified maximum number of bytes--- might be received at once.------ If an optional timeout is given and interactions with the remote end--- take more time that such timeout, then throw a 'Timeout' exception in--- the 'P.ExceptionP' proxy transformer.------ This proxy returns if EOF is received or the remote end closes its side of--- the connection while we are trying to read from it.-socketSyncServer- :: P.Proxy p- => Maybe Int -- ^Optional timeout in microseconds (1/10^6 seconds).- -> NS.Socket -- ^Connected socket.- -> Request B.ByteString- -> P.Server (P.ExceptionP p) (Request B.ByteString) Response P.SafeIO ()-socketSyncServer Nothing sock = loop where- loop (Send bs) = do- P.tryIO (send sock bs)- P.respond Sent >>= loop- loop (Receive nbytes) = do- mbs <- P.tryIO (recv sock nbytes)- case mbs of- Just bs -> P.respond (Received bs) >>= loop- Nothing -> return ()-socketSyncServer (Just wait) sock = loop where- loop (Send bs) = do- m <- P.tryIO (timeout wait (send sock bs))- case m of- Just () -> P.respond Sent >>= loop- Nothing -> P.throw ex- loop (Receive nbytes) = do- mmbs <- P.tryIO (timeout wait (recv sock nbytes))- case mmbs of- Just (Just bs) -> P.respond (Received bs) >>= loop- Just Nothing -> return ()- Nothing -> P.throw ex- ex = Timeout $ "socketSyncServer: " <> show wait <> " microseconds."-{-# INLINABLE socketSyncServer #-}---- | 'P.Proxy' able to send and receive bytes through a 'NS.Socket'.------ If downstream requests @'Send' a'@, then such @a'@ request is forwarded--- upstream, which in return responds a 'B.ByteString' that this proxy sends to--- the remote end. After sending to the remote end, this proxy responds 'Sent'--- downstream.------ If downstream requests @'Receive' num@, then at most @num@ bytes are received--- from the remote end. This proxy then responds downstream such received--- bytes as @'Received' bytes@. Less than the specified maximum number of bytes--- might be received at once.------ If an optional timeout is given and interactions with the remote end--- take more time that such timeout, then throw a 'Timeout' exception in--- the 'P.ExceptionP' proxy transformer.------ This proxy returns if EOF is received or the remote end closes its side of--- the connection while we are trying to read from it.-socketSyncProxy- :: P.Proxy p- => Maybe Int -- ^Optional timeout in microseconds (1/10^6 seconds).- -> NS.Socket -- ^Connected socket.- -> Request a'- -> (P.ExceptionP p) a' B.ByteString (Request a') Response P.SafeIO ()-socketSyncProxy Nothing sock = loop where- loop (Send a') = do- P.tryIO . send sock =<< P.request a'- P.respond Sent >>= loop- loop (Receive nbytes) = do- mbs <- P.tryIO (recv sock nbytes)- case mbs of- Just bs -> P.respond (Received bs) >>= loop- Nothing -> return ()-socketSyncProxy (Just wait) sock = loop where- loop (Send a') = do- m <- P.tryIO . timeout wait . send sock =<< P.request a'- case m of- Just () -> P.respond Sent >>= loop- Nothing -> P.throw ex- loop (Receive nbytes) = do- mmbs <- P.tryIO (timeout wait (recv sock nbytes))- case mmbs of- Just (Just bs) -> P.respond (Received bs) >>= loop- Just Nothing -> return ()- Nothing -> P.throw ex- ex = Timeout $ "socketSyncProxy: " <> show wait <> " microseconds."-{-# INLINABLE socketSyncProxy #-}--
− src/Control/Proxy/TCP/Sync.hs
@@ -1,208 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}---- | This module exports 'P.Proxy's that allow implementing synchronous RPC-like--- communication with a remote end by using a simple protocol on their--- downstream interface.------ As opposed to the similar proxies found in--- "Control.Proxy.TCP.Safe.Sync", these don't use the exception handling--- facilities provided by 'P.ExceptionP'.------ You may prefer the more general and efficient proxies from--- "Control.Proxy.TCP".--module Control.Proxy.TCP.Sync (- -- * Socket proxies- socketSyncServer,- socketSyncProxy,- -- ** Timeouts- -- $timeouts- socketSyncServerTimeout,- socketSyncProxyTimeout,- -- * RPC support- syncDelimit,- -- * Protocol types- Request(..),- Response(..),- ) where--import Control.Monad.Trans.Class-import qualified Control.Proxy as P-import Control.Proxy.Network.Internal-import qualified Control.Proxy.Trans.Either as PE-import qualified Data.ByteString.Char8 as B-import Data.Monoid-import qualified Network.Socket as NS-import System.Timeout (timeout)----- | A request made to one of the @socketSync*@ proxies.-data Request t = Send t | Receive Int- deriving (Eq, Read, Show)---- | A response received from one of the @socketSync*@ proxies.-data Response = Sent | Received B.ByteString- deriving (Eq, Read, Show)-------------------------------------------------------------------------------------- | 'P.Server' able to send and receive bytes through a 'NS.Socket'.------ If downstream requests @'Send' bytes@, then such @bytes@ are sent to the--- remote end and then this proxy responds 'Sent' downstream.------ If downstream requests @'Receive' num@, then at most @num@ bytes are received--- from the remote end. This proxy then responds downstream such received--- bytes as @'Received' bytes@. Less than the specified maximum number of bytes--- might be received at once.------ This proxy returns if EOF is received or the remote end closes its side of--- the connection while we are trying to read from it.-socketSyncServer- :: P.Proxy p- => NS.Socket -- ^Connected socket.- -> Request B.ByteString- -> P.Server p (Request B.ByteString) Response IO ()-socketSyncServer sock = P.runIdentityK loop where- loop (Send bs) = do- lift (send sock bs)- P.respond Sent >>= loop- loop (Receive nbytes) = do- mbs <- lift (recv sock nbytes)- case mbs of- Just bs -> P.respond (Received bs) >>= loop- Nothing -> return ()-{-# INLINABLE socketSyncServer #-}---- | 'P.Proxy' able to send and receive bytes through a 'NS.Socket'.------ If downstream requests @'Send' a'@, then such @a'@ request is forwarded--- upstream, which in return responds a 'B.ByteString' that this proxy sends to--- the remote end. After sending to the remote end, this proxy responds 'Sent'--- downstream.------ If downstream requests @'Receive' num@, then at most @num@ bytes are received--- from the remote end. This proxy then responds downstream such received--- bytes as @'Received' bytes@. Less than the specified maximum number of bytes--- might be received at once.------ This proxy returns if EOF is received or the remote end closes its side of--- the connection while we are trying to read from it.-socketSyncProxy- :: P.Proxy p- => NS.Socket -- ^Connected socket.- -> Request a'- -> p a' B.ByteString (Request a') Response IO ()-socketSyncProxy sock = P.runIdentityK loop where- loop (Send a') = do- lift . send sock =<< P.request a'- P.respond Sent >>= loop- loop (Receive nbytes) = do- mbs <- lift (recv sock nbytes)- case mbs of- Just bs -> P.respond (Received bs) >>= loop- Nothing -> return ()-{-# INLINABLE socketSyncProxy #-}-------------------------------------------------------------------------------------- $timeouts------ These proxies behave like the similarly named ones above, except support for--- timing out the interaction with the remote end is added.---- | Like 'socketSyncServer', except it throws a 'Timeout' exception in the--- 'PE.EitherP' proxy transformer if interacting with the remote end takes--- more time than specified.-socketSyncServerTimeout- :: P.Proxy p- => Int -- ^Timeout in microseconds (1/10^6 seconds).- -> NS.Socket -- ^Connected socket.- -> Request B.ByteString- -> P.Server (PE.EitherP Timeout p) (Request B.ByteString) Response IO ()-socketSyncServerTimeout wait sock = loop where- loop (Send bs) = do- m <- lift (timeout wait (send sock bs))- case m of- Just () -> P.respond Sent >>= loop- Nothing -> PE.throw ex- loop (Receive nbytes) = do- mmbs <- lift (timeout wait (recv sock nbytes))- case mmbs of- Just (Just bs) -> P.respond (Received bs) >>= loop- Just Nothing -> return ()- Nothing -> PE.throw ex- ex = Timeout $ "socketSyncServerTimeout: " <> show wait <> " microseconds."-{-# INLINABLE socketSyncServerTimeout #-}---- | Like 'socketSyncProxy', except it throws a 'Timeout' exception in the--- 'PE.EitherP' proxy transformer if interacting with the remote end takes--- more time than specified.-socketSyncProxyTimeout- :: P.Proxy p- => Int -- ^Timeout in microseconds (1/10^6 seconds).- -> NS.Socket -- ^Connected socket.- -> Request a'- -> (PE.EitherP Timeout p) a' B.ByteString (Request a') Response IO ()-socketSyncProxyTimeout wait sock = loop where- loop (Send a') = do- m <- lift . timeout wait . send sock =<< P.request a'- case m of- Just () -> P.respond Sent >>= loop- Nothing -> PE.throw ex- loop (Receive nbytes) = do- mmbs <- lift (timeout wait (recv sock nbytes))- case mmbs of- Just (Just bs) -> P.respond (Received bs) >>= loop- Just Nothing -> return ()- Nothing -> PE.throw ex- ex = Timeout $ "socketSyncProxyTimeout: " <> show wait <> " microseconds."-{-# INLINABLE socketSyncProxyTimeout #-}-------------------------------------------------------------------------------------- | When used together with one of the @socketSync*@ proxies upstream, this--- proxy sends a single 'B.ByteString' to the remote end and then repeatedly--- receives bytes from the remote end until the given delimiter is found.--- Finally, a single 'B.ByteString' up to the given delimiter (inclusive) is--- sent downstream and then the whole process is repeated.------ This proxy works cooperatively with any @socketSync*@ proxy immediately--- upstream, so read their documentation to understand the purpose of the--- @b'@ value received from downstream.------ For example, if you'd like to convert a 'NS.Socket' into an synchronous--- line-oriented RPC client implemented as a 'P.Server' in which RPC calls are--- received via the downstream interface and RPC responses are sent downstream,--- then you could use this proxy as:------ > socketSyncServer ... >-> syncDelimit 4096 "\r\n"------ Otherwise, if you'd like to convert a 'NS.Socket' into an synchronous--- line-oriented RPC client implemented as a 'P.Proxy' in which RPC calls are--- received via the upstream interface and RPC responses are sent downstream,--- then you could use this proxy as:------ > socketSyncProxy ... >-> syncDelimit 4096 "\r\n"-syncDelimit- :: (Monad m, P.Proxy p)- => Int -- ^Maximum number of bytes to receive at once.- -> B.ByteString -- ^Delimiting bytes.- -> b'-> p (Request b') Response b' B.ByteString m r-syncDelimit nbytes delim b' =- -- XXX this implementation might be inefficient.- P.runIdentityP $ use =<< more mempty (Send b')- where- more buf req = do- a <- P.request req- case a of- Received bs -> return (buf <> bs)- Sent -> more buf (Receive nbytes)- use buf = do- let (pre,suf) = B.breakSubstring delim buf- case B.length suf of- 0 -> use =<< more buf (Receive nbytes)- _ -> do b'2 <- P.respond (pre <> delim)- use =<< more (B.drop (B.length delim) suf) (Send b'2)-{-# INLINABLE syncDelimit #-}-