refactor: simplify client goroutine

This commit is contained in:
ICKelin
2021-05-13 19:06:18 +08:00
parent ea0e7b24ff
commit b05294abf5

View File

@@ -133,11 +133,9 @@ func (c *Client) tcpProxy(stream *yamux.Stream, p *proto.ProxyProtocol) {
io.Copy(remoteConn, stream) io.Copy(remoteConn, stream)
}() }()
go func() {
defer remoteConn.Close() defer remoteConn.Close()
defer stream.Close() defer stream.Close()
io.Copy(stream, remoteConn) io.Copy(stream, remoteConn)
}()
} }
func (c *Client) udpProxy(stream *yamux.Stream, p *proto.ProxyProtocol) { func (c *Client) udpProxy(stream *yamux.Stream, p *proto.ProxyProtocol) {
@@ -177,7 +175,6 @@ func (c *Client) udpProxy(stream *yamux.Stream, p *proto.ProxyProtocol) {
} }
}() }()
go func() {
defer remoteConn.Close() defer remoteConn.Close()
defer stream.Close() defer stream.Close()
buf := make([]byte, 64*1024) buf := make([]byte, 64*1024)
@@ -195,7 +192,6 @@ func (c *Client) udpProxy(stream *yamux.Stream, p *proto.ProxyProtocol) {
break break
} }
} }
}()
} }
func encode(raw []byte) []byte { func encode(raw []byte) []byte {