go.crypto/ssh: implement memTransport using sync.Cond.
This makes memTransport safe for use with multiple writers/closers. R=golang-dev, dave CC=agl, golang-dev https://golang.org/cl/14532048
This commit is contained in:
committed by
Dave Cheney
parent
44256fa2df
commit
7dc9a79b3e
@@ -8,41 +8,10 @@ package ssh
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"io"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// An in-memory packetConn.
|
||||
type memTransport struct {
|
||||
r, w chan []byte
|
||||
}
|
||||
|
||||
func (t *memTransport) readPacket() ([]byte, error) {
|
||||
p, ok := <-t.r
|
||||
if !ok {
|
||||
return nil, io.EOF
|
||||
}
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (t *memTransport) Close() error {
|
||||
close(t.w)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *memTransport) writePacket(p []byte) error {
|
||||
t.w <- p
|
||||
return nil
|
||||
}
|
||||
|
||||
func memPipe() (a, b packetConn) {
|
||||
p := make(chan []byte, 1)
|
||||
q := make(chan []byte, 1)
|
||||
return &memTransport{p, q}, &memTransport{q, p}
|
||||
}
|
||||
|
||||
func TestKexes(t *testing.T) {
|
||||
type kexResultErr struct {
|
||||
result *kexResult
|
||||
|
||||
Reference in New Issue
Block a user