~fnux/yggdrasil-go-coap

yggdrasil-go-coap/net/isTemporary.go -rw-r--r-- 601 bytes
614f652bTimothée Floure Add syntax highlighting to code snippets in README 1 year, 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package net

import (
	"net"
	"strings"

	"github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil"
)

// https://github.com/golang/go/blob/958e212db799e609b2a8df51cdd85c9341e7a404/src/internal/poll/fd.go#L43
const ioTimeout = "i/o timeout"

func isTemporary(err error) bool {
	if netErr, ok := err.(net.Error); ok && (netErr.Temporary() || netErr.Timeout()) {
		return true
	}

	if yggdrasilConnErr, ok := err.(yggdrasil.ConnError); ok && (yggdrasilConnErr.Temporary() || yggdrasilConnErr.Timeout()) {
		return true
	}

	if strings.Contains(err.Error(), ioTimeout) {
		return true
	}
	return false
}