Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 427 lines (371 sloc) 13.742 kb
b85b710 Update copyright statements to reflect the facts that:
Nick Mathewson authored
1 /*
e49e289 Update copyright notices to 2012
Nick Mathewson authored
2 * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
b85b710 Update copyright statements to reflect the facts that:
Nick Mathewson authored
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
3f8c7cd Convert include-guard macro convention to avoid reserved identifiers
Nick Mathewson authored
26 #ifndef UTIL_INTERNAL_H_INCLUDED_
27 #define UTIL_INTERNAL_H_INCLUDED_
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
28
ec347b9 Move event-config.h to include/event2
Nick Mathewson authored
29 #include "event2/event-config.h"
0915ca0 @kev009 Include evconfig-private.h in internal files for great good.
kev009 authored
30 #include "evconfig-private.h"
31
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
32 #include <errno.h>
33
37c3456 Add an EVUTIL_ASSERT() to replace our calls to assert().
Nick Mathewson authored
34 /* For EVUTIL_ASSERT */
35 #include "log-internal.h"
36 #include <stdio.h>
37 #include <stdlib.h>
68120d9 Convert event-config.h macros to avoid reserved identifiers
Nick Mathewson authored
38 #ifdef EVENT__HAVE_SYS_SOCKET_H
0b9eb1b Add a bufferevent function to resolve a name then connect to it.
Nick Mathewson authored
39 #include <sys/socket.h>
40 #endif
68120d9 Convert event-config.h macros to avoid reserved identifiers
Nick Mathewson authored
41 #ifdef EVENT__HAVE_SYS_EVENTFD_H
a1c042b Infrastructure for using faster/fewer syscalls when creating sockets
Nick Mathewson authored
42 #include <sys/eventfd.h>
43 #endif
47bad8a Implement size limits on HTTP header length and body length.
Nick Mathewson authored
44 #include "event2/util.h"
37c3456 Add an EVUTIL_ASSERT() to replace our calls to assert().
Nick Mathewson authored
45
713c254 Try to build correctly on platforms with no IPv6 support
Nick Mathewson authored
46 #include "ipv6-internal.h"
47
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
ebf2945 Compilation fixes for vc++ 2008 express. Not the end of them.
Nick Mathewson authored
52 /* If we need magic to say "inline", get it for free internally. */
68120d9 Convert event-config.h macros to avoid reserved identifiers
Nick Mathewson authored
53 #ifdef EVENT__inline
54 #define inline EVENT__inline
ebf2945 Compilation fixes for vc++ 2008 express. Not the end of them.
Nick Mathewson authored
55 #endif
68120d9 Convert event-config.h macros to avoid reserved identifiers
Nick Mathewson authored
56 #ifdef EVENT____func__
57 #define __func__ EVENT____func__
ebf2945 Compilation fixes for vc++ 2008 express. Not the end of them.
Nick Mathewson authored
58 #endif
59
661b5ee Actually, move EVUTIL_NIL_STMT to util-internal.h
Nick Mathewson authored
60 /* A good no-op to use in macro definitions. */
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
61 #define EVUTIL_NIL_STMT_ ((void)0)
cb8059d Fix compilation on Windows with NDEBUG
Nick Mathewson authored
62 /* A no-op that tricks the compiler into thinking a condition is used while
63 * definitely not making any code for it. Used to compile out asserts while
64 * avoiding "unused variable" warnings. The "!" forces the compiler to
65 * do the sizeof() on an int, in case "condition" is a bitfield value.
66 */
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
67 #define EVUTIL_NIL_CONDITION_(condition) do { \
cb8059d Fix compilation on Windows with NDEBUG
Nick Mathewson authored
68 (void)sizeof(!(condition)); \
b63ab17 EVUTIL_ASSERT: Use sizeof() to avoid "unused variable" warnings.
Evan Jones authored
69 } while(0)
661b5ee Actually, move EVUTIL_NIL_STMT to util-internal.h
Nick Mathewson authored
70
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
71 /* Internal use only: macros to match patterns of error codes in a
72 cross-platform way. We need these macros because of two historical
73 reasons: first, nonblocking IO functions are generally written to give an
74 error on the "blocked now, try later" case, so sometimes an error from a
75 read, write, connect, or accept means "no error; just wait for more
76 data," and we need to look at the error code. Second, Windows defines
77 a different set of error codes for sockets. */
78
9f560bf Use "_WIN32", not WIN32: it's standard and we don't need to fake it
Nick Mathewson authored
79 #ifndef _WIN32
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
80
81 /* True iff e is an error that means a read/write operation can be retried. */
82 #define EVUTIL_ERR_RW_RETRIABLE(e) \
83 ((e) == EINTR || (e) == EAGAIN)
7bc48bf deal with connect() failing immediately
Niels Provos authored
84 /* True iff e is an error that means an connect can be retried. */
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
85 #define EVUTIL_ERR_CONNECT_RETRIABLE(e) \
86 ((e) == EINTR || (e) == EINPROGRESS)
7bc48bf deal with connect() failing immediately
Niels Provos authored
87 /* True iff e is an error that means a accept can be retried. */
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
88 #define EVUTIL_ERR_ACCEPT_RETRIABLE(e) \
89 ((e) == EINTR || (e) == EAGAIN || (e) == ECONNABORTED)
90
7bc48bf deal with connect() failing immediately
Niels Provos authored
91 /* True iff e is an error that means the connection was refused */
92 #define EVUTIL_ERR_CONNECT_REFUSED(e) \
93 ((e) == ECONNREFUSED)
94
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
95 #else
96
bbd6a33 reindent macros in util-internal.h
Nick Mathewson authored
97 #define EVUTIL_ERR_RW_RETRIABLE(e) \
98 ((e) == WSAEWOULDBLOCK || \
99 (e) == WSAEINTR)
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
100
bbd6a33 reindent macros in util-internal.h
Nick Mathewson authored
101 #define EVUTIL_ERR_CONNECT_RETRIABLE(e) \
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
102 ((e) == WSAEWOULDBLOCK || \
bbd6a33 reindent macros in util-internal.h
Nick Mathewson authored
103 (e) == WSAEINTR || \
104 (e) == WSAEINPROGRESS || \
105 (e) == WSAEINVAL)
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
106
107 #define EVUTIL_ERR_ACCEPT_RETRIABLE(e) \
108 EVUTIL_ERR_RW_RETRIABLE(e)
109
7bc48bf deal with connect() failing immediately
Niels Provos authored
110 #define EVUTIL_ERR_CONNECT_REFUSED(e) \
111 ((e) == WSAECONNREFUSED)
112
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
113 #endif
114
145f221 Define symbolic constants to use in place of SHUT_RD etc
Nick Mathewson authored
115 /* Arguments for shutdown() */
116 #ifdef SHUT_RD
117 #define EVUTIL_SHUT_RD SHUT_RD
118 #else
119 #define EVUTIL_SHUT_RD 0
120 #endif
121 #ifdef SHUT_WR
122 #define EVUTIL_SHUT_WR SHUT_WR
123 #else
124 #define EVUTIL_SHUT_WR 1
125 #endif
126 #ifdef SHUT_BOTH
127 #define EVUTIL_SHUT_BOTH SHUT_BOTH
128 #else
129 #define EVUTIL_SHUT_BOTH 2
130 #endif
131
c89b4e6 Refactor the functions that run over every event.
Nick Mathewson authored
132 /* Helper: Verify that all the elements in 'dlist' are internally consistent.
133 * Checks for circular lists and bad prev/next pointers.
134 *
135 * Example usage:
136 * EVUTIL_ASSERT_LIST_OK(eventlist, event, ev_next);
137 */
138 #define EVUTIL_ASSERT_LIST_OK(dlist, type, field) do { \
139 struct type *elm1, *elm2, **nextp; \
140 if (LIST_EMPTY((dlist))) \
141 break; \
142 \
143 /* Check list for circularity using Floyd's */ \
144 /* 'Tortoise and Hare' algorithm */ \
145 elm1 = LIST_FIRST((dlist)); \
146 elm2 = LIST_NEXT(elm1, field); \
147 while (elm1 && elm2) { \
148 EVUTIL_ASSERT(elm1 != elm2); \
149 elm1 = LIST_NEXT(elm1, field); \
150 elm2 = LIST_NEXT(elm2, field); \
151 if (!elm2) \
152 break; \
153 EVUTIL_ASSERT(elm1 != elm2); \
154 elm2 = LIST_NEXT(elm2, field); \
155 } \
156 \
157 /* Now check next and prev pointers for consistency. */ \
158 nextp = &LIST_FIRST((dlist)); \
159 elm1 = LIST_FIRST((dlist)); \
160 while (elm1) { \
161 EVUTIL_ASSERT(*nextp == elm1); \
162 EVUTIL_ASSERT(nextp == elm1->field.le_prev); \
163 nextp = &LIST_NEXT(elm1, field); \
164 elm1 = *nextp; \
165 } \
166 } while (0)
167
168 /* Helper: Verify that all the elements in a TAILQ are internally consistent.
169 * Checks for circular lists and bad prev/next pointers.
170 *
171 * Example usage:
172 * EVUTIL_ASSERT_TAILQ_OK(activelist, event, ev_active_next);
173 */
174 #define EVUTIL_ASSERT_TAILQ_OK(tailq, type, field) do { \
175 struct type *elm1, *elm2, **nextp; \
176 if (TAILQ_EMPTY((tailq))) \
177 break; \
178 \
179 /* Check list for circularity using Floyd's */ \
180 /* 'Tortoise and Hare' algorithm */ \
181 elm1 = TAILQ_FIRST((tailq)); \
182 elm2 = TAILQ_NEXT(elm1, field); \
183 while (elm1 && elm2) { \
184 EVUTIL_ASSERT(elm1 != elm2); \
185 elm1 = TAILQ_NEXT(elm1, field); \
186 elm2 = TAILQ_NEXT(elm2, field); \
187 if (!elm2) \
188 break; \
189 EVUTIL_ASSERT(elm1 != elm2); \
190 elm2 = TAILQ_NEXT(elm2, field); \
191 } \
192 \
193 /* Now check next and prev pointers for consistency. */ \
194 nextp = &TAILQ_FIRST((tailq)); \
195 elm1 = TAILQ_FIRST((tailq)); \
196 while (elm1) { \
197 EVUTIL_ASSERT(*nextp == elm1); \
198 EVUTIL_ASSERT(nextp == elm1->field.tqe_prev); \
199 nextp = &TAILQ_NEXT(elm1, field); \
200 elm1 = *nextp; \
201 } \
202 EVUTIL_ASSERT(nextp == (tailq)->tqh_last); \
203 } while (0)
204
cd731b7 Do not use ctypes functions in cases when we need the "net" locale.
Nick Mathewson authored
205 /* Locale-independent replacements for some ctypes functions. Use these
206 * when you care about ASCII's notion of character types, because you are about
207 * to send those types onto the wire.
208 */
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
209 int EVUTIL_ISALPHA_(char c);
210 int EVUTIL_ISALNUM_(char c);
211 int EVUTIL_ISSPACE_(char c);
212 int EVUTIL_ISDIGIT_(char c);
213 int EVUTIL_ISXDIGIT_(char c);
214 int EVUTIL_ISPRINT_(char c);
215 int EVUTIL_ISLOWER_(char c);
216 int EVUTIL_ISUPPER_(char c);
217 char EVUTIL_TOUPPER_(char c);
218 char EVUTIL_TOLOWER_(char c);
cd731b7 Do not use ctypes functions in cases when we need the "net" locale.
Nick Mathewson authored
219
838d0a8 Document many internal functions and pieces of code.
Nick Mathewson authored
220 /** Helper macro. If we know that a given pointer points to a field in a
221 structure, return a pointer to the structure itself. Used to implement
222 our half-baked C OO. Example:
223
224 struct subtype {
e5bbd40 Clean up formatting: use tabs, not 8-spaces, to indent.
Nick Mathewson authored
225 int x;
226 struct supertype common;
227 int y;
838d0a8 Document many internal functions and pieces of code.
Nick Mathewson authored
228 };
229 ...
230 void fn(struct supertype *super) {
e5bbd40 Clean up formatting: use tabs, not 8-spaces, to indent.
Nick Mathewson authored
231 struct subtype *sub = EVUTIL_UPCAST(super, struct subtype, common);
232 ...
838d0a8 Document many internal functions and pieces of code.
Nick Mathewson authored
233 }
234 */
0b47b12 Add a new EVUTIL_UPCAST macro so that I do not need to keep figuring out...
Nick Mathewson authored
235 #define EVUTIL_UPCAST(ptr, type, field) \
8283b2f Fix a major parenthesis bug in EVUTIL_UPCAST.
Nick Mathewson authored
236 ((type *)(((char*)(ptr)) - evutil_offsetof(type, field)))
0b47b12 Add a new EVUTIL_UPCAST macro so that I do not need to keep figuring out...
Nick Mathewson authored
237
03dce42 Tweak the evutil_open_closeonexec patch to work on windows, old unixes.
Nick Mathewson authored
238 /* As open(pathname, flags, mode), except that the file is always opened with
239 * the close-on-exec flag set. (And the mode argument is mandatory.)
240 */
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
241 int evutil_open_closeonexec_(const char *pathname, int flags, unsigned mode);
d2b5f72 @rosslagerwall Make uses of open() close-on-exec safe by introducing evutil_open_closeo...
authored
242
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
243 int evutil_read_file_(const char *filename, char **content_out, size_t *len_out,
0f7144f Refactor code from evdns into a new internal "read a file" function.
Nick Mathewson authored
244 int is_binary);
709c21c Bufferevent support for openssl.
Nick Mathewson authored
245
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
246 int evutil_socket_connect_(evutil_socket_t *fd_ptr, struct sockaddr *sa, int socklen);
709c21c Bufferevent support for openssl.
Nick Mathewson authored
247
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
248 int evutil_socket_finished_connecting_(evutil_socket_t fd);
25af695 When a bufferevent_connect() call fails, give the client an error callba...
Nick Mathewson authored
249
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
250 int evutil_ersatz_socketpair_(int, int , int, evutil_socket_t[]);
57b30cd Turn our socketpair() replacement into its own function
Nick Mathewson authored
251
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
252 int evutil_resolve_(int family, const char *hostname, struct sockaddr *sa,
0b9eb1b Add a bufferevent function to resolve a name then connect to it.
Nick Mathewson authored
253 ev_socklen_t *socklen, int port);
254
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
255 const char *evutil_getenv_(const char *name);
629a613 When running set[ug]id, don't check the environment.
Nick Mathewson authored
256
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
257 long evutil_weakrand_(void);
165d30e Fix compilation of rate-limiting code on win32.
Nick Mathewson authored
258
37c3456 Add an EVUTIL_ASSERT() to replace our calls to assert().
Nick Mathewson authored
259 /* Evaluates to the same boolean value as 'p', and hints to the compiler that
260 * we expect this value to be false. */
09d39a1 Fix compilation with GCC 2, which had no __builtin_expect
Dave Hart authored
261 #if defined(__GNUC__) && __GNUC__ >= 3 /* gcc 3.0 or later */
37c3456 Add an EVUTIL_ASSERT() to replace our calls to assert().
Nick Mathewson authored
262 #define EVUTIL_UNLIKELY(p) __builtin_expect(!!(p),0)
263 #else
264 #define EVUTIL_UNLIKELY(p) (p)
265 #endif
266
267 /* Replacement for assert() that calls event_errx on failure. */
743f866 Honor NDEBUG; build without warnings with NDEBUG; make NDEBUG always-off...
Nick Mathewson authored
268 #ifdef NDEBUG
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
269 #define EVUTIL_ASSERT(cond) EVUTIL_NIL_CONDITION_(cond)
743f866 Honor NDEBUG; build without warnings with NDEBUG; make NDEBUG always-off...
Nick Mathewson authored
270 #define EVUTIL_FAILURE_CHECK(cond) 0
271 #else
37c3456 Add an EVUTIL_ASSERT() to replace our calls to assert().
Nick Mathewson authored
272 #define EVUTIL_ASSERT(cond) \
273 do { \
274 if (EVUTIL_UNLIKELY(!(cond))) { \
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
275 event_errx(EVENT_ERR_ABORT_, \
37c3456 Add an EVUTIL_ASSERT() to replace our calls to assert().
Nick Mathewson authored
276 "%s:%d: Assertion %s failed in %s", \
277 __FILE__,__LINE__,#cond,__func__); \
8fdf09c Clean up formatting: Disallow space-before-tab.
Nick Mathewson authored
278 /* In case a user-supplied handler tries to */ \
37c3456 Add an EVUTIL_ASSERT() to replace our calls to assert().
Nick Mathewson authored
279 /* return control to us, log and abort here. */ \
280 (void)fprintf(stderr, \
281 "%s:%d: Assertion %s failed in %s", \
282 __FILE__,__LINE__,#cond,__func__); \
283 abort(); \
284 } \
2c2618d more whitespace normalization
Nick Mathewson authored
285 } while (0)
743f866 Honor NDEBUG; build without warnings with NDEBUG; make NDEBUG always-off...
Nick Mathewson authored
286 #define EVUTIL_FAILURE_CHECK(cond) EVUTIL_UNLIKELY(cond)
287 #endif
37c3456 Add an EVUTIL_ASSERT() to replace our calls to assert().
Nick Mathewson authored
288
68120d9 Convert event-config.h macros to avoid reserved identifiers
Nick Mathewson authored
289 #ifndef EVENT__HAVE_STRUCT_SOCKADDR_STORAGE
9184563 Build correctly on platforms without sockaddr_storage
Nick Mathewson authored
290 /* Replacement for sockaddr storage that we can use internally on platforms
291 * that lack it. It is not space-efficient, but neither is sockaddr_storage.
292 */
293 struct sockaddr_storage {
294 union {
295 struct sockaddr ss_sa;
296 struct sockaddr_in ss_sin;
297 struct sockaddr_in6 ss_sin6;
298 char ss_padding[128];
299 } ss_union;
300 };
301 #define ss_family ss_union.ss_sa.sa_family
302 #endif
303
86f5742 Add two implementations of getaddrinfo: one blocking and one nonblocking...
Nick Mathewson authored
304 /* Internal addrinfo error code. This one is returned from only from
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
305 * evutil_getaddrinfo_common_, when we are sure that we'll have to hit a DNS
86f5742 Add two implementations of getaddrinfo: one blocking and one nonblocking...
Nick Mathewson authored
306 * server. */
307 #define EVUTIL_EAI_NEED_RESOLVE -90002
308
309 struct evdns_base;
310 struct evdns_getaddrinfo_request;
311 typedef struct evdns_getaddrinfo_request* (*evdns_getaddrinfo_fn)(
312 struct evdns_base *base,
313 const char *nodename, const char *servname,
314 const struct evutil_addrinfo *hints_in,
315 void (*cb)(int, struct evutil_addrinfo *, void *), void *arg);
316
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
317 void evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo_fn fn);
86f5742 Add two implementations of getaddrinfo: one blocking and one nonblocking...
Nick Mathewson authored
318
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
319 struct evutil_addrinfo *evutil_new_addrinfo_(struct sockaddr *sa,
86f5742 Add two implementations of getaddrinfo: one blocking and one nonblocking...
Nick Mathewson authored
320 ev_socklen_t socklen, const struct evutil_addrinfo *hints);
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
321 struct evutil_addrinfo *evutil_addrinfo_append_(struct evutil_addrinfo *first,
86f5742 Add two implementations of getaddrinfo: one blocking and one nonblocking...
Nick Mathewson authored
322 struct evutil_addrinfo *append);
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
323 void evutil_adjust_hints_for_addrconfig_(struct evutil_addrinfo *hints);
324 int evutil_getaddrinfo_common_(const char *nodename, const char *servname,
86f5742 Add two implementations of getaddrinfo: one blocking and one nonblocking...
Nick Mathewson authored
325 struct evutil_addrinfo *hints, struct evutil_addrinfo **res, int *portnum);
326
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
327 int evutil_getaddrinfo_async_(struct evdns_base *dns_base,
86f5742 Add two implementations of getaddrinfo: one blocking and one nonblocking...
Nick Mathewson authored
328 const char *nodename, const char *servname,
329 const struct evutil_addrinfo *hints_in,
330 void (*cb)(int, struct evutil_addrinfo *, void *), void *arg);
331
8d4aaf9 Don't use a bind address for nameservers on loopback
Nick Mathewson authored
332 /** Return true iff sa is a looback address. (That is, it is 127.0.0.1/8, or
333 * ::1). */
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
334 int evutil_sockaddr_is_loopback_(const struct sockaddr *sa);
8d4aaf9 Don't use a bind address for nameservers on loopback
Nick Mathewson authored
335
b1c7950 Make evdns logging threadsafe
Nick Mathewson authored
336
337 /**
338 Formats a sockaddr sa into a string buffer of size outlen stored in out.
339 Returns a pointer to out. Always writes something into out, so it's safe
340 to use the output of this function without checking it for NULL.
341 */
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
342 const char *evutil_format_sockaddr_port_(const struct sockaddr *sa, char *out, size_t outlen);
b1c7950 Make evdns logging threadsafe
Nick Mathewson authored
343
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
344 long evutil_tv_to_msec_(const struct timeval *tv);
850c3ff @chris-davis Add evutil_tv_to_msec for safe conversion of timevals to milliseconds.
chris-davis authored
345
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
346 int evutil_hex_char_to_int_(char c);
20fda29 Try /proc on Linux as entropy fallback; use sysctl as last resort
Nick Mathewson authored
347
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
348 void evutil_usleep_(const struct timeval *tv);
f25d9d3 Add an (internal) usleep function for use by unit tests
Nick Mathewson authored
349
041ca00 Add a new libevent_global_shutdown() to free all globals before exiting.
Mark Ellzey authored
350 void evutil_free_secure_rng_globals_(void);
351 void evutil_free_globals_(void);
352
9f560bf Use "_WIN32", not WIN32: it's standard and we don't need to fake it
Nick Mathewson authored
353 #ifdef _WIN32
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
354 HANDLE evutil_load_windows_system_library_(const TCHAR *library_name);
d49b5e3 Do not search outside of the system directory for windows DLLs
Nick Mathewson authored
355 #endif
356
3203f88 Use the correct printf args when formatting size_t
Nick Mathewson authored
357 #ifndef EV_SIZE_FMT
358 #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
359 #define EV_U64_FMT "%I64u"
360 #define EV_I64_FMT "%I64d"
361 #define EV_I64_ARG(x) ((__int64)(x))
362 #define EV_U64_ARG(x) ((unsigned __int64)(x))
363 #else
364 #define EV_U64_FMT "%llu"
365 #define EV_I64_FMT "%lld"
366 #define EV_I64_ARG(x) ((long long)(x))
367 #define EV_U64_ARG(x) ((unsigned long long)(x))
368 #endif
369 #endif
370
371 #if defined(__STDC__) && defined(__STDC_VERSION__)
372 #if (__STDC_VERSION__ >= 199901L)
373 #define EV_SIZE_FMT "%zu"
374 #define EV_SSIZE_FMT "%zd"
375 #define EV_SIZE_ARG(x) (x)
376 #define EV_SSIZE_ARG(x) (x)
377 #endif
378 #endif
379
380 #ifndef EV_SIZE_FMT
68120d9 Convert event-config.h macros to avoid reserved identifiers
Nick Mathewson authored
381 #if (EVENT__SIZEOF_SIZE_T <= EVENT__SIZEOF_LONG)
3203f88 Use the correct printf args when formatting size_t
Nick Mathewson authored
382 #define EV_SIZE_FMT "%lu"
383 #define EV_SSIZE_FMT "%ld"
384 #define EV_SIZE_ARG(x) ((unsigned long)(x))
385 #define EV_SSIZE_ARG(x) ((long)(x))
386 #else
387 #define EV_SIZE_FMT EV_U64_FMT
388 #define EV_SSIZE_FMT EV_I64_FMT
389 #define EV_SIZE_ARG(x) EV_U64_ARG(x)
390 #define EV_SSIZE_ARG(x) EV_I64_ARG(x)
391 #endif
392 #endif
393
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
394 evutil_socket_t evutil_socket_(int domain, int type, int protocol);
395 evutil_socket_t evutil_accept4_(evutil_socket_t sockfd, struct sockaddr *addr,
ca47fa0 evutil_accept4() should take ev_socklen_t
Nick Mathewson authored
396 ev_socklen_t *addrlen, int flags);
8ac3c4c Have all visible internal function names end with an underscore.
Nick Mathewson authored
397 int evutil_make_internal_pipe_(evutil_socket_t fd[2]);
398 evutil_socket_t evutil_eventfd_(unsigned initval, int flags);
a1c042b Infrastructure for using faster/fewer syscalls when creating sockets
Nick Mathewson authored
399
400 #ifdef SOCK_NONBLOCK
401 #define EVUTIL_SOCK_NONBLOCK SOCK_NONBLOCK
402 #else
403 #define EVUTIL_SOCK_NONBLOCK 0x4000000
404 #endif
405 #ifdef SOCK_CLOEXEC
406 #define EVUTIL_SOCK_CLOEXEC SOCK_CLOEXEC
407 #else
408 #define EVUTIL_SOCK_CLOEXEC 0x80000000
409 #endif
410 #ifdef EFD_NONBLOCK
411 #define EVUTIL_EFD_NONBLOCK EFD_NONBLOCK
412 #else
413 #define EVUTIL_EFD_NONBLOCK 0x4000
414 #endif
415 #ifdef EFD_CLOEXEC
416 #define EVUTIL_EFD_CLOEXEC EFD_CLOEXEC
417 #else
418 #define EVUTIL_EFD_CLOEXEC 0x8000
419 #endif
420
421
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
422 #ifdef __cplusplus
423 }
424 #endif
425
426 #endif
Something went wrong with that request. Please try again.