Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: He Xian <hexian000@outlook.com>
  • Loading branch information
hexian000 committed Jan 24, 2024
1 parent e8a658e commit 46dfc2b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 7 additions & 9 deletions v2/forwarder/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,23 @@ func (f *forwarder) Forward(accepted net.Conn, dialed net.Conn) error {
return ErrConnLimit
}
f.addConn(accepted, dialed)
cleanupOnce := &sync.Once{}
cleanup := func() {
cleanupOnce.Do(func() {
f.delConn(accepted, dialed)
<-f.counter
})
f.delConn(accepted, dialed)
<-f.counter
}
cleanupOnce := &sync.Once{}
if err := f.g.Go(func() {
defer cleanup()
defer cleanupOnce.Do(cleanup)
f.connCopy(accepted, dialed)
}); err != nil {
cleanup()
cleanupOnce.Do(cleanup)
return err
}
if err := f.g.Go(func() {
defer cleanup()
defer cleanupOnce.Do(cleanup)
f.connCopy(dialed, accepted)
}); err != nil {
cleanup()
cleanupOnce.Do(cleanup)
return err
}
return nil
Expand Down
4 changes: 3 additions & 1 deletion v2/tlswrapper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tlswrapper

import (
"fmt"
"io"

"github.com/hexian000/gosnippets/formats"
Expand All @@ -14,6 +15,7 @@ var (

func ioClose(c io.Closer) {
if err := c.Close(); err != nil {
slog.Warningf("close: %s", formats.Error(err))
msg := fmt.Sprintf("close: %s", formats.Error(err))
slog.Output(2, slog.LevelWarning, []byte(msg))
}
}

0 comments on commit 46dfc2b

Please sign in to comment.