Skip to content

Commit

Permalink
fix proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroyaonoe committed Nov 24, 2023
1 parent 452ec95 commit 120c369
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions app/ingressgateway/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ package ingressgateway
import (
"io"
"net"

"golang.org/x/sync/errgroup"
)

func proxy(client, server net.Conn) error {
var eg errgroup.Group
errCh := make(chan error, 2)

eg.Go(func() error { return relay(client, server) })
eg.Go(func() error { return relay(server, client) })
go relay(errCh, client, server)
go relay(errCh, server, client)

return eg.Wait()
return <-errCh
}

func relay(src io.Reader, dst io.Writer) error {
func relay(errCh chan error, src io.Reader, dst io.Writer) {
_, err := io.Copy(dst, src)
return err
errCh <- err
return
}

0 comments on commit 120c369

Please sign in to comment.