-
Notifications
You must be signed in to change notification settings - Fork 15
/
errors.go
93 lines (76 loc) · 2.08 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
package zmq3
/*
#include <zmq.h>
#include "zmq3.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)
}