github.com/sagernet/sing@v0.4.0-beta.19.0.20240518125136-f67a0988a636/common/exceptions/timeout.go (about)

     1  package exceptions
     2  
     3  import "net"
     4  
     5  type TimeoutError interface {
     6  	Timeout() bool
     7  }
     8  
     9  func IsTimeout(err error) bool {
    10  	if netErr, isNetErr := err.(net.Error); isNetErr {
    11  		//goland:noinspection GoDeprecation
    12  		//nolint:staticcheck
    13  		return netErr.Temporary() && netErr.Timeout()
    14  	} else if timeoutErr, isTimeout := Cast[TimeoutError](err); isTimeout {
    15  		return timeoutErr.Timeout()
    16  	}
    17  	return false
    18  }