packages feed

wai-websockets 3.0.0.8 → 3.0.0.9

raw patch · 3 files changed

+22/−17 lines, 3 files

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## 3.0.0.9++* Clean up stream resources when websockets completes [#549](https://github.com/yesodweb/wai/pull/549)+ ## 3.0.0.8  * Support wai 3.2
Network/Wai/Handler/WebSockets.hs view
@@ -7,6 +7,7 @@     , runWebSockets     ) where +import              Control.Exception               (bracket) import              Data.ByteString                 (ByteString) import qualified    Data.ByteString.Char8           as BC import qualified    Data.ByteString.Lazy            as BL@@ -94,20 +95,20 @@               -> IO ByteString               -> (ByteString -> IO ())               -> IO a-runWebSockets opts req app src sink = do-    stream <- WS.makeStream-        (do-            bs <- src-            return $ if BC.null bs then Nothing else Just bs)-        (\mbBl -> case mbBl of-            Nothing -> return ()-            Just bl -> mapM_ sink (BL.toChunks bl))--    let pc = WS.PendingConnection-                { WS.pendingOptions     = opts-                , WS.pendingRequest     = req-                , WS.pendingOnAccept    = \_ -> return ()-                , WS.pendingStream      = stream-                }+runWebSockets opts req app src sink = bracket mkStream WS.close (app . pc)+  where+    mkStream =+        WS.makeStream+            (do+                bs <- src+                return $ if BC.null bs then Nothing else Just bs)+            (\mbBl -> case mbBl of+                Nothing -> return ()+                Just bl -> mapM_ sink (BL.toChunks bl)) -    app pc+    pc stream = WS.PendingConnection+        { WS.pendingOptions     = opts+        , WS.pendingRequest     = req+        , WS.pendingOnAccept    = \_ -> return ()+        , WS.pendingStream      = stream+        }
wai-websockets.cabal view
@@ -1,5 +1,5 @@ Name:                wai-websockets-Version:             3.0.0.8+Version:             3.0.0.9 Synopsis:            Provide a bridge between WAI and the websockets package. License:             MIT License-file:        LICENSE