Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 127 lines (109 sloc) 4.721 kb
b85b710 Update copyright statements to reflect the facts that:
Nick Mathewson authored
1 /*
2 * Copyright (c) 2007-2009 Niels Provos and Nick Mathewson
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 */
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
26 #ifndef _EVENT_UTIL_INTERNAL_H
27 #define _EVENT_UTIL_INTERNAL_H
28
29 #include "event-config.h"
30 #include <errno.h>
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
661b5ee Actually, move EVUTIL_NIL_STMT to util-internal.h
Nick Mathewson authored
36 /* A good no-op to use in macro definitions. */
37 #define _EVUTIL_NIL_STMT ((void)0)
38
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
39 /* Internal use only: macros to match patterns of error codes in a
40 cross-platform way. We need these macros because of two historical
41 reasons: first, nonblocking IO functions are generally written to give an
42 error on the "blocked now, try later" case, so sometimes an error from a
43 read, write, connect, or accept means "no error; just wait for more
44 data," and we need to look at the error code. Second, Windows defines
45 a different set of error codes for sockets. */
46
47 #ifndef WIN32
48
49 /* True iff e is an error that means a read/write operation can be retried. */
50 #define EVUTIL_ERR_RW_RETRIABLE(e) \
51 ((e) == EINTR || (e) == EAGAIN)
52 /* True iff e is an error that means an accept can be retried. */
53 #define EVUTIL_ERR_CONNECT_RETRIABLE(e) \
54 ((e) == EINTR || (e) == EINPROGRESS)
55 /* True iff e is an error that means a connect can be retried. */
56 #define EVUTIL_ERR_ACCEPT_RETRIABLE(e) \
57 ((e) == EINTR || (e) == EAGAIN || (e) == ECONNABORTED)
58
59 #else
60
bbd6a33 reindent macros in util-internal.h
Nick Mathewson authored
61 #define EVUTIL_ERR_RW_RETRIABLE(e) \
62 ((e) == WSAEWOULDBLOCK || \
63 (e) == WSAEINTR)
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
64
bbd6a33 reindent macros in util-internal.h
Nick Mathewson authored
65 #define EVUTIL_ERR_CONNECT_RETRIABLE(e) \
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
66 ((e) == WSAEWOULDBLOCK || \
bbd6a33 reindent macros in util-internal.h
Nick Mathewson authored
67 (e) == WSAEINTR || \
68 (e) == WSAEINPROGRESS || \
69 (e) == WSAEINVAL)
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
70
71 #define EVUTIL_ERR_ACCEPT_RETRIABLE(e) \
72 EVUTIL_ERR_RW_RETRIABLE(e)
73
74 #endif
75
7dd362b Have util-internal.h define socklen_t if we need it, and include it a…
Nick Mathewson authored
76 #ifdef _EVENT_socklen_t
77 #define socklen_t _EVENT_socklen_t
78 #endif
79
cd731b7 Do not use ctypes functions in cases when we need the "net" locale.
Nick Mathewson authored
80 /* Locale-independent replacements for some ctypes functions. Use these
81 * when you care about ASCII's notion of character types, because you are about
82 * to send those types onto the wire.
83 */
84 #define DECLARE_CTYPE_FN(name) \
85 static int EVUTIL_##name(char c); \
86 extern const ev_uint32_t EVUTIL_##name##_TABLE[]; \
87 static inline int EVUTIL_##name(char c) { \
88 ev_uint8_t u = c; \
89 return !!(EVUTIL_##name##_TABLE[(u >> 5) & 7] & (1 << (u & 31))); \
90 }
91 DECLARE_CTYPE_FN(ISALPHA)
92 DECLARE_CTYPE_FN(ISALNUM)
93 DECLARE_CTYPE_FN(ISSPACE)
94 DECLARE_CTYPE_FN(ISDIGIT)
95 DECLARE_CTYPE_FN(ISXDIGIT)
96 DECLARE_CTYPE_FN(ISPRINT)
97 DECLARE_CTYPE_FN(ISLOWER)
98 DECLARE_CTYPE_FN(ISUPPER)
99 extern const char EVUTIL_TOUPPER_TABLE[];
100 extern const char EVUTIL_TOLOWER_TABLE[];
101 #define EVUTIL_TOLOWER(c) (EVUTIL_TOLOWER_TABLE[(ev_uint8_t)c])
102 #define EVUTIL_TOUPPER(c) (EVUTIL_TOUPPER_TABLE[(ev_uint8_t)c])
103
838d0a8 Document many internal functions and pieces of code.
Nick Mathewson authored
104 /** Helper macro. If we know that a given pointer points to a field in a
105 structure, return a pointer to the structure itself. Used to implement
106 our half-baked C OO. Example:
107
108 struct subtype {
109 int x;
110 struct supertype common;
111 int y;
112 };
113 ...
114 void fn(struct supertype *super) {
115 struct subtype *sub = EVUTIL_UPCAST(super, struct subtype, common);
116 ...
117 }
118 */
0b47b12 Add a new EVUTIL_UPCAST macro so that I do not need to keep figuring …
Nick Mathewson authored
119 #define EVUTIL_UPCAST(ptr, type, field) \
120 ((type *)((char*)ptr) - evutil_offsetof(type, field))
121
5ebd23a New EVUTIL_ERR_*_RETRIABLE macros to tell if an errno blocked or failed.
Nick Mathewson authored
122 #ifdef __cplusplus
123 }
124 #endif
125
126 #endif
Something went wrong with that request. Please try again.