Browse Source

Add stanza identifier generator to the `SessionConfiguration' object

master
Jon Kristensen 13 years ago
parent
commit
5923d07f51
  1. 7
      source/Network/Xmpp/Concurrent.hs
  2. 9
      source/Network/Xmpp/Types.hs

7
source/Network/Xmpp/Concurrent.hs

@ -97,17 +97,12 @@ newSession stream config = runErrorT $ do
let stanzaHandler = toChans stanzaChan outC iqHandlers let stanzaHandler = toChans stanzaChan outC iqHandlers
(kill, wLock, streamState, readerThread) <- ErrorT $ startThreadsWith stanzaHandler eh stream (kill, wLock, streamState, readerThread) <- ErrorT $ startThreadsWith stanzaHandler eh stream
writer <- lift $ forkIO $ writeWorker outC wLock writer <- lift $ forkIO $ writeWorker outC wLock
idRef <- lift $ newTVarIO 1
let getId = atomically $ do
curId <- readTVar idRef
writeTVar idRef (curId + 1 :: Integer)
return . read. show $ curId
return $ Session { stanzaCh = stanzaChan return $ Session { stanzaCh = stanzaChan
, outCh = outC , outCh = outC
, iqHandlers = iqHandlers , iqHandlers = iqHandlers
, writeRef = wLock , writeRef = wLock
, readerThread = readerThread , readerThread = readerThread
, idGenerator = getId , idGenerator = sessionStanzaIDs config
, streamRef = streamState , streamRef = streamState
, eventHandlers = eh , eventHandlers = eh
, stopThreads = kill >> killThread writer , stopThreads = kill >> killThread writer

9
source/Network/Xmpp/Types.hs

@ -1095,8 +1095,15 @@ data SessionConfiguration = SessionConfiguration
sessionStreamConfiguration :: StreamConfiguration sessionStreamConfiguration :: StreamConfiguration
-- | Handler to be run when the session ends (for whatever reason). -- | Handler to be run when the session ends (for whatever reason).
, sessionClosedHandler :: XmppFailure -> IO () , sessionClosedHandler :: XmppFailure -> IO ()
, sessionStanzaIDs :: IO StanzaID
} }
instance Default SessionConfiguration where instance Default SessionConfiguration where
def = SessionConfiguration { sessionStreamConfiguration = def def = SessionConfiguration { sessionStreamConfiguration = def
, sessionClosedHandler = \_ -> return () } , sessionClosedHandler = \_ -> return ()
, sessionStanzaIDs = do
idRef <- newTVarIO 1
atomically $ do
curId <- readTVar idRef
writeTVar idRef (curId + 1 :: Integer)
return . read. show $ curId}

Loading…
Cancel
Save