Browse Source

Merge branch 'optional-whitespace-keepalive' of https://github.com/singpolyma/pontarius-xmpp into singpolyma-optional-whitespace-keepalive

master
Philipp Balzarek 11 years ago
parent
commit
2cb1dcdc9c
  1. 1
      source/Network/Xmpp/Concurrent.hs
  2. 12
      source/Network/Xmpp/Concurrent/Threads.hs
  3. 4
      source/Network/Xmpp/Concurrent/Types.hs

1
source/Network/Xmpp/Concurrent.hs

@ -187,6 +187,7 @@ newSession stream config realm mbSasl = runErrorT $ do
] ]
(kill, sState, reader) <- ErrorT $ startThreadsWith writeSem stanzaHandler (kill, sState, reader) <- ErrorT $ startThreadsWith writeSem stanzaHandler
eh stream eh stream
(keepAlive config)
idGen <- liftIO $ sessionStanzaIDs config idGen <- liftIO $ sessionStanzaIDs config
let sess = Session { stanzaCh = stanzaChan let sess = Session { stanzaCh = stanzaChan
, iqHandlers = iqHands , iqHandlers = iqHands

12
source/Network/Xmpp/Concurrent/Threads.hs

@ -86,14 +86,15 @@ startThreadsWith :: TMVar (BS.ByteString -> IO (Either XmppFailure ()))
-> (Stanza -> IO ()) -> (Stanza -> IO ())
-> TMVar EventHandlers -> TMVar EventHandlers
-> Stream -> Stream
-> Maybe Int
-> IO (Either XmppFailure (IO (), -> IO (Either XmppFailure (IO (),
TMVar Stream, TMVar Stream,
ThreadId)) ThreadId))
startThreadsWith writeSem stanzaHandler eh con = do startThreadsWith writeSem stanzaHandler eh con keepAlive = do
-- read' <- withStream' (gets $ streamSend . streamHandle) con -- read' <- withStream' (gets $ streamSend . streamHandle) con
-- writeSem <- newTMVarIO read' -- writeSem <- newTMVarIO read'
conS <- newTMVarIO con conS <- newTMVarIO con
cp <- forkIO $ connPersist writeSem cp <- forkIO $ connPersist keepAlive writeSem
rdw <- forkIO $ readWorker stanzaHandler (noCon eh) conS rdw <- forkIO $ readWorker stanzaHandler (noCon eh) conS
return $ Right ( killConnection [rdw, cp] return $ Right ( killConnection [rdw, cp]
, conS , conS
@ -115,9 +116,10 @@ startThreadsWith writeSem stanzaHandler eh con = do
-- Acquires the write lock, pushes a space, and releases the lock. -- Acquires the write lock, pushes a space, and releases the lock.
-- | Sends a blank space every 30 seconds to keep the connection alive. -- | Sends a blank space every 30 seconds to keep the connection alive.
connPersist :: TMVar (BS.ByteString -> IO a) -> IO () connPersist :: Maybe Int -> TMVar (BS.ByteString -> IO a) -> IO ()
connPersist sem = forever $ do connPersist (Just delay) sem = forever $ do
pushBS <- atomically $ takeTMVar sem pushBS <- atomically $ takeTMVar sem
_ <- pushBS " " _ <- pushBS " "
atomically $ putTMVar sem pushBS atomically $ putTMVar sem pushBS
threadDelay 30000000 -- 30s threadDelay (delay*1000000)
connPersist Nothing _ = return ()

4
source/Network/Xmpp/Concurrent/Types.hs

@ -96,6 +96,9 @@ data SessionConfiguration = SessionConfiguration
-> PeerStatus -> PeerStatus
-> PeerStatus -> PeerStatus
-> IO ()) -> IO ())
-- | How often to send keep-alives
-- 'Nothing' disables keep-alive
, keepAlive :: Maybe Int
} }
instance Default SessionConfiguration where instance Default SessionConfiguration where
@ -111,6 +114,7 @@ instance Default SessionConfiguration where
, enableRoster = True , enableRoster = True
, enablePresenceTracking = True , enablePresenceTracking = True
, onPresenceChange = Nothing , onPresenceChange = Nothing
, keepAlive = Just 30
} }
-- | Handlers to be run when the Xmpp session ends and when the Xmpp connection is -- | Handlers to be run when the Xmpp session ends and when the Xmpp connection is

Loading…
Cancel
Save