feat: dispatch proxy error
This commit is contained in:
parent
7aa977d2fe
commit
30564efd85
@ -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
|
||||
}
|
||||
|
19
helper.go
19
helper.go
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user