mirror of
https://github.com/xmdhs/natupnp.git
synced 2025-12-24 13:37:51 +08:00
判断 ErrClosed
This commit is contained in:
5
main.go
5
main.go
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user