libzmq
src
err.hpp
Go to the documentation of this file.
1
/* SPDX-License-Identifier: MPL-2.0 */
2
3
#ifndef __ZMQ_ERR_HPP_INCLUDED__
4
#define __ZMQ_ERR_HPP_INCLUDED__
5
6
#include <
assert.h
>
7
#if defined _WIN32_WCE
8
#include "..\builds\msvc\errno.hpp"
9
#else
10
#include <errno.h>
11
#endif
12
#include <string.h>
13
#include <stdlib.h>
14
#include <stdio.h>
15
16
#ifndef ZMQ_HAVE_WINDOWS
17
#include <netdb.h>
18
#endif
19
20
#include "
likely.hpp
"
21
22
// 0MQ-specific error codes are defined in zmq.h
23
24
// EPROTO is not used by OpenBSD and maybe other platforms.
25
#ifndef EPROTO
26
#define EPROTO 0
27
#endif
28
29
namespace
zmq
30
{
31
const
char
*
errno_to_string
(
int
errno_);
32
#if defined __clang__
33
#if __has_feature(attribute_analyzer_noreturn)
34
void
zmq_abort
(
const
char
*errmsg_) __attribute__ ((analyzer_noreturn));
35
#else
36
void
zmq_abort
(
const
char
*errmsg_);
37
#endif
38
#elif defined __MSCVER__
39
__declspec(noreturn)
void
zmq_abort
(
const
char
*errmsg_);
40
#else
41
void
zmq_abort
(
const
char
*errmsg_);
42
#endif
43
void
print_backtrace
();
44
}
45
46
#ifdef ZMQ_HAVE_WINDOWS
47
48
namespace
zmq
49
{
50
const
char
*wsa_error ();
51
const
char
*
52
wsa_error_no (
int
no_,
53
const
char
*wsae_wouldblock_string_ =
"Operation would block"
);
54
void
win_error (
char
*
buffer_
,
size_t
buffer_size_);
55
int
wsa_error_to_errno (
int
errcode_);
56
}
57
58
// Provides convenient way to check WSA-style errors on Windows.
59
#define wsa_assert(x) \
60
do { \
61
if (unlikely (!(x))) { \
62
const char *errstr = zmq::wsa_error (); \
63
if (errstr != NULL) { \
64
fprintf (stderr, "Assertion failed: %s [%i] (%s:%d)\n", \
65
errstr, WSAGetLastError (), __FILE__, __LINE__); \
66
fflush (stderr); \
67
zmq::zmq_abort (errstr); \
68
} \
69
} \
70
} while (false)
71
72
// Provides convenient way to assert on WSA-style errors on Windows.
73
#define wsa_assert_no(no) \
74
do { \
75
const char *errstr = zmq::wsa_error_no (no); \
76
if (errstr != NULL) { \
77
fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \
78
__FILE__, __LINE__); \
79
fflush (stderr); \
80
zmq::zmq_abort (errstr); \
81
} \
82
} while (false)
83
84
// Provides convenient way to check GetLastError-style errors on Windows.
85
#define win_assert(x) \
86
do { \
87
if (unlikely (!(x))) { \
88
char errstr[256]; \
89
zmq::win_error (errstr, 256); \
90
fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \
91
__FILE__, __LINE__); \
92
fflush (stderr); \
93
zmq::zmq_abort (errstr); \
94
} \
95
} while (false)
96
97
#endif
98
99
// This macro works in exactly the same way as the normal assert. It is used
100
// in its stead because standard assert on Win32 in broken - it prints nothing
101
// when used within the scope of JNI library.
102
#define zmq_assert(x) \
103
do { \
104
if (unlikely (!(x))) { \
105
fprintf (stderr, "Assertion failed: %s (%s:%d)\n", #x, __FILE__, \
106
__LINE__); \
107
fflush (stderr); \
108
zmq::zmq_abort (#x); \
109
} \
110
} while (false)
111
112
// Provides convenient way to check for errno-style errors.
113
#define errno_assert(x) \
114
do { \
115
if (unlikely (!(x))) { \
116
const char *errstr = strerror (errno); \
117
fprintf (stderr, "%s (%s:%d)\n", errstr, __FILE__, __LINE__); \
118
fflush (stderr); \
119
zmq::zmq_abort (errstr); \
120
} \
121
} while (false)
122
123
// Provides convenient way to check for POSIX errors.
124
#define posix_assert(x) \
125
do { \
126
if (unlikely (x)) { \
127
const char *errstr = strerror (x); \
128
fprintf (stderr, "%s (%s:%d)\n", errstr, __FILE__, __LINE__); \
129
fflush (stderr); \
130
zmq::zmq_abort (errstr); \
131
} \
132
} while (false)
133
134
// Provides convenient way to check for errors from getaddrinfo.
135
#define gai_assert(x) \
136
do { \
137
if (unlikely (x)) { \
138
const char *errstr = gai_strerror (x); \
139
fprintf (stderr, "%s (%s:%d)\n", errstr, __FILE__, __LINE__); \
140
fflush (stderr); \
141
zmq::zmq_abort (errstr); \
142
} \
143
} while (false)
144
145
// Provides convenient way to check whether memory allocation have succeeded.
146
#define alloc_assert(x) \
147
do { \
148
if (unlikely (!(x))) { \
149
fprintf (stderr, "FATAL ERROR: OUT OF MEMORY (%s:%d)\n", __FILE__, \
150
__LINE__); \
151
fflush (stderr); \
152
zmq::zmq_abort ("FATAL ERROR: OUT OF MEMORY"); \
153
} \
154
} while (false)
155
156
#endif
zmq::zmq_abort
void zmq_abort(const char *errmsg_)
Definition:
err.cpp:50
zmq
Definition:
zmq.hpp:229
likely.hpp
buffer_
static uint8 buffer_[kBufferSize]
Definition:
coded_stream_unittest.cc:136
zmq::errno_to_string
const char * errno_to_string(int errno_)
Definition:
err.cpp:7
zmq::print_backtrace
void print_backtrace()
Definition:
err.cpp:422
assert.h
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:51