|
|
|
@ -153,7 +153,7 @@ waitForPresence f = do |
|
|
|
-- and resumed with the new session details once the action returns. |
|
|
|
-- and resumed with the new session details once the action returns. |
|
|
|
-- The Action will run in the calling thread/ |
|
|
|
-- The Action will run in the calling thread/ |
|
|
|
-- Any uncaught exceptions will be interpreted as connection failure |
|
|
|
-- Any uncaught exceptions will be interpreted as connection failure |
|
|
|
withConnection :: XMPPConMonad a -> XMPP a |
|
|
|
withConnection :: XMPPConMonad a -> XMPP (Either StreamError a) |
|
|
|
withConnection a = do |
|
|
|
withConnection a = do |
|
|
|
readerId <- asks readerThread |
|
|
|
readerId <- asks readerThread |
|
|
|
stateRef <- asks conStateRef |
|
|
|
stateRef <- asks conStateRef |
|
|
|
@ -171,17 +171,18 @@ withConnection a = do |
|
|
|
>> Ex.throwIO (e :: Ex.SomeException) |
|
|
|
>> Ex.throwIO (e :: Ex.SomeException) |
|
|
|
-- No MVar taken |
|
|
|
-- No MVar taken |
|
|
|
) |
|
|
|
) |
|
|
|
Ex.catch ( do |
|
|
|
Ex.catches ( do |
|
|
|
(res, s') <- runStateT a s |
|
|
|
(res, s') <- runStateT a s |
|
|
|
atomically $ do |
|
|
|
atomically $ do |
|
|
|
putTMVar write (sConPushBS s') |
|
|
|
putTMVar write (sConPushBS s') |
|
|
|
putTMVar stateRef s' |
|
|
|
putTMVar stateRef s' |
|
|
|
return res |
|
|
|
return $ Right res |
|
|
|
) |
|
|
|
) |
|
|
|
-- we treat all Exceptions as fatal |
|
|
|
-- we treat all Exceptions as fatal |
|
|
|
(\e -> runStateT xmppKillConnection s |
|
|
|
[ Ex.Handler $ \e -> return $ Left (e :: StreamError) |
|
|
|
>> Ex.throwIO (e :: Ex.SomeException) |
|
|
|
, Ex.Handler $ \e -> runStateT xmppKillConnection s |
|
|
|
) |
|
|
|
>> Ex.throwIO (e :: Ex.SomeException) |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
-- | Send a presence Stanza |
|
|
|
-- | Send a presence Stanza |
|
|
|
sendPresence :: Presence -> XMPP () |
|
|
|
sendPresence :: Presence -> XMPP () |
|
|
|
@ -216,11 +217,11 @@ runHandler h = do |
|
|
|
-- | End the current xmpp session |
|
|
|
-- | End the current xmpp session |
|
|
|
endSession :: XMPP () |
|
|
|
endSession :: XMPP () |
|
|
|
endSession = do -- TODO: This has to be idempotent (is it?) |
|
|
|
endSession = do -- TODO: This has to be idempotent (is it?) |
|
|
|
withConnection xmppKillConnection |
|
|
|
void $ withConnection xmppKillConnection |
|
|
|
liftIO =<< asks stopThreads |
|
|
|
liftIO =<< asks stopThreads |
|
|
|
runHandler sessionEndHandler |
|
|
|
runHandler sessionEndHandler |
|
|
|
|
|
|
|
|
|
|
|
-- | Close the connection to the server |
|
|
|
-- | Close the connection to the server |
|
|
|
closeConnection :: XMPP () |
|
|
|
closeConnection :: XMPP () |
|
|
|
closeConnection = withConnection xmppKillConnection |
|
|
|
closeConnection = void $ withConnection xmppKillConnection |
|
|
|
|
|
|
|
|
|
|
|
|