From b6e3f6e044e50bbe9f3a4ee7963a6667bcd9e656 Mon Sep 17 00:00:00 2001 From: Jon Kristensen Date: Mon, 18 Feb 2013 01:41:58 +0100 Subject: [PATCH] Moved `withStream', `withStream\'', and `mkStream' to Stream.hs --- source/Network/Xmpp/Stream.hs | 22 ++++++++++++++++++++++ source/Network/Xmpp/Types.hs | 24 ------------------------ 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/source/Network/Xmpp/Stream.hs b/source/Network/Xmpp/Stream.hs index 8023cb1..3af4e6a 100644 --- a/source/Network/Xmpp/Stream.hs +++ b/source/Network/Xmpp/Stream.hs @@ -8,6 +8,7 @@ module Network.Xmpp.Stream where import Control.Applicative ((<$>), (<*>)) import qualified Control.Exception as Ex +import Control.Exception.Base import Control.Monad.Error import Control.Monad.Reader import Control.Monad.State.Strict @@ -528,3 +529,24 @@ elements = do streamName :: Name streamName = (Name "stream" (Just "http://etherx.jabber.org/streams") (Just "stream")) + +withStream :: StateT Stream IO (Either XmppFailure c) -> TMVar Stream -> IO (Either XmppFailure c) +withStream action stream = bracketOnError + (atomically $ takeTMVar stream) + (atomically . putTMVar stream) + (\s -> do + (r, s') <- runStateT action s + atomically $ putTMVar stream s' + return r + ) + +-- nonblocking version. Changes to the connection are ignored! +withStream' :: StateT Stream IO (Either XmppFailure b) -> TMVar Stream -> IO (Either XmppFailure b) +withStream' action stream = do + stream_ <- atomically $ readTMVar stream + (r, _) <- runStateT action stream_ + return r + + +mkStream :: Stream -> IO (TMVar Stream) +mkStream con = {- Stream `fmap` -} (atomically $ newTMVar con) diff --git a/source/Network/Xmpp/Types.hs b/source/Network/Xmpp/Types.hs index 7b73644..5fd4f41 100644 --- a/source/Network/Xmpp/Types.hs +++ b/source/Network/Xmpp/Types.hs @@ -33,9 +33,6 @@ module Network.Xmpp.Types , Version(..) , StreamHandle(..) , Stream(..) - , withStream - , withStream' - , mkStream , StreamState(..) , StreamErrorInfo(..) , langTag @@ -816,27 +813,6 @@ data Stream = Stream -- the connection is plain. } -withStream :: StateT Stream IO (Either XmppFailure c) -> TMVar Stream -> IO (Either XmppFailure c) -withStream action stream = bracketOnError - (atomically $ takeTMVar stream) - (atomically . putTMVar stream) - (\s -> do - (r, s') <- runStateT action s - atomically $ putTMVar stream s' - return r - ) - --- nonblocking version. Changes to the connection are ignored! -withStream' :: StateT Stream IO (Either XmppFailure b) -> TMVar Stream -> IO (Either XmppFailure b) -withStream' action stream = do - stream_ <- atomically $ readTMVar stream - (r, _) <- runStateT action stream_ - return r - - -mkStream :: Stream -> IO (TMVar Stream) -mkStream con = {- Stream `fmap` -} (atomically $ newTMVar con) - --------------- -- JID ---------------