Skip to content

Commit

Permalink
conn: seperate io.Reader and io.WriteCloser (pkg#118)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davecheney authored Jun 15, 2016
1 parent e3fac22 commit ea1a7bc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 2 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ func NewClientPipe(rd io.Reader, wr io.WriteCloser, opts ...func(*Client) error)
sftp := &Client{
clientConn: clientConn{
conn: conn{
ReadWriteCloser: struct {
io.Reader
io.WriteCloser
}{rd, wr},
Reader: rd,
WriteCloser: wr,
},
inflight: make(map[uint32]chan<- result),
},
Expand Down
3 changes: 2 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
// conn implements a bidirectional channel on which client and server
// connections are multiplexed.
type conn struct {
io.ReadWriteCloser
io.Reader
io.WriteCloser
sync.Mutex // used to serialise writes to sendPacket
}

Expand Down
3 changes: 2 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ type serverRespondablePacket interface {
func NewServer(rwc io.ReadWriteCloser, options ...ServerOption) (*Server, error) {
s := &Server{
conn: conn{
ReadWriteCloser: rwc,
Reader: rwc,
WriteCloser: rwc,
},
debugStream: ioutil.Discard,
pktChan: make(chan rxPacket, sftpServerWorkerCount),
Expand Down

0 comments on commit ea1a7bc

Please sign in to comment.