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)
}
pipe(stream, net)
if err := pipe(stream, net); err != nil {
return nil, errors.WithStack(err)
}
return nil, nil
}

View File

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