From 34e80d8fe2cc72d2d5fba22a1359946b55b24f25 Mon Sep 17 00:00:00 2001 From: Philipp Balzarek Date: Sat, 1 Jun 2013 17:41:36 +0200 Subject: [PATCH] export setConnectionClosedHandler --- source/Network/Xmpp.hs | 1 + source/Network/Xmpp/Concurrent/Monad.hs | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) 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