From: Matt Joiner Date: Wed, 18 Mar 2015 07:36:27 +0000 (+1100) Subject: Don't accept unless connections are wanted X-Git-Tag: v1.0.0~1267 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=f90e6e7c2c9039973ae77d80cfb1b8cfa7b64c21;p=btrtrc.git Don't accept unless connections are wanted --- 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) }