-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patherrors.go
86 lines (69 loc) · 1.78 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
package zmq2
/*
#include <zmq.h>
#ifndef ENOTSOCK
#define ENOTSOCK (ZMQ_HAUSNUMERO + 9)
#endif
*/
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)
ECONNREFUSED = Errno(C.ECONNREFUSED)
EINPROGRESS = Errno(C.EINPROGRESS)
ENETDOWN = Errno(C.ENETDOWN)
ENOBUFS = Errno(C.ENOBUFS)
ENOTSOCK = Errno(C.ENOTSOCK)
ENOTSUP = Errno(C.ENOTSUP)
EPROTONOSUPPORT = Errno(C.EPROTONOSUPPORT)
// 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)
}