mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2024-12-30 02:37:01 +00:00
update error detect
This commit is contained in:
+1
-1
@@ -43,7 +43,7 @@ func (h *udpHandler) fetchUDPInput(conn core.UDPConn, input net.PacketConn, addr
|
||||
input.SetDeadline(time.Now().Add(h.timeout))
|
||||
n, _, err := input.ReadFrom(buf)
|
||||
if err != nil {
|
||||
if netErr, ok := err.(net.Error); !ok || !netErr.Timeout() {
|
||||
if !isTimeout(err) && !isClosed(err) {
|
||||
log.Warnf("failed to read UDP data from remote: %v", err)
|
||||
}
|
||||
return
|
||||
|
||||
@@ -5,11 +5,25 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/proxy/socks"
|
||||
)
|
||||
|
||||
// Error
|
||||
func isTimeout(err error) bool {
|
||||
if netErr, ok := err.(net.Error); ok {
|
||||
return netErr.Timeout()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isClosed(err error) bool {
|
||||
want := "use of closed network connection"
|
||||
return strings.Contains(err.Error(), want)
|
||||
}
|
||||
|
||||
// UDP util
|
||||
type udpElement struct {
|
||||
remoteAddr net.Addr
|
||||
|
||||
Reference in New Issue
Block a user