判断 ErrClosed

This commit is contained in:
xmdhs
2023-06-15 19:40:39 +08:00
parent ad0b7e8749
commit 593eb59f61
2 changed files with 8 additions and 1 deletions

View File

@@ -100,7 +100,10 @@ func openPort(ctx context.Context, target, localAddr string, portu uint16, stun
errCh := make(chan error, 1)
m, s, err := natmap.NatMap(ctx, stun, localAddr, uint16(portu), func(s error) {
cancel()
errCh <- ErrNatMap{err: s}
select {
case errCh <- ErrNatMap{err: s}:
default:
}
})
if err != nil {
return fmt.Errorf("openPort: %w", err)

View File

@@ -2,6 +2,7 @@ package natmap
import (
"context"
"errors"
"fmt"
"io"
"net"
@@ -100,6 +101,9 @@ func Forward(ctx context.Context, port uint16, target string, log func(string))
c, err := l.Accept()
if err != nil {
log(err.Error())
if errors.Is(err, net.ErrClosed) {
return
}
continue
}
var d net.Dialer