diff --git a/client.go b/client.go index ea8a4803..26951e48 100644 --- a/client.go +++ b/client.go @@ -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() diff --git a/peerconn.go b/peerconn.go index ac2b0ddf..dc9f9efb 100644 --- a/peerconn.go +++ b/peerconn.go @@ -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 { diff --git a/requesting.go b/requesting.go index f622b043..ed1c8d15 100644 --- a/requesting.go +++ b/requesting.go @@ -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): } } }