27 lines
343 B
Go
27 lines
343 B
Go
|
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
|
||
|
}
|