go.crypto/ssh: assorted close related fixes

Fixes golang/go#3810.

Fixes chanWriter Write after close behaviour bug.

Fixes serverChan writePacket after close bug.

Addresses final comments by agl on 6405064, plus various cleanups.

R=agl, kardianos, gustav.paul, fullung
CC=golang-dev
https://golang.org/cl/6479056
This commit is contained in:
Dave Cheney
2012-09-05 09:47:02 +10:00
parent 06790d30c2
commit 552202b8e3
5 changed files with 51 additions and 60 deletions
+4 -3
View File
@@ -249,7 +249,8 @@ func (c *ClientConn) mainLoop() {
ch.stderr.write(packet)
}
default:
switch msg := decode(packet).(type) {
msg := decode(packet)
switch msg := msg.(type) {
case *channelOpenMsg:
c.handleChanOpen(msg)
case *channelOpenConfirmMsg:
@@ -270,8 +271,7 @@ func (c *ClientConn) mainLoop() {
return
}
ch.Close()
// TODO(dfc) may need to optimisically remove the
// channel before closing
close(ch.msg)
c.chanList.remove(msg.PeersId)
case *channelEOFMsg:
ch, ok := c.getChan(msg.PeersId)
@@ -502,5 +502,6 @@ func (c *chanList) closeAll() {
continue
}
ch.Close()
close(ch.msg)
}
}