feat: dispatch proxy error

This commit is contained in:
wpetit 2020-10-23 13:42:44 +02:00
parent 7aa977d2fe
commit 30564efd85
2 changed files with 16 additions and 7 deletions

View File

@ -117,7 +117,9 @@ func (c *Client) handleProxyRequest(ctx context.Context, m *control.Message) (*c
return nil, errors.WithStack(err) return nil, errors.WithStack(err)
} }
pipe(stream, net) if err := pipe(stream, net); err != nil {
return nil, errors.WithStack(err)
}
return nil, nil return nil, nil
} }

View File

@ -5,22 +5,29 @@ import (
"net" "net"
) )
func pipe(client net.Conn, server net.Conn) { func pipe(client net.Conn, server net.Conn) (err error) {
stop := make(chan bool) stop := make(chan bool)
go relay(client, server, stop) go func() {
go relay(server, client, stop) err = relay(client, server, stop)
}()
go func() {
err = relay(server, client, stop)
}()
select { select {
case <-stop: case <-stop:
return return err
} }
} }
func relay(src net.Conn, dst net.Conn, stop chan bool) { func relay(src io.ReadCloser, dst io.WriteCloser, stop chan bool) (err error) {
io.Copy(dst, src) _, err = io.Copy(dst, src)
dst.Close() dst.Close()
src.Close() src.Close()
stop <- true stop <- true
return return
} }