Browse Source

documentation clarification and some formatting

master
Jon Kristensen 14 years ago
parent
commit
00ab24c3cb
  1. 30
      source/Network/Xmpp/Concurrent/Monad.hs
  2. 5
      source/Network/Xmpp/Monad.hs

30
source/Network/Xmpp/Concurrent/Monad.hs

@ -235,8 +235,8 @@ setConnectionClosedHandler eh = do
-- | Run an event handler. -- | Run an event handler.
runHandler :: (EventHandlers -> IO a) -> Xmpp a runHandler :: (EventHandlers -> IO a) -> Xmpp a
runHandler h = do runHandler h = do
eh <- liftIO . atomically . readTVar =<< asks eventHandlers eh <- liftIO . atomically . readTVar =<< asks eventHandlers
liftIO $ h eh liftIO $ h eh
-- | End the current Xmpp session. -- | End the current Xmpp session.
endSession :: Xmpp () endSession :: Xmpp ()
@ -244,15 +244,21 @@ endSession = do -- TODO: This has to be idempotent (is it?)
void $ withConnection xmppKillConnection void $ withConnection xmppKillConnection
liftIO =<< asks stopThreads liftIO =<< asks stopThreads
-- | Close the connection to the server. -- | Close the connection to the server. Closes the stream (by enforcing a
-- write lock and sending a </stream:stream> element), waits (blocks) for three
-- seconds, and then closes the connection.
closeConnection :: Xmpp () closeConnection :: Xmpp ()
closeConnection = Ex.mask_ $ do closeConnection = Ex.mask_ $ do
write <- asks writeRef write <- asks writeRef
send <- liftIO . atomically $ takeTMVar write send <- liftIO . atomically $ takeTMVar write
cc <- sCloseConnection <$> (liftIO . atomically . readTMVar =<< asks conStateRef) cc <- sCloseConnection <$>
liftIO . send $ "</stream:stream>" (liftIO . atomically . readTMVar =<< asks conStateRef)
void . liftIO . forkIO $ do liftIO . send $ "</stream:stream>"
threadDelay 3000000 void . liftIO . forkIO $ do
(Ex.try cc) :: IO (Either Ex.SomeException ()) threadDelay 3000000
return () -- When we close the connection, we close the handle that was used in the
liftIO . atomically $ putTMVar write (\_ -> return False) -- sCloseConnection above. So even if a new connection has been
-- established at this point, it will not be affected by this action.
(Ex.try cc) :: IO (Either Ex.SomeException ())
return ()
liftIO . atomically $ putTMVar write (\_ -> return False)

5
source/Network/Xmpp/Monad.hs

@ -83,8 +83,9 @@ pullPickle p = do
Left e -> liftIO . Ex.throwIO $ StreamXMLError e Left e -> liftIO . Ex.throwIO $ StreamXMLError e
Right r -> return r Right r -> return r
-- Pulls a stanza from the stream. Throws an error on failure. -- Pulls a stanza (or stream error) from the stream. Throws an error on a stream
pullStanza :: XmppConMonad Stanza -- error.
pullStanza :: XmppConMonad Stanza
pullStanza = do pullStanza = do
res <- pullPickle xpStreamStanza res <- pullPickle xpStreamStanza
case res of case res of

Loading…
Cancel
Save