websockets-snap 0.8.2.2 → 0.9.0.0
raw patch · 2 files changed
+31/−31 lines, 2 filesdep −blaze-builderdep −io-streamsdep ~websocketsPVP ok
version bump matches the API change (PVP)
Dependencies removed: blaze-builder, io-streams
Dependency ranges changed: websockets
API changes (from Hackage documentation)
Files
- src/Network/WebSockets/Snap.hs +28/−27
- websockets-snap.cabal +3/−4
src/Network/WebSockets/Snap.hs view
@@ -8,8 +8,6 @@ ---------------------------------------------------------------------------------import Blaze.ByteString.Builder (Builder)-import qualified Blaze.ByteString.Builder as Builder import Control.Concurrent (forkIO, myThreadId, threadDelay) import Control.Concurrent.MVar (MVar, newEmptyMVar, putMVar, takeMVar)@@ -27,11 +25,10 @@ import Data.Typeable (Typeable, cast) import qualified Network.WebSockets as WS import qualified Network.WebSockets.Connection as WS+import qualified Network.WebSockets.Stream as WS import qualified Snap.Core as Snap import qualified Snap.Internal.Http.Types as Snap import qualified Snap.Types.Headers as Headers-import System.IO.Streams (InputStream, OutputStream)-import qualified System.IO.Streams as Streams --------------------------------------------------------------------------------@@ -54,9 +51,10 @@ ---------------------------------------------------------------------------------copyIterateeToMVar :: ((Int -> Int) -> IO ())- -> MVar Chunk- -> E.Iteratee ByteString IO ()+copyIterateeToMVar+ :: ((Int -> Int) -> IO ())+ -> MVar Chunk+ -> E.Iteratee ByteString IO () copyIterateeToMVar tickle mvar = E.catchError go handler where go = do@@ -76,8 +74,8 @@ ---------------------------------------------------------------------------------copyMVarToInputStream :: MVar Chunk -> IO (InputStream ByteString)-copyMVarToInputStream mvar = Streams.makeInputStream go+copyMVarToStream :: MVar Chunk -> IO (IO (Maybe ByteString))+copyMVarToStream mvar = return go where go = do chunk <- takeMVar mvar@@ -88,18 +86,19 @@ ---------------------------------------------------------------------------------copyOutputStreamToIteratee :: E.Iteratee ByteString IO ()- -> IO (OutputStream Builder)-copyOutputStreamToIteratee iteratee0 = do+copyStreamToIteratee+ :: E.Iteratee ByteString IO ()+ -> IO (Maybe BL.ByteString -> IO ())+copyStreamToIteratee iteratee0 = do ref <- newIORef =<< E.runIteratee iteratee0- Streams.makeOutputStream (go ref)+ return (go ref) where- go _ Nothing = return ()- go ref (Just bld) = do+ go _ Nothing = return ()+ go ref (Just bl) = do step <- readIORef ref case step of E.Continue f -> do- let chunks = BL.toChunks $ Builder.toLazyByteString bld+ let chunks = BL.toChunks bl step' <- E.runIteratee $ f $ E.Chunks chunks writeIORef ref step' E.Yield () _ -> throw WS.ConnectionClosed@@ -111,26 +110,29 @@ -- continues processing the 'WS.WebSockets' action. The action to be executed -- takes the 'WS.Request' as a parameter, because snap has already read this -- from the socket.-runWebSocketsSnap :: Snap.MonadSnap m- => WS.ServerApp- -> m ()+runWebSocketsSnap+ :: Snap.MonadSnap m+ => WS.ServerApp+ -> m () runWebSocketsSnap = runWebSocketsSnapWith WS.defaultConnectionOptions -------------------------------------------------------------------------------- -- | Variant of 'runWebSocketsSnap' which allows custom options-runWebSocketsSnapWith :: Snap.MonadSnap m- => WS.ConnectionOptions- -> WS.ServerApp- -> m ()+runWebSocketsSnapWith+ :: Snap.MonadSnap m+ => WS.ConnectionOptions+ -> WS.ServerApp+ -> m () runWebSocketsSnapWith options app = do rq <- Snap.getRequest Snap.escapeHttp $ \tickle writeEnd -> do thisThread <- lift myThreadId mvar <- lift newEmptyMVar- is <- lift $ copyMVarToInputStream mvar- os <- lift $ copyOutputStreamToIteratee writeEnd+ parse <- lift $ copyMVarToStream mvar+ write <- lift $ copyStreamToIteratee writeEnd+ stream <- lift $ WS.makeStream parse write let options' = options { WS.connectionOnPong = do@@ -142,8 +144,7 @@ { WS.pendingOptions = options' , WS.pendingRequest = fromSnapRequest rq , WS.pendingOnAccept = forkPingThread tickle- , WS.pendingIn = is- , WS.pendingOut = os+ , WS.pendingStream = stream } _ <- lift $ forkIO $ app pc >> throwTo thisThread ServerAppDone
websockets-snap.cabal view
@@ -1,5 +1,5 @@ Name: websockets-snap-Version: 0.8.2.2+Version: 0.9.0.0 Synopsis: Snap integration for the websockets library Description: Snap integration for the websockets library License: BSD3@@ -15,20 +15,19 @@ Library Hs-source-dirs: src+ Ghc-options: -Wall Exposed-modules: Network.WebSockets.Snap Build-depends: base >= 4 && < 5,- blaze-builder >= 0.3 && < 0.4, bytestring >= 0.9 && < 0.11, enumerator >= 0.4 && < 0.5,- io-streams >= 1.1 && < 1.2, mtl >= 2.1 && < 2.3, snap-core >= 0.8 && < 0.10, snap-server >= 0.8 && < 0.10,- websockets >= 0.8 && < 0.9+ websockets >= 0.9 && < 0.10 Source-repository head Type: git