Skip to content

Commit 654cef1

Browse files
authored
feat: netpoll exception implement net.Error interface (#300)
1 parent 9707178 commit 654cef1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

connection_errors.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package netpoll
1616

1717
import (
1818
"fmt"
19+
"net"
1920
"syscall"
2021
)
2122

@@ -51,6 +52,10 @@ func Exception(err error, suffix string) error {
5152
return &exception{no: no, suffix: suffix}
5253
}
5354

55+
var (
56+
_ net.Error = (*exception)(nil)
57+
)
58+
5459
type exception struct {
5560
no syscall.Errno
5661
suffix string
@@ -88,6 +93,21 @@ func (e *exception) Unwrap() error {
8893
return e.no
8994
}
9095

96+
func (e *exception) Timeout() bool {
97+
switch e.no {
98+
case ErrDialTimeout, ErrReadTimeout, ErrWriteTimeout:
99+
return true
100+
}
101+
if e.no.Timeout() {
102+
return true
103+
}
104+
return false
105+
}
106+
107+
func (e *exception) Temporary() bool {
108+
return e.no.Temporary()
109+
}
110+
91111
// Errors defined in netpoll
92112
var errnos = [...]string{
93113
ErrnoMask & ErrConnClosed: "connection has been closed",

0 commit comments

Comments
 (0)