Skip to content

Commit

Permalink
feat: netpoll exception implement net.Error interface (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
joway authored Jan 4, 2024
1 parent 9707178 commit 654cef1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions connection_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package netpoll

import (
"fmt"
"net"
"syscall"
)

Expand Down Expand Up @@ -51,6 +52,10 @@ func Exception(err error, suffix string) error {
return &exception{no: no, suffix: suffix}
}

var (
_ net.Error = (*exception)(nil)
)

type exception struct {
no syscall.Errno
suffix string
Expand Down Expand Up @@ -88,6 +93,21 @@ func (e *exception) Unwrap() error {
return e.no
}

func (e *exception) Timeout() bool {
switch e.no {
case ErrDialTimeout, ErrReadTimeout, ErrWriteTimeout:
return true
}
if e.no.Timeout() {
return true
}
return false
}

func (e *exception) Temporary() bool {
return e.no.Temporary()
}

// Errors defined in netpoll
var errnos = [...]string{
ErrnoMask & ErrConnClosed: "connection has been closed",
Expand Down

0 comments on commit 654cef1

Please sign in to comment.