network-simple-wss 0.1 → 0.2
raw patch · 4 files changed
+53/−21 lines, 4 filesdep +asyncdep ~network-simple-tlsdep ~network-simple-wsdep ~websocketssetup-changedPVP ok
version bump matches the API change (PVP)
Dependencies added: async
Dependency ranges changed: network-simple-tls, network-simple-ws, websockets
API changes (from Hackage documentation)
+ Network.Simple.WSS: clientConnectionFromStream :: MonadIO m => Stream -> HostName -> ServiceName -> ByteString -> [(ByteString, ByteString)] -> m Connection
+ Network.Simple.WSS: close :: MonadIO m => Connection -> Word16 -> ByteString -> m ()
- Network.Simple.WSS: connect :: (MonadIO m, MonadMask m) => ClientSettings -> HostName -> ServiceName -> ByteString -> [(ByteString, ByteString)] -> ((Connection, SockAddr) -> m r) -> m r
+ Network.Simple.WSS: connect :: (MonadIO m, MonadMask m) => ClientParams -> HostName -> ServiceName -> ByteString -> [(ByteString, ByteString)] -> ((Connection, SockAddr) -> m r) -> m r
- Network.Simple.WSS: connectOverSOCKS5 :: (MonadIO m, MonadMask m) => HostName -> ServiceName -> ClientSettings -> HostName -> ServiceName -> ByteString -> [(ByteString, ByteString)] -> ((Connection, SockAddr, SockAddr) -> m r) -> m r
+ Network.Simple.WSS: connectOverSOCKS5 :: (MonadIO m, MonadMask m) => HostName -> ServiceName -> ClientParams -> HostName -> ServiceName -> ByteString -> [(ByteString, ByteString)] -> ((Connection, SockAddr, SockAddr) -> m r) -> m r
- Network.Simple.WSS: recv :: MonadIO m => Connection -> m ByteString
+ Network.Simple.WSS: recv :: MonadIO m => Connection -> m (Either (Word16, ByteString) ByteString)
Files
- Setup.hs +0/−4
- changelog.md +18/−0
- network-simple-wss.cabal +12/−9
- src/Network/Simple/WSS.hs +23/−8
− Setup.hs
@@ -1,4 +0,0 @@-#! /usr/bin/env nix-shell-#! nix-shell ./shell.nix -i runghc-import Distribution.Simple-main = defaultMain
changelog.md view
@@ -1,3 +1,21 @@+# Version 0.2++* /COMPILER ASSISTED BREAKING CHANGE:/ `send` and `recv` now use+ lazy `ByteString`s. ++* /COMPILER ASSISTED BREAKING CHANGE:/ `recv`'s close semantics have + improved. See its documentation for details.++* Re-exported `close` and `clientConnectionFromStream` from + `network-simple-ws`.++* Depend on `network-simple-tls >=0.4`.++* Depend on `network-simple-ws >=0.2`.++* Depend on `websockets >=0.12.6`.++ # Version 0.1 * First release.
network-simple-wss.cabal view
@@ -1,32 +1,35 @@+cabal-version: 2.4 name: network-simple-wss-version: 0.1+version: 0.2 synopsis: Simple interface to TLS secured WebSockets. description: Simple interface to TLS secured WebSockets.-homepage: https://github.com/k0001/network-simple-wss-bug-reports: https://github.com/k0001/network-simple-wss/issues-license: BSD3+homepage: https://hackage.haskell.org/package/network-simple-wss+bug-reports: https://github.com/k0001/network-simple/issues+license: BSD-3-Clause license-file: LICENSE author: Renzo Carbonara maintainer: renλren.zone copyright: Copyright (c) Renzo Carbonara 2018 category: Network build-type: Simple-cabal-version: >=1.8 extra-source-files: README.md changelog.md source-repository head type: git- location: https://github.com/k0001/network-simple-wss+ location: https://github.com/k0001/network-simple+ subdir: network-simple-wss library+ default-language: Haskell2010 hs-source-dirs: src exposed-modules: Network.Simple.WSS ghc-options: -Wall -O2 build-depends:+ async, base >=4.7 && <5.0, bytestring, safe-exceptions,- network-simple-tls >=0.3.2,- network-simple-ws,- websockets+ network-simple-tls >=0.4,+ network-simple-ws >=0.2,+ websockets >=0.12.6
src/Network/Simple/WSS.hs view
@@ -13,17 +13,21 @@ -- intreresting from a client's point of view. Server side support will come -- later. module Network.Simple.WSS- ( W.Connection- , WS.send+ ( -- * Sending and receiving+ WS.Connection , WS.recv+ , WS.send+ , WS.close -- * Client side , connect , connectOverSOCKS5 -- * Low level+ , WS.clientConnectionFromStream , streamFromContext ) where +import qualified Control.Concurrent.Async as Async import Control.Monad.IO.Class (MonadIO, liftIO) import qualified Control.Exception.Safe as Ex import qualified Data.ByteString as B@@ -32,6 +36,7 @@ import qualified Network.Simple.TCP.TLS as T import qualified Network.Simple.WS as WS import qualified Network.WebSockets as W+import qualified Network.WebSockets.Connection as W (pingThread) import qualified Network.WebSockets.Stream as W (Stream, makeStream, close) --------------------------------------------------------------------------------@@ -39,7 +44,7 @@ -- | Connect to the specified Secure WebSockets server. connect :: (MonadIO m, Ex.MonadMask m)- => T.ClientSettings -- ^ TLS settings.+ => T.ClientParams -- ^ TLS settings. -> T.HostName -- ^ Secure WebSockets server host name (e.g., @\"www.example.com\"@ or IP -- address).@@ -60,8 +65,8 @@ T.connect cs hn sn $ \(ctx, saddr) -> do Ex.bracket (streamFromContext ctx) (liftIO . W.close) $ \stream -> do conn <- WS.clientConnectionFromStream stream hn sn res hds- liftIO (W.forkPingThread conn 30)- act (conn, saddr)+ withAsync (W.pingThread conn 30 (pure ())) $ \_ -> + act (conn, saddr) -- | Like 'connect', but connects to the destination server through a SOCKS5 -- proxy.@@ -69,7 +74,7 @@ :: (MonadIO m, Ex.MonadMask m) => T.HostName -- ^ SOCKS5 proxy server hostname or IP address. -> T.ServiceName -- ^ SOCKS5 proxy server service port name or number.- -> T.ClientSettings -- ^ TLS settings.+ -> T.ClientParams -- ^ TLS settings. -> T.HostName -- ^ Destination Secure WebSockets server hostname or IP address. We connect -- to this host /through/ the SOCKS5 proxy specified in the previous@@ -96,8 +101,8 @@ T.connectOverSOCKS5 phn psn tcs dhn dsn $ \(ctx, pa, da) -> do Ex.bracket (streamFromContext ctx) (liftIO . W.close) $ \stream -> do conn <- WS.clientConnectionFromStream stream dhn dsn res hds- liftIO (W.forkPingThread conn 30)- act (conn, pa, da)+ withAsync (W.pingThread conn 30 (pure ())) $ \_ -> + act (conn, pa, da) -- | Obtain a 'W.Stream' implemented using the given TLS 'T.Context'. You can -- use the@@ -106,4 +111,14 @@ streamFromContext :: MonadIO m => T.Context -> m W.Stream streamFromContext ctx = liftIO $ do W.makeStream (T.recv ctx) (traverse_ (T.sendLazy ctx))++-- | Like 'Async.async', but generalized to 'Ex.MonadMask' and 'MonadIO'.+withAsync+ :: (Ex.MonadMask m, MonadIO m) + => IO a + -> (Async.Async a -> m b) + -> m b+withAsync io = Ex.bracket+ (liftIO $ Async.asyncWithUnmask (\u -> u io))+ (liftIO . Async.uninterruptibleCancel)