Skip to content

Commit

Permalink
init sync.WaitGroup as ptrs
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Apr 1, 2022
1 parent e5389c9 commit 7c6196c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/fly-aps/udp-echo

go 1.17

require github.com/pires/go-proxyproto v0.6.2 // indirect
require github.com/pires/go-proxyproto v0.6.2
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Conn struct {
}

func main() {
var done &sync.WaitGroup{}
done := &sync.WaitGroup{}
done.Add(5)

t5000, err := net.Listen("tcp", ":5000")
Expand All @@ -36,7 +36,7 @@ func main() {
fmt.Println("started: tcp-server on port 443")
}
pp443 := &proxyproto.Listener{Listener: t443}

//setting up tcp tls server
t80, err := net.Listen("tcp", ":80")
if err != nil {
Expand All @@ -56,7 +56,7 @@ func main() {

t5001, err := net.Listen("tcp", "0.0.0.0:5001")
if err != nil {
log.Fatalf("err tcp-sever on port 5001 %q\n", addr, err.Error())
log.Fatalf("err tcp-sever on port 5001 %q\n", err.Error())
}
pp5001 := &proxyproto.Listener{Listener: t5001} //converting tcp connection to proxy proto

Expand Down Expand Up @@ -210,7 +210,7 @@ func process(conn net.Conn) {
func forwardConn(src net.Conn) {
c := src.(*Conn)
_, port, err := net.SplitHostPort(src.LocalAddr().String())

if err != nil {
log.Print("invalid forward port")
return
Expand All @@ -223,7 +223,7 @@ func forwardConn(src net.Conn) {
}
defer dst.Close()

var wg &sync.WaitGroup{}
wg := &sync.WaitGroup{}
wg.Add(2)
go proxyCopy(src, dst, wg)
go proxyCopy(dst, src, wg)
Expand All @@ -245,7 +245,7 @@ func proxyCopy(dst, src net.Conn, wg *sync.WaitGroup) {
// 1.11's splice optimization kicks in.
src = UnderlyingConn(src)
dst = UnderlyingConn(dst)

io.Copy(dst, src)
}

Expand Down

0 comments on commit 7c6196c

Please sign in to comment.