openrport-openrport/share/pipe.go
Nikita Vanyasin d5d7d168a2 Initial commit
- Cloned the chisel repo
- Binary rebranded
- Added golangci-lint and fixed some issues
2020-06-08 12:15:42 +03:00

30 lines
433 B
Go

package chshare
import (
"io"
"sync"
)
func Pipe(src io.ReadWriteCloser, dst io.ReadWriteCloser) (int64, int64) {
var sent, received int64
var wg sync.WaitGroup
var o sync.Once
close := func() {
src.Close()
dst.Close()
}
wg.Add(2)
go func() {
received, _ = io.Copy(src, dst)
o.Do(close)
wg.Done()
}()
go func() {
sent, _ = io.Copy(dst, src)
o.Do(close)
wg.Done()
}()
wg.Wait()
return sent, received
}