From 97bd16b6df1dbdb5796f527e6b831bcc94e02321 Mon Sep 17 00:00:00 2001
From: Philipp Balzarek
Date: Wed, 20 Mar 2013 13:51:00 +0100
Subject: [PATCH] fix stanza ID generator
---
source/Network/Xmpp/Concurrent.hs | 3 ++-
source/Network/Xmpp/Types.hs | 6 +++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/source/Network/Xmpp/Concurrent.hs b/source/Network/Xmpp/Concurrent.hs
index c40090f..9ff6ccc 100644
--- a/source/Network/Xmpp/Concurrent.hs
+++ b/source/Network/Xmpp/Concurrent.hs
@@ -113,12 +113,13 @@ newSession stream config = runErrorT $ do
]
(kill, wLock, streamState, readerThread) <- ErrorT $ startThreadsWith stanzaHandler eh stream
writer <- lift $ forkIO $ writeWorker outC wLock
+ idGen <- liftIO $ sessionStanzaIDs config
return $ Session { stanzaCh = stanzaChan
, outCh = outC
, iqHandlers = iqHandlers
, writeRef = wLock
, readerThread = readerThread
- , idGenerator = sessionStanzaIDs config
+ , idGenerator = idGen
, streamRef = streamState
, eventHandlers = eh
, stopThreads = kill >> killThread writer
diff --git a/source/Network/Xmpp/Types.hs b/source/Network/Xmpp/Types.hs
index 19c9f0e..5ad805d 100644
--- a/source/Network/Xmpp/Types.hs
+++ b/source/Network/Xmpp/Types.hs
@@ -1100,7 +1100,7 @@ data SessionConfiguration = SessionConfiguration
-- | Handler to be run when the session ends (for whatever reason).
, sessionClosedHandler :: XmppFailure -> IO ()
-- | Function to generate the stream of stanza identifiers.
- , sessionStanzaIDs :: IO StanzaID
+ , sessionStanzaIDs :: IO (IO StanzaID)
, extraStanzaHandlers :: [StanzaHandler]
}
@@ -1109,10 +1109,10 @@ instance Default SessionConfiguration where
, sessionClosedHandler = \_ -> return ()
, sessionStanzaIDs = do
idRef <- newTVarIO 1
- atomically $ do
+ return . atomically $ do
curId <- readTVar idRef
writeTVar idRef (curId + 1 :: Integer)
- return . read. show $ curId
+ return . StanzaID . Text.pack . show $ curId
, extraStanzaHandlers = []
}