Skip to content

Commit

Permalink
Delete WaitGroup from forwarder struct and add it directly to the fun…
Browse files Browse the repository at this point in the history
…ction.
  • Loading branch information
steffano0 committed Nov 19, 2024
1 parent f850865 commit 1709986
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions forwarder/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type Forwarder struct {
ListeningPort int
LocalAddr string
data hosting.MeetingData
wg sync.WaitGroup
ctx context.Context
cancel context.CancelFunc
l net.Listener
Expand Down Expand Up @@ -146,20 +145,20 @@ func (f *Forwarder) forwardTraffic(conn1, conn2 *net.TCPConn) {
defer conn1.Close()
defer conn2.Close()

f.wg.Add(2)
var wg sync.WaitGroup

wg.Add(2)

go func() {
defer f.wg.Done()
defer wg.Done()
io.Copy(conn1, conn2)
conn1.CloseWrite()
}()
go func() {
defer f.wg.Done()
defer wg.Done()
io.Copy(conn2, conn1)
conn2.CloseWrite()
}()

f.wg.Wait()
wg.Wait()
}

func (f *Forwarder) StartForwarder() {
Expand Down Expand Up @@ -239,7 +238,6 @@ func (f *Forwarder) StopForwarder() {

f.shutdownListener()

f.wg.Wait()
f.pausing.stop()
log.Debug("Forwarder stopped.")
f.isRunning = false
Expand Down

0 comments on commit 1709986

Please sign in to comment.