Skip to content

Commit

Permalink
Merge pull request pkg#279 from wutzx/client-conn-wait
Browse files Browse the repository at this point in the history
Add Wait method to detect underlying SFTP connection closed
  • Loading branch information
eikenb authored Feb 5, 2019
2 parents c35a030 + 5cd7f32 commit a713b07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func NewClientPipe(rd io.Reader, wr io.WriteCloser, opts ...ClientOption) (*Clie
WriteCloser: wr,
},
inflight: make(map[uint32]chan<- result),
closed: make(chan struct{}),
},
maxPacket: 1 << 15,
maxConcurrentRequests: 64,
Expand Down
13 changes: 13 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ type clientConn struct {
wg sync.WaitGroup
sync.Mutex // protects inflight
inflight map[uint32]chan<- result // outstanding requests

closed chan struct{}
err error
}

// Wait blocks until the conn has shut down, and return the error
// causing the shutdown. It can be called concurrently from multiple
// goroutines.
func (c *clientConn) Wait() error {
<-c.closed
return c.err
}

// Close closes the SFTP session.
Expand Down Expand Up @@ -122,6 +133,8 @@ func (c *clientConn) broadcastErr(err error) {
for _, ch := range listeners {
ch <- result{err: err}
}
c.err = err
close(c.closed)
}

type serverConn struct {
Expand Down

0 comments on commit a713b07

Please sign in to comment.