-
Notifications
You must be signed in to change notification settings - Fork 164
/
errors.go
103 lines (85 loc) · 2.26 KB
/
errors.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package zmq4
/*
#include <zmq.h>
*/
import "C"
import (
"syscall"
)
// An Errno is an unsigned number describing an error condition as returned by a call to ZeroMQ.
// It implements the error interface.
// The number is either a standard system error, or an error defined by the C library of ZeroMQ.
type Errno uintptr
const (
// Error conditions defined by the C library of ZeroMQ.
// On Windows platform some of the standard POSIX errnos are not defined.
EADDRINUSE = Errno(C.EADDRINUSE)
EADDRNOTAVAIL = Errno(C.EADDRNOTAVAIL)
EAFNOSUPPORT = Errno(C.EAFNOSUPPORT)
ECONNABORTED = Errno(C.ECONNABORTED)
ECONNREFUSED = Errno(C.ECONNREFUSED)
ECONNRESET = Errno(C.ECONNRESET)
EHOSTUNREACH = Errno(C.EHOSTUNREACH)
EINPROGRESS = Errno(C.EINPROGRESS)
EMSGSIZE = Errno(C.EMSGSIZE)
ENETDOWN = Errno(C.ENETDOWN)
ENETRESET = Errno(C.ENETRESET)
ENETUNREACH = Errno(C.ENETUNREACH)
ENOBUFS = Errno(C.ENOBUFS)
ENOTCONN = Errno(C.ENOTCONN)
ENOTSOCK = Errno(C.ENOTSOCK)
ENOTSUP = Errno(C.ENOTSUP)
EPROTONOSUPPORT = Errno(C.EPROTONOSUPPORT)
ETIMEDOUT = Errno(C.ETIMEDOUT)
// Native 0MQ error codes.
EFSM = Errno(C.EFSM)
EMTHREAD = Errno(C.EMTHREAD)
ENOCOMPATPROTO = Errno(C.ENOCOMPATPROTO)
ETERM = Errno(C.ETERM)
)
func errget(err error) error {
eno, ok := err.(syscall.Errno)
if ok {
return Errno(eno)
}
return err
}
// Return Errno as string.
func (errno Errno) Error() string {
if errno >= C.ZMQ_HAUSNUMERO {
return C.GoString(C.zmq_strerror(C.int(errno)))
}
return syscall.Errno(errno).Error()
}
/*
Convert error to Errno.
Example usage:
switch AsErrno(err) {
case zmq.Errno(syscall.EINTR):
// standard system error
// call was interrupted
case zmq.ETERM:
// error defined by ZeroMQ
// context was terminated
}
See also: examples/interrupt.go
*/
func AsErrno(err error) Errno {
if eno, ok := err.(Errno); ok {
return eno
}
if eno, ok := err.(syscall.Errno); ok {
return Errno(eno)
}
return Errno(0)
}
func (ctx *Context) retry(err error) bool {
if ctx == nil || !ctx.retryEINTR || err == nil {
return false
}
eno, ok := err.(syscall.Errno)
if !ok {
return false
}
return eno == syscall.EINTR
}