ssh: defer channel window adjustment
Sending a window adjustment after every read is unnecessarily chatty, especially with a series of small reads like with TTY interactions. Copy OpenSSH's logic for deferring these, which seemingly hasn't changed since 2007. Note that since channelWindowSize and c.maxIncomingPayload are currently constants here, the two checks could be combined into a single check for c.myWindow < 2 MiB - 96 KiB (with the current values of the constants). Fixes golang/go#57424. Change-Id: Ifcef5be76fcc3f0b1a6dc396096bed9c50d64f21 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/459915 Reviewed-by: Nicola Murino <nicola.murino@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Nicola Murino <nicola.murino@gmail.com> Auto-Submit: Nicola Murino <nicola.murino@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Commit-Queue: Nicola Murino <nicola.murino@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
committed by
Gopher Robot
parent
b8ffc16e10
commit
fdfe1f8531
+17
-3
@@ -13,9 +13,10 @@ import (
|
||||
// An in-memory packetConn. It is safe to call Close and writePacket
|
||||
// from different goroutines.
|
||||
type memTransport struct {
|
||||
eof bool
|
||||
pending [][]byte
|
||||
write *memTransport
|
||||
eof bool
|
||||
pending [][]byte
|
||||
write *memTransport
|
||||
writeCount uint64
|
||||
sync.Mutex
|
||||
*sync.Cond
|
||||
}
|
||||
@@ -63,9 +64,16 @@ func (t *memTransport) writePacket(p []byte) error {
|
||||
copy(c, p)
|
||||
t.write.pending = append(t.write.pending, c)
|
||||
t.write.Cond.Signal()
|
||||
t.writeCount++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *memTransport) getWriteCount() uint64 {
|
||||
t.write.Lock()
|
||||
defer t.write.Unlock()
|
||||
return t.writeCount
|
||||
}
|
||||
|
||||
func memPipe() (a, b packetConn) {
|
||||
t1 := memTransport{}
|
||||
t2 := memTransport{}
|
||||
@@ -81,6 +89,9 @@ func TestMemPipe(t *testing.T) {
|
||||
if err := a.writePacket([]byte{42}); err != nil {
|
||||
t.Fatalf("writePacket: %v", err)
|
||||
}
|
||||
if wc := a.(*memTransport).getWriteCount(); wc != 1 {
|
||||
t.Fatalf("got %v, want 1", wc)
|
||||
}
|
||||
if err := a.Close(); err != nil {
|
||||
t.Fatal("Close: ", err)
|
||||
}
|
||||
@@ -95,6 +106,9 @@ func TestMemPipe(t *testing.T) {
|
||||
if err != io.EOF {
|
||||
t.Fatalf("got %v, %v, want EOF", p, err)
|
||||
}
|
||||
if wc := b.(*memTransport).getWriteCount(); wc != 0 {
|
||||
t.Fatalf("got %v, want 0", wc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDoubleClose(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user