From 03ae8c9d659a1bd9736c18ec3c1e073792ce3f93 Mon Sep 17 00:00:00 2001 From: Jon Kristensen Date: Tue, 12 Mar 2013 02:10:21 +0100 Subject: [PATCH] Add connection closed handler to `SessionConfiguration' object --- source/Network/Xmpp/Concurrent.hs | 2 +- source/Network/Xmpp/Types.hs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/Network/Xmpp/Concurrent.hs b/source/Network/Xmpp/Concurrent.hs index bbc9b04..3881cd8 100644 --- a/source/Network/Xmpp/Concurrent.hs +++ b/source/Network/Xmpp/Concurrent.hs @@ -93,7 +93,7 @@ newSession stream config = runErrorT $ do outC <- lift newTChanIO stanzaChan <- lift newTChanIO iqHandlers <- lift $ newTVarIO (Map.empty, Map.empty) - eh <- lift $ newTVarIO $ EventHandlers { connectionClosedHandler = \_ -> return () } + eh <- lift $ newTVarIO $ EventHandlers { connectionClosedHandler = sessionClosedHandler config } let stanzaHandler = toChans stanzaChan outC iqHandlers (kill, wLock, streamState, readerThread) <- ErrorT $ startThreadsWith stanzaHandler eh stream writer <- lift $ forkIO $ writeWorker outC wLock diff --git a/source/Network/Xmpp/Types.hs b/source/Network/Xmpp/Types.hs index 6865e2f..a878db4 100644 --- a/source/Network/Xmpp/Types.hs +++ b/source/Network/Xmpp/Types.hs @@ -1093,7 +1093,10 @@ hostnameP = do data SessionConfiguration = SessionConfiguration { -- | Configuration for the @Stream@ object. sessionStreamConfiguration :: StreamConfiguration + -- | Handler to be run when the session ends (for whatever reason). + , sessionClosedHandler :: XmppFailure -> IO () } instance Default SessionConfiguration where - def = SessionConfiguration { sessionStreamConfiguration = def } + def = SessionConfiguration { sessionStreamConfiguration = def + , sessionClosedHandler = \_ -> return () }