Choked: true,
PeerChoked: true,
write: make(chan []byte),
- post: make(chan pp.Message),
PeerMaxRequests: 250, // Default in libtorrent is 250.
}
defer func() {
if !me.addConnection(torrent, conn) {
return
}
+ conn.post = make(chan pp.Message)
go conn.writeOptimizer(time.Minute)
if conn.PeerExtensions[5]&0x10 != 0 {
conn.Post(pp.Message{
func (c *connection) Close() {
c.mu.Lock()
+ defer c.mu.Unlock()
if c.closed {
return
}
c.Socket.Close()
- close(c.post)
+ if c.post == nil {
+ // writeOptimizer isn't running, so we need to signal the writer to
+ // stop.
+ close(c.write)
+ } else {
+ // This will kill the writeOptimizer, and it kills the writer.
+ close(c.post)
+ }
c.closed = true
- c.mu.Unlock()
}
func (c *connection) getClosed() bool {