diff options
author | EuAndreh <eu@euandre.org> | 2024-08-08 18:51:28 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-08-08 18:51:28 -0300 |
commit | a75fc0abe7aa34c2ed49990655562985c68aea32 (patch) | |
tree | 825715e4bf7079c6f735754cfb7867f9d97f1df5 /src/binder.go | |
parent | Makefile: Use "go tool {compile,link}" over "go {build,test}" (diff) | |
download | binder-a75fc0abe7aa34c2ed49990655562985c68aea32.tar.gz binder-a75fc0abe7aa34c2ed49990655562985c68aea32.tar.xz |
src/binder.go: Vendor in copyData()
Diffstat (limited to 'src/binder.go')
-rw-r--r-- | src/binder.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/binder.go b/src/binder.go index 8950c29..fc198e1 100644 --- a/src/binder.go +++ b/src/binder.go @@ -1,6 +1,7 @@ package binder import ( + "io" "fmt" "net" "os" @@ -87,6 +88,11 @@ func DropRoot() { } } +func copyData(c chan struct{}, from io.Reader, to io.WriteCloser) { + io.Copy(to, from) + c <- struct{}{} +} + func Start(toAddr string, listener net.Listener) { for { connFrom, err := listener.Accept() @@ -113,9 +119,9 @@ func Start(toAddr string, listener net.Listener) { } defer connTo.Close() - c := make(chan g.CopyResult) - go g.CopyData(c, "c2s", connFrom, connTo) - go g.CopyData(c, "s2c", connTo, connFrom) + c := make(chan struct{}) + go copyData(c, connFrom, connTo) + go copyData(c, connTo, connFrom) go func() { <- c EmitActiveConnection.Dec() |