client.go | 15 +++++++++++++++ diff --git a/client.go b/client.go index 341cb5ec20b8eaf140e1479bde51d5678c05a690..6d3ec782859c26dfec8f47df1167a493880e4de1 100644 --- a/client.go +++ b/client.go @@ -624,8 +624,22 @@ r = cl.ipBlockList.Lookup(ip) 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) dropConnection(torrent *torrent, conn *connection) { + me.event.Broadcast() for r := range conn.Requests { me.connDeleteRequest(torrent, conn, r) }