-
Notifications
You must be signed in to change notification settings - Fork 6
/
timeout.go
34 lines (29 loc) · 862 Bytes
/
timeout.go
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
27
28
29
30
31
32
33
34
package lifxlan
import (
"time"
)
// UDPReadTimeout is the read timeout we use to read all the UDP messages.
//
// In some functions (e.g. Discover),
// the function will simply use the timeout to check context cancellation and
// continue reading,
// instead of return upon timeout.
//
// It's intentionally defined as variable instead of constant,
// so the user could adjust it if needed.
var UDPReadTimeout = time.Millisecond * 100
// GetReadDeadline returns a value can be used in net.Conn.SetReadDeadline from
// UDPReadTimeout value.
func GetReadDeadline() time.Time {
return time.Now().Add(UDPReadTimeout)
}
type timeouter interface {
Timeout() bool
}
// CheckTimeoutError returns true if err is caused by timeout in net package.
func CheckTimeoutError(err error) bool {
if t, ok := err.(timeouter); ok {
return t.Timeout()
}
return false
}