Browse Source

Utilities.hs: Implemented `IO [Int]' function for reconnection waiting

master
Jon Kristensen 13 years ago
parent
commit
57bb2a1d21
  1. 11
      source/Network/Xmpp/Utilities.hs

11
source/Network/Xmpp/Utilities.hs

@ -28,6 +28,7 @@ import Prelude
import System.IO.Unsafe(unsafePerformIO) import System.IO.Unsafe(unsafePerformIO)
import qualified Text.XML.Stream.Render as TXSR import qualified Text.XML.Stream.Render as TXSR
import Text.XML.Unresolved as TXU import Text.XML.Unresolved as TXU
import System.Random
-- | Apply f with the content of tv as state, restoring the original value when an -- | Apply f with the content of tv as state, restoring the original value when an
-- exception occurs -- exception occurs
@ -92,3 +93,13 @@ hostnameP = do
if Text.length label + 1 + Text.length r > 255 if Text.length label + 1 + Text.length r > 255
then fail "Hostname too long." then fail "Hostname too long."
else return $ Text.concat [label, Text.pack ".", r] else return $ Text.concat [label, Text.pack ".", r]
-- The number of seconds to wait before reconnection attempts in accordance with
-- the truncated binary exponential backoff algorithm.
waitingTimes :: IO [Int]
waitingTimes = do
wait <- randomRIO (1, 59)
waits <- Prelude.mapM (\n -> randomRIO (0, wait * n)) slotTimes
return (wait:waits)
where
slotTimes = [1, 3, 8, 15, 24, 35, 48, 63, 80, 99, 99, 99, 99, 99, 99]

Loading…
Cancel
Save