summaryrefslogtreecommitdiff
path: root/P2P
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-12-09 15:08:54 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-12-09 15:08:54 -0400
commit1eeae43d88c924dfac7c004ff7aeb67e17c52a13 (patch)
tree3517803c0484901bd99cab3a25dd2be6faf8dd0d /P2P
parentb3b800bb6140543306ec65751506ae2862ca345f (diff)
only start ref change watcher thread once per P2P connection
This is more efficient. Note that the peer will get CHANGED messages for all refs changed since the connection opened, even if those changes happened before it sent NOTIFYCHANGE.
Diffstat (limited to 'P2P')
-rw-r--r--P2P/Annex.hs21
1 files changed, 9 insertions, 12 deletions
diff --git a/P2P/Annex.hs b/P2P/Annex.hs
index e9b59652c..351fb38bb 100644
--- a/P2P/Annex.hs
+++ b/P2P/Annex.hs
@@ -25,10 +25,8 @@ import Utility.Metered
import Control.Monad.Free
--- When we're serving a peer, we know their uuid, and can use it to update
--- transfer logs.
data RunMode
- = Serving UUID
+ = Serving UUID ChangedRefsHandle
| Client
-- Full interpreter for Proto, that can receive and send objects.
@@ -115,18 +113,17 @@ runLocal runmode runner a = case a of
protoaction False
next
Right _ -> runner next
- WaitRefChange next -> do
- v <- tryNonAsync $ bracket
- watchChangedRefs
- (liftIO . stopWatchingChangedRefs)
- (liftIO . waitChangedRefs)
- case v of
- Left e -> return (Left (show e))
- Right changedrefs -> runner (next changedrefs)
+ WaitRefChange next -> case runmode of
+ Serving _ h -> do
+ v <- tryNonAsync $ liftIO $ waitChangedRefs h
+ case v of
+ Left e -> return (Left (show e))
+ Right changedrefs -> runner (next changedrefs)
+ _ -> return $ Left "change notification not implemented for client"
where
transfer mk k af ta = case runmode of
-- Update transfer logs when serving.
- Serving theiruuid ->
+ Serving theiruuid _ ->
mk theiruuid k af noRetry ta noNotification
-- Transfer logs are updated higher in the stack when
-- a client.