feat: implement ready chanel to wait for established connection
This commit is contained in:
parent
4ed6a61b1d
commit
5de9ff7961
3 changed files with 41 additions and 11 deletions
|
|
@ -28,7 +28,7 @@ func NewForwarder(client *ssh.Client, localPort, remotePort, remoteHost string)
|
|||
}
|
||||
}
|
||||
|
||||
func (f *Forwarder) Start(ctx context.Context) error {
|
||||
func (f *Forwarder) Start(ctx context.Context, ready chan<- struct{}) error {
|
||||
localAddr := "127.0.0.1:" + f.localPort
|
||||
remoteAddr := net.JoinHostPort(f.remoteHost, f.remotePort)
|
||||
|
||||
|
|
@ -37,6 +37,10 @@ func (f *Forwarder) Start(ctx context.Context) error {
|
|||
return fmt.Errorf("failed to listen on %s: %w", localAddr, err)
|
||||
}
|
||||
|
||||
if ready != nil {
|
||||
close(ready)
|
||||
}
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
listener.Close()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue