diff options
author | Joey Hess <joey@kitenet.net> | 2014-01-06 17:07:08 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-01-06 17:07:08 -0400 |
commit | 108d51811a2befe1da8f5259a9e2d13dcb91c28f (patch) | |
tree | 30ae4c27502e4929bacdbd9b1f5399255c363067 /Assistant/Types | |
parent | 6728be8d14484071a3b086eb5b7493db055683d1 (diff) |
tested transferkeys restarting; fix some bugs
Diffstat (limited to 'Assistant/Types')
-rw-r--r-- | Assistant/Types/TransferrerPool.hs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/Assistant/Types/TransferrerPool.hs b/Assistant/Types/TransferrerPool.hs index 899e6969f..b66fdfa13 100644 --- a/Assistant/Types/TransferrerPool.hs +++ b/Assistant/Types/TransferrerPool.hs @@ -11,7 +11,7 @@ import Common.Annex import Utility.NotificationBroadcaster import Assistant.Types.DaemonStatus -import Control.Concurrent.STM +import Control.Concurrent.STM hiding (check) {- This TMVar is never left empty. -} type TransferrerPool = TMVar (MkCheckTransferrer, [TransferrerPoolItem]) @@ -33,23 +33,22 @@ data Transferrer = Transferrer newTransferrerPool :: MkCheckTransferrer -> IO TransferrerPool newTransferrerPool c = newTMVarIO (c, []) -popTransferrerPool :: TransferrerPool -> STM (Maybe TransferrerPoolItem) +popTransferrerPool :: TransferrerPool -> STM (Maybe TransferrerPoolItem, Int) popTransferrerPool p = do (c, l) <- takeTMVar p case l of [] -> do putTMVar p (c, []) - return Nothing + return (Nothing, 0) (i:is) -> do putTMVar p (c, is) - return $ Just i + return $ (Just i, length is) -pushTransferrerPool :: TransferrerPool -> TransferrerPoolItem -> STM Int +pushTransferrerPool :: TransferrerPool -> TransferrerPoolItem -> STM () pushTransferrerPool p i = do (c, l) <- takeTMVar p let l' = i:l putTMVar p (c, l') - return $ length l' {- Note that making a CheckTransferrer may allocate resources, - such as a NotificationHandle, so it's important that the returned @@ -65,4 +64,4 @@ checkNetworkConnections :: DaemonStatusHandle -> MkCheckTransferrer checkNetworkConnections dstatushandle = do dstatus <- atomically $ readTMVar dstatushandle h <- newNotificationHandle False (networkConnectedNotifier dstatus) - return $ checkNotification h + return $ not <$> checkNotification h |