@ -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 ()