go-tunnel/helper.go

27 lines
343 B
Go
Raw Normal View History

2020-10-21 18:00:15 +02:00
package tunnel
import (
"io"
"net"
)
func pipe(client net.Conn, server net.Conn) {
stop := make(chan bool)
go relay(client, server, stop)
go relay(server, client, stop)
select {
case <-stop:
return
}
}
func relay(src net.Conn, dst net.Conn, stop chan bool) {
io.Copy(dst, src)
dst.Close()
src.Close()
stop <- true
return
}