update error detect

This commit is contained in:
Jason
2019-08-30 17:18:44 +08:00
parent 78b65e6a83
commit a8fce929c3
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -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
+14
View File
@@ -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