Fix err check

This commit is contained in:
世界 2022-07-20 12:56:59 +08:00
parent 3d74b823ed
commit 2af19486bb
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 18 additions and 4 deletions

View file

@ -6,10 +6,11 @@ import (
"io"
"net"
"os"
"syscall"
_ "unsafe"
"github.com/sagernet/sing/common"
F "github.com/sagernet/sing/common/format"
"syscall"
)
type Handler interface {
@ -45,10 +46,17 @@ func Errors(errors ...error) error {
}
}
func IsCanceled(err error) bool {
return IsMulti(err, context.Canceled, context.DeadlineExceeded)
//go:linkname errCanceled net.errCanceled
var errCanceled error
func IsClosedOrCanceled(err error) bool {
return IsMulti(err, io.EOF, net.ErrClosed, io.ErrClosedPipe, os.ErrClosed, syscall.EPIPE, syscall.ECONNRESET, context.Canceled, context.DeadlineExceeded, errCanceled)
}
func IsClosed(err error) bool {
return IsMulti(err, io.EOF, net.ErrClosed, io.ErrClosedPipe, os.ErrClosed, syscall.EPIPE)
return IsMulti(err, io.EOF, net.ErrClosed, io.ErrClosedPipe, os.ErrClosed, syscall.EPIPE, syscall.ECONNRESET)
}
func IsCanceled(err error) bool {
return IsMulti(err, context.Canceled, context.DeadlineExceeded, errCanceled)
}