Browse Source

Moved `withStream', `withStream\'', and `mkStream' to Stream.hs

master
Jon Kristensen 13 years ago
parent
commit
b6e3f6e044
  1. 22
      source/Network/Xmpp/Stream.hs
  2. 24
      source/Network/Xmpp/Types.hs

22
source/Network/Xmpp/Stream.hs

@ -8,6 +8,7 @@ module Network.Xmpp.Stream where
import Control.Applicative ((<$>), (<*>)) import Control.Applicative ((<$>), (<*>))
import qualified Control.Exception as Ex import qualified Control.Exception as Ex
import Control.Exception.Base
import Control.Monad.Error import Control.Monad.Error
import Control.Monad.Reader import Control.Monad.Reader
import Control.Monad.State.Strict import Control.Monad.State.Strict
@ -528,3 +529,24 @@ elements = do
streamName :: Name streamName :: Name
streamName = (Name "stream" (Just "http://etherx.jabber.org/streams") (Just "stream")) 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)

24
source/Network/Xmpp/Types.hs

@ -33,9 +33,6 @@ module Network.Xmpp.Types
, Version(..) , Version(..)
, StreamHandle(..) , StreamHandle(..)
, Stream(..) , Stream(..)
, withStream
, withStream'
, mkStream
, StreamState(..) , StreamState(..)
, StreamErrorInfo(..) , StreamErrorInfo(..)
, langTag , langTag
@ -816,27 +813,6 @@ data Stream = Stream
-- the connection is plain. -- 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 -- JID
--------------- ---------------

Loading…
Cancel
Save