on master help sign in
Merge pull request #70 from bitonic/master

Stop processing when the iteratee is done in wai-websockets

commit8854576119c676daadc621c30b54d0219ef2ffad authorMichael Snoyman <michael@snoyman.com> dateSat 12 May 2012, 22:50 (14 years ago) parent8149617bd63158
1 file changed+8−1
wai-websockets/Network/Wai/Handler/WebSockets.hs+8−1
wai-websockets/Network/Wai/Handler/WebSockets.hs+8−1
@@ -52,7 +52,10 @@ runWebSockets opts req app source conn = do
5252
5353 push iter bs = do
5454 step <- liftIO $ E.runIteratee $ E.enumList 1 [bs] E.$$ iter
55− return $ C.StateProcessing $ E.returnI step
55+ case step of
56+ E.Continue _ -> return $ C.StateProcessing $ E.returnI step
57+ E.Yield out inp -> return $ C.StateDone (streamToMaybe inp) out
58+ E.Error e -> C.monadThrow e
5659 close iter = do
5760 _ <- liftIO $ E.runIteratee $ E.enumEOF E.$$ iter
5861 return ()
@@ -63,3 +66,7 @@ iterConnection c = E.continue go
6366 go (E.Chunks []) = E.continue go
6467 go (E.Chunks cs) = E.tryIO (Warp.connSendMany c cs) >> E.continue go
6568 go E.EOF = E.continue go
69+
70+streamToMaybe :: E.Stream S.ByteString -> Maybe S.ByteString
71+streamToMaybe E.EOF = Nothing
72+streamToMaybe (E.Chunks bs) = Just $ S.concat bs