streaming-commons 0.1.2.4 → 0.1.3
raw patch · 3 files changed
+42/−11 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Data.Streaming.Network: getAddrFamily :: ClientSettings -> Family
+ Data.Streaming.Network: getSocketFamilyGen :: SocketType -> String -> Int -> Family -> IO (Socket, AddrInfo)
+ Data.Streaming.Network: getSocketFamilyTCP :: ByteString -> Int -> Family -> IO (Socket, SockAddr)
+ Data.Streaming.Network: setAddrFamily :: Family -> ClientSettings -> ClientSettings
+ Data.Streaming.Network.Internal: clientAddrFamily :: ClientSettings -> !Family
- Data.Streaming.Network.Internal: ClientSettings :: !Int -> !ByteString -> ClientSettings
+ Data.Streaming.Network.Internal: ClientSettings :: !Int -> !ByteString -> !Family -> ClientSettings
Files
- Data/Streaming/Network.hs +39/−9
- Data/Streaming/Network/Internal.hs +2/−1
- streaming-commons.cabal +1/−1
Data/Streaming/Network.hs view
@@ -33,6 +33,7 @@ -- ** Setters , setPort , setHost+ , setAddrFamily , setAfterBind , setNeedLocalAddr #if !WINDOWS@@ -41,6 +42,7 @@ -- ** Getters , getPort , getHost+ , getAddrFamily , getAfterBind , getNeedLocalAddr #if !WINDOWS@@ -55,6 +57,7 @@ , bindPortGen , bindRandomPortGen , getSocketGen+ , getSocketFamilyGen , acceptSafe , unassignedPorts , getUnassignedPort@@ -62,6 +65,7 @@ , bindPortTCP , bindRandomPortTCP , getSocketTCP+ , getSocketFamilyTCP , safeRecv , runTCPServer , runTCPClient@@ -103,18 +107,25 @@ import Control.Concurrent.MVar (putMVar, takeMVar, newEmptyMVar) #endif --- | Attempt to connect to the given host/port using given @SocketType@.-getSocketGen :: SocketType -> String -> Int -> IO (Socket, AddrInfo)-getSocketGen sockettype host' port' = do+-- | Attempt to connect to the given host/port/address family using given @SocketType@.+--+-- Since 0.1.3+getSocketFamilyGen :: SocketType -> String -> Int -> NS.Family -> IO (Socket, AddrInfo)+getSocketFamilyGen sockettype host' port' af = do let hints = NS.defaultHints { NS.addrFlags = [NS.AI_ADDRCONFIG] , NS.addrSocketType = sockettype+ , NS.addrFamily = af } (addr:_) <- NS.getAddrInfo (Just hints) (Just host') (Just $ show port') sock <- NS.socket (NS.addrFamily addr) (NS.addrSocketType addr) (NS.addrProtocol addr) return (sock, addr) +-- | Attempt to connect to the given host/port using given @SocketType@.+getSocketGen :: SocketType -> String -> Int -> IO (Socket, AddrInfo)+getSocketGen sockettype host port = getSocketFamilyGen sockettype host port NS.AF_UNSPEC+ -- | Attempt to bind a listening @Socket@ on the given host/port using given -- @SocketType@. If no host is given, will use the first address available. bindPortGen :: SocketType -> Int -> HostPreference -> IO Socket@@ -358,12 +369,15 @@ clientSettingsTCP port host = ClientSettings { clientPort = port , clientHost = host+ , clientAddrFamily = NS.AF_UNSPEC } --- | Attempt to connect to the given host/port.-getSocketTCP :: ByteString -> Int -> IO (NS.Socket, NS.SockAddr)-getSocketTCP host' port' = do- (sock, addr) <- getSocketGen NS.Stream (S8.unpack host') port'+-- | Attempt to connect to the given host/port/address family.+--+-- Since 0.1.3+getSocketFamilyTCP :: ByteString -> Int -> NS.Family -> IO (NS.Socket, NS.SockAddr)+getSocketFamilyTCP host' port' addrFamily = do+ (sock, addr) <- getSocketFamilyGen NS.Stream (S8.unpack host') port' addrFamily ee <- try' $ NS.connect sock (NS.addrAddress addr) case ee of Left e -> NS.sClose sock >> throwIO e@@ -372,6 +386,10 @@ try' :: IO a -> IO (Either SomeException a) try' = try +-- | Attempt to connect to the given host/port.+getSocketTCP :: ByteString -> Int -> IO (NS.Socket, NS.SockAddr)+getSocketTCP host port = getSocketFamilyTCP host port NS.AF_UNSPEC+ -- | Attempt to bind a listening @Socket@ on the given host/port. If no host is -- given, will use the first address available. -- 'maxListenQueue' is topically 128 which is too short for@@ -442,6 +460,18 @@ getHost :: ClientSettings -> ByteString getHost = clientHost +-- | Set the address family for the given settings.+--+-- Since 0.1.3+setAddrFamily :: NS.Family -> ClientSettings -> ClientSettings+setAddrFamily af cs = cs { clientAddrFamily = af }++-- | Get the address family for the given settings.+--+-- Since 0.1.3+getAddrFamily :: ClientSettings -> NS.Family+getAddrFamily = clientAddrFamily+ #if !WINDOWS class HasPath a where pathLens :: Functor f => (FilePath -> f FilePath) -> a -> f a@@ -518,8 +548,8 @@ -- | Run an @Application@ by connecting to the specified server. runTCPClient :: ClientSettings -> (AppData -> IO a) -> IO a-runTCPClient (ClientSettings port host) app = E.bracket- (getSocketTCP host port)+runTCPClient (ClientSettings port host addrFamily) app = E.bracket+ (getSocketFamilyTCP host port addrFamily) (NS.sClose . fst) (\(s, address) -> app AppData { appRead' = safeRecv s 4096
Data/Streaming/Network/Internal.hs view
@@ -14,7 +14,7 @@ import Data.String (IsString (..)) import Data.ByteString (ByteString)-import Network.Socket (Socket, SockAddr)+import Network.Socket (Socket, SockAddr, Family) -- | Settings for a TCP server. It takes a port to listen on, and an optional -- hostname to bind to.@@ -30,6 +30,7 @@ data ClientSettings = ClientSettings { clientPort :: !Int , clientHost :: !ByteString+ , clientAddrFamily :: !Family } -- | Which host to bind.
streaming-commons.cabal view
@@ -1,5 +1,5 @@ name: streaming-commons-version: 0.1.2.4+version: 0.1.3 synopsis: Common lower-level functions needed by various streaming data libraries description: Provides low-dependency functionality commonly needed by various streaming data libraries, such as conduit and pipes. homepage: https://github.com/fpco/streaming-commons