diff options
Diffstat (limited to 'libgo/go/net/net.go')
-rw-r--r-- | libgo/go/net/net.go | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/libgo/go/net/net.go b/libgo/go/net/net.go index 77b8f69..b3f9b8b 100644 --- a/libgo/go/net/net.go +++ b/libgo/go/net/net.go @@ -282,7 +282,7 @@ func (c *conn) SetWriteBuffer(bytes int) error { return nil } -// File returns a copy of the underlying os.File +// File returns a copy of the underlying os.File. // It is the caller's responsibility to close f when finished. // Closing c does not affect f, and closing f does not affect c. // @@ -448,6 +448,8 @@ type OpError struct { Err error } +func (e *OpError) Unwrap() error { return e.Err } + func (e *OpError) Error() string { if e == nil { return "<nil>" @@ -473,7 +475,7 @@ func (e *OpError) Error() string { var ( // aLongTimeAgo is a non-zero time, far in the past, used for - // immediate cancelation of dials. + // immediate cancellation of dials. aLongTimeAgo = time.Unix(1, 0) // nonDeadline and noCancel are just zero values for @@ -514,6 +516,16 @@ func (e *OpError) Temporary() bool { return ok && t.Temporary() } +func (e *OpError) Is(target error) bool { + switch target { + case os.ErrTemporary: + return e.Temporary() + case os.ErrTimeout: + return e.Timeout() + } + return false +} + // A ParseError is the error type of literal network address parsers. type ParseError struct { // Type is the type of string that was expected, such as @@ -563,6 +575,7 @@ type DNSConfigError struct { Err error } +func (e *DNSConfigError) Unwrap() error { return e.Err } func (e *DNSConfigError) Error() string { return "error reading DNS config: " + e.Err.Error() } func (e *DNSConfigError) Timeout() bool { return false } func (e *DNSConfigError) Temporary() bool { return false } @@ -579,6 +592,7 @@ type DNSError struct { Server string // server used IsTimeout bool // if true, timed out; not all timeouts set this IsTemporary bool // if true, error is temporary; not all errors set this + IsNotFound bool // if true, host could not be found } func (e *DNSError) Error() string { @@ -603,6 +617,16 @@ func (e *DNSError) Timeout() bool { return e.IsTimeout } // error and return a DNSError for which Temporary returns false. func (e *DNSError) Temporary() bool { return e.IsTimeout || e.IsTemporary } +func (e *DNSError) Is(target error) bool { + switch target { + case os.ErrTemporary: + return e.Temporary() + case os.ErrTimeout: + return e.Timeout() + } + return false +} + type writerOnly struct { io.Writer } |