diff --git a/source/Network/Xmpp.hs b/source/Network/Xmpp.hs index 0c4ef44..48a7e89 100644 --- a/source/Network/Xmpp.hs +++ b/source/Network/Xmpp.hs @@ -27,6 +27,7 @@ module Network.Xmpp ( -- * Session management Session , session + , setConnectionClosedHandler , StreamConfiguration(..) , SessionConfiguration(..) , ConnectionDetails(..) diff --git a/source/Network/Xmpp/Concurrent/Monad.hs b/source/Network/Xmpp/Concurrent/Monad.hs index a7e5b19..06c0711 100644 --- a/source/Network/Xmpp/Concurrent/Monad.hs +++ b/source/Network/Xmpp/Concurrent/Monad.hs @@ -70,9 +70,11 @@ modifyHandlers f session = atomically $ modifyTVar_ (eventHandlers session) f x <- readTVar var writeTVar var (g x) --- | Sets the handler to be executed when the server connection is closed. -setConnectionClosedHandler_ :: (XmppFailure -> Session -> IO ()) -> Session -> IO () -setConnectionClosedHandler_ eh session = do +-- | Changes the handler to be executed when the server connection is closed. To +-- avoid race conditions the initial value should be set in the configuration +-- when creating the session +setConnectionClosedHandler :: (XmppFailure -> Session -> IO ()) -> Session -> IO () +setConnectionClosedHandler eh session = do modifyHandlers (\s -> s{connectionClosedHandler = \e -> eh e session}) session