conn: seperate io.Reader and io.WriteCloser (#118)

Reading and Writing are less coupled in the sftp client and server than
they may be over a traditional ReadWriter. This mirrors the full duplex
/ half close nature of a TCP connection.

In essence conn.Reader cannot be closed locally, it can only close in
response to the remote side using conn.WriteCloser.Close(), or a network
error, which is effectively the same thing.

Make this behaviour super clear by no longer smooshing the type into a
ReadWriteCloser.
This commit is contained in:
Dave Cheney 2016-06-15 20:19:51 +10:00 committed by GitHub
parent e3fac22d8a
commit ea1a7bcdfc
3 changed files with 6 additions and 6 deletions

View File

@ -54,10 +54,8 @@ func NewClientPipe(rd io.Reader, wr io.WriteCloser, opts ...func(*Client) error)
sftp := &Client{ sftp := &Client{
clientConn: clientConn{ clientConn: clientConn{
conn: conn{ conn: conn{
ReadWriteCloser: struct { Reader: rd,
io.Reader WriteCloser: wr,
io.WriteCloser
}{rd, wr},
}, },
inflight: make(map[uint32]chan<- result), inflight: make(map[uint32]chan<- result),
}, },

View File

@ -11,7 +11,8 @@ import (
// conn implements a bidirectional channel on which client and server // conn implements a bidirectional channel on which client and server
// connections are multiplexed. // connections are multiplexed.
type conn struct { type conn struct {
io.ReadWriteCloser io.Reader
io.WriteCloser
sync.Mutex // used to serialise writes to sendPacket sync.Mutex // used to serialise writes to sendPacket
} }

View File

@ -77,7 +77,8 @@ type serverRespondablePacket interface {
func NewServer(rwc io.ReadWriteCloser, options ...ServerOption) (*Server, error) { func NewServer(rwc io.ReadWriteCloser, options ...ServerOption) (*Server, error) {
s := &Server{ s := &Server{
conn: conn{ conn: conn{
ReadWriteCloser: rwc, Reader: rwc,
WriteCloser: rwc,
}, },
debugStream: ioutil.Discard, debugStream: ioutil.Discard,
pktChan: make(chan rxPacket, sftpServerWorkerCount), pktChan: make(chan rxPacket, sftpServerWorkerCount),