go.crypto/ssh: close channel feeding tcpListener.
Close both on closing the listener, and on closing the
connection. Test the former case.
R=dave
CC=golang-dev
https://golang.org/cl/11349043
diff --git a/ssh/tcpip.go b/ssh/tcpip.go
index 8ebe262..ad92b43 100644
--- a/ssh/tcpip.go
+++ b/ssh/tcpip.go
@@ -101,17 +101,30 @@
return f.c
}
+// remove removes the forward entry, and the channel feeding its
+// listener.
func (l *forwardList) remove(addr net.TCPAddr) {
l.Lock()
defer l.Unlock()
for i, f := range l.entries {
if addr.IP.Equal(f.laddr.IP) && addr.Port == f.laddr.Port {
l.entries = append(l.entries[:i], l.entries[i+1:]...)
+ close(f.c)
return
}
}
}
+// closeAll closes and clears all forwards.
+func (l *forwardList) closeAll() {
+ l.Lock()
+ defer l.Unlock()
+ for _, f := range l.entries {
+ close(f.c)
+ }
+ l.entries = nil
+}
+
func (l *forwardList) lookup(addr net.TCPAddr) (chan forward, bool) {
l.Lock()
defer l.Unlock()