packages feed

websockets 0.5.0.0 → 0.5.1.0

raw patch · 3 files changed

+21/−18 lines, 3 filesdep +network-enumerator

Dependencies added: network-enumerator

Files

+ src/Network/WebSockets/Internal.hs view
@@ -0,0 +1,8 @@+-- | This module exports some extra functions. However, note that these+-- utilities are primarily meant for internal use, and can change between minor+-- releases.+module Network.WebSockets.Internal+    ( S.iterSocket+    ) where++import qualified Network.WebSockets.Socket as S
src/Network/WebSockets/Socket.hs view
@@ -4,8 +4,7 @@ module Network.WebSockets.Socket     ( runServer     , runWithSocket-    , receiveEnum-    , sendIter+    , iterSocket     ) where  import Prelude hiding (catch)@@ -16,11 +15,12 @@ import Control.Monad.Trans (liftIO)  import Data.ByteString (ByteString)-import Data.Enumerator (Enumerator, Iteratee, (>>==), ($$))+import Data.Enumerator (Iteratee, ($$)) import Network.Socket (Socket) import qualified Data.Enumerator as E import qualified Network.Socket as S import qualified Network.Socket.ByteString as SB+import qualified Network.Socket.Enumerator as SE  import Network.WebSockets.Handshake.Http import Network.WebSockets.Monad@@ -44,7 +44,7 @@     flip catch (closeSock sock) $ forever $ do         (conn, _) <- S.accept sock         -- Voodoo fix: set this to True as soon as we notice the connection was-        -- closed. Will prevent sendIter' from even trying to send anything.+        -- closed. Will prevent iterSocket' from even trying to send anything.         -- Without it, we got many "Couldn't decode text frame as UTF8" errors         -- in the browser (although the payload is definitely UTF8).         -- killRef <- newIORef False@@ -59,22 +59,15 @@ runWithSocket :: Protocol p               => Socket -> (Request -> WebSockets p a) -> IO a runWithSocket s ws = do-    r <- E.run $ receiveEnum s $$-        runWebSocketsWithHandshake defaultWebSocketsOptions ws (sendIter s)+    r <- E.run $ SE.enumSocket 4096 s $$+        runWebSocketsWithHandshake defaultWebSocketsOptions ws (iterSocket s)     S.sClose s     either (error . show) return r --- | Create an enumerator which reads from a socket and yields the chunks-receiveEnum :: Socket -> Enumerator ByteString IO a-receiveEnum s = E.checkContinue0 $ \loop f -> do-    b <- liftIO $ SB.recv s 4096-    if b == ""-        then E.continue f-        else f (E.Chunks [b]) >>== loop---- | Create an iterator which writes to a socket-sendIter :: Socket -> Iteratee ByteString IO ()-sendIter s = E.continue go+-- | Create an iterator which writes to a socket. Throws a 'ConnectionClosed'+-- exception if the user attempts to write to a closed socket.+iterSocket :: Socket -> Iteratee ByteString IO ()+iterSocket s = E.continue go   where     go (E.Chunks []) = E.continue go     go (E.Chunks cs) = do
websockets.cabal view
@@ -1,5 +1,5 @@ Name:    websockets-Version: 0.5.0.0+Version: 0.5.1.0  Synopsis:   A sensible and clean way to write WebSocket-capable servers in Haskell.@@ -45,6 +45,7 @@    Exposed-modules:     Network.WebSockets+    Network.WebSockets.Internal    Other-modules:     Network.WebSockets.Handshake@@ -75,6 +76,7 @@     enumerator               >= 0.4.13 && < 0.5,     mtl                      >= 2.0    && < 2.2,     network                  >= 2.3    && < 2.4,+    network-enumerator       >= 0.1    && < 0.2,     random                   >= 1.0    && < 1.1,     SHA                      >= 1.5    && < 1.6,     text                     >= 0.10   && < 0.12,