|
|
|
|
@ -8,6 +8,7 @@ module Network.Xmpp.Stream where
@@ -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
@@ -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) |
|
|
|
|
|