diff options
author | 2012-10-27 00:42:14 -0400 | |
---|---|---|
committer | 2012-10-27 00:42:14 -0400 | |
commit | ce5b38aa1dbd1e320c5247d95344e373bf03e7cf (patch) | |
tree | 99e55c492457520f016188e00ba553c23f8bc187 /Assistant/Pushes.hs | |
parent | 5b7d00b6e9f79f4e0a2093feea58ad164a766ab2 (diff) |
reconnect XMPP when NetWatcher notices a change
Diffstat (limited to 'Assistant/Pushes.hs')
-rw-r--r-- | Assistant/Pushes.hs | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/Assistant/Pushes.hs b/Assistant/Pushes.hs index 7842c1884..49772d56a 100644 --- a/Assistant/Pushes.hs +++ b/Assistant/Pushes.hs @@ -11,6 +11,7 @@ import Common.Annex import Utility.TSet import Control.Concurrent.STM +import Control.Concurrent.MSampleVar import Data.Time.Clock import qualified Data.Map as M @@ -18,8 +19,13 @@ import qualified Data.Map as M type PushMap = M.Map Remote UTCTime type FailedPushMap = TMVar PushMap -{- Used to notify about successful pushes. -} -newtype PushNotifier = PushNotifier (TSet UUID) +{- The TSet is recent, successful pushes that other remotes should be + - notified about. + - + - The MSampleVar is written to when the PushNotifier thread should be + - restarted for some reason. + -} +data PushNotifier = PushNotifier (TSet UUID) (MSampleVar ()) {- The TMVar starts empty, and is left empty when there are no - failed pushes. This way we can block until there are some failed pushes. @@ -50,10 +56,18 @@ changeFailedPushMap v a = atomically $ | otherwise = putTMVar v $! m newPushNotifier :: IO PushNotifier -newPushNotifier = PushNotifier <$> newTSet +newPushNotifier = PushNotifier + <$> newTSet + <*> newEmptySV notifyPush :: [UUID] -> PushNotifier -> IO () -notifyPush us (PushNotifier s) = putTSet s us +notifyPush us (PushNotifier s _) = putTSet s us waitPush :: PushNotifier -> IO [UUID] -waitPush (PushNotifier s) = getTSet s +waitPush (PushNotifier s _) = getTSet s + +notifyRestart :: PushNotifier -> IO () +notifyRestart (PushNotifier _ sv) = writeSV sv () + +waitRestart :: PushNotifier -> IO () +waitRestart (PushNotifier _ sv) = readSV sv |