Increase request update interval if there's no signalling

This commit is contained in:
Matt Joiner 2021-08-01 22:52:51 +10:00
parent 7096da9f03
commit d42f2516a4
3 changed files with 12 additions and 11 deletions

View File

@ -53,7 +53,7 @@ type Client struct {
_mu lockWithDeferreds
event sync.Cond
closed missinggo.Event
closed chansync.SetOnce
config *ClientConfig
logger log.Logger
@ -398,10 +398,8 @@ func (cl *Client) NewAnacrolixDhtServer(conn net.PacketConn) (s *dht.Server, err
return
}
func (cl *Client) Closed() <-chan struct{} {
cl.lock()
defer cl.unlock()
return cl.closed.C()
func (cl *Client) Closed() chansync.Done {
return cl.closed.Done()
}
func (cl *Client) eachDhtServer(f func(DhtServer)) {
@ -1518,7 +1516,7 @@ func (cl *Client) clearAcceptLimits() {
func (cl *Client) acceptLimitClearer() {
for {
select {
case <-cl.closed.LockedChan(cl.locker()):
case <-cl.closed.Done():
return
case <-time.After(15 * time.Minute):
cl.lock()

View File

@ -1297,6 +1297,7 @@ func (c *Peer) receiveChunk(msg *pp.Message) error {
c.allStats(add(int64(len(msg.Piece)), func(cs *ConnStats) *Count { return &cs.BytesReadUsefulData }))
if deletedRequest {
c.piecesReceivedSinceLastRequestUpdate++
c.updateRequests()
c.allStats(add(int64(len(msg.Piece)), func(cs *ConnStats) *Count { return &cs.BytesReadUsefulIntendedData }))
}
for _, f := range c.t.cl.config.Callbacks.ReceivedUsefulData {

View File

@ -19,14 +19,16 @@ func (cl *Client) requester() {
cl.doRequests()
return cl.updateRequests.Signaled()
}()
// We can probably tune how often to heed this signal. TODO: Currently disabled to retain
// existing behaviour, while the signalling is worked out.
update = nil
select {
case <-cl.closed.LockedChan(cl.locker()):
case <-cl.closed.Done():
return
case <-time.After(100 * time.Millisecond):
}
select {
case <-cl.closed.Done():
return
case <-update:
case <-time.After(100 * time.Millisecond):
case <-time.After(time.Second):
}
}
}