Skip to content

Commit fbf9e05

Browse files
committed
Add Wait method to detect underlying SFTP connection closed
Closes pkg#278
1 parent 08de04f commit fbf9e05

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func NewClientPipe(rd io.Reader, wr io.WriteCloser, opts ...ClientOption) (*Clie
122122
WriteCloser: wr,
123123
},
124124
inflight: make(map[uint32]chan<- result),
125+
errCh: make(chan error, 1),
125126
},
126127
maxPacket: 1 << 15,
127128
maxConcurrentRequests: 64,

conn.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ type clientConn struct {
3636
wg sync.WaitGroup
3737
sync.Mutex // protects inflight
3838
inflight map[uint32]chan<- result // outstanding requests
39+
errCh chan error
40+
}
41+
42+
// Wait blocks until the conn has shut down, and return the error
43+
// causing the shutdown.
44+
func (c *clientConn) Wait() error {
45+
return <-c.errCh
3946
}
4047

4148
// Close closes the SFTP session.
@@ -49,6 +56,7 @@ func (c *clientConn) loop() {
4956
err := c.recv()
5057
if err != nil {
5158
c.broadcastErr(err)
59+
c.errCh <- err
5260
}
5361
}
5462

0 commit comments

Comments
 (0)