From f90e6e7c2c9039973ae77d80cfb1b8cfa7b64c21 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 18 Mar 2015 18:36:27 +1100 Subject: [PATCH] Don't accept unless connections are wanted --- client.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/client.go b/client.go index 341cb5ec..6d3ec782 100644 --- a/client.go +++ b/client.go @@ -624,8 +624,22 @@ func (cl *Client) ipBlockRange(ip net.IP) (r *iplist.Range) { return } +func (cl *Client) waitAccept() { + cl.mu.Lock() + defer cl.mu.Unlock() + for { + for _, t := range cl.torrents { + if cl.wantConns(t) { + return + } + } + cl.event.Wait() + } +} + func (cl *Client) acceptConnections(l net.Listener, utp bool) { for { + cl.waitAccept() // We accept all connections immediately, because we don't know what // torrent they're for. conn, err := l.Accept() @@ -1668,6 +1682,7 @@ func (me *Client) connectionLoop(t *torrent, c *connection) error { } func (me *Client) dropConnection(torrent *torrent, conn *connection) { + me.event.Broadcast() for r := range conn.Requests { me.connDeleteRequest(torrent, conn, r) } -- 2.48.1