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

@ -9,6 +9,7 @@ import (
"github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/buf"
E "github.com/sagernet/sing/common/exceptions"
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
"github.com/sagernet/sing/common/rw"
@ -37,6 +38,11 @@ func needReadFromWrapper(dst io.ReaderFrom, src io.Reader) bool {
}
func Copy(dst io.Writer, src io.Reader) (n int64, err error) {
if src == nil {
return 0, E.New("nil reader")
} else if dst == nil {
return 0, E.New("nil writer")
}
src = N.UnwrapReader(src)
dst = N.UnwrapWriter(dst)
if wt, ok := src.(io.WriterTo); ok {

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)
}