From 654cef17e9abae548d176dedad204bc67780fbc0 Mon Sep 17 00:00:00 2001 From: Joway Date: Thu, 4 Jan 2024 13:40:26 +0800 Subject: [PATCH] feat: netpoll exception implement net.Error interface (#300) --- connection_errors.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/connection_errors.go b/connection_errors.go index b08ba668..1edfa21d 100644 --- a/connection_errors.go +++ b/connection_errors.go @@ -16,6 +16,7 @@ package netpoll import ( "fmt" + "net" "syscall" ) @@ -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 @@ -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",