mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 20:37:40 +03:00
23 lines
384 B
Go
23 lines
384 B
Go
package exceptions
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
)
|
|
|
|
type TimeoutError interface {
|
|
Timeout() bool
|
|
}
|
|
|
|
func IsTimeout(err error) bool {
|
|
if unwrapErr := errors.Unwrap(err); unwrapErr != nil {
|
|
err = unwrapErr
|
|
}
|
|
if ne, ok := err.(*os.SyscallError); ok {
|
|
err = ne.Err
|
|
}
|
|
if timeoutErr, isTimeoutErr := err.(TimeoutError); isTimeoutErr {
|
|
return timeoutErr.Timeout()
|
|
}
|
|
return false
|
|
}
|