mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 13:41:23 +08:00
25 lines
568 B
Go
25 lines
568 B
Go
package net
|
|
|
|
import (
|
|
"io"
|
|
"net"
|
|
"time"
|
|
)
|
|
|
|
// Relay copies between left and right bidirectionally.
|
|
func Relay(leftConn, rightConn net.Conn) {
|
|
ch := make(chan error)
|
|
|
|
go func() {
|
|
// Wrapping to avoid using *net.TCPConn.(ReadFrom)
|
|
// See also https://github.com/Dreamacro/clash/pull/1209
|
|
_, err := io.Copy(WriteOnlyWriter{Writer: leftConn}, ReadOnlyReader{Reader: rightConn})
|
|
leftConn.SetReadDeadline(time.Now())
|
|
ch <- err
|
|
}()
|
|
|
|
io.Copy(WriteOnlyWriter{Writer: rightConn}, ReadOnlyReader{Reader: leftConn})
|
|
rightConn.SetReadDeadline(time.Now())
|
|
<-ch
|
|
}
|