/* A good no-op to use in macro definitions. */ #define EVUTIL_NIL_STMT_ ((void)0) /* A no-op that tricks the compiler into thinking a condition is used while *definitelynotmakinganycodeforit.Usedtocompileoutassertswhile *avoiding"unusedvariable"warnings.The"!"forcesthecompilerto *dothesizeof()onanint,incase"condition"isabitfieldvalue.
*/ #define EVUTIL_NIL_CONDITION_(condition) do { \
(void)sizeof(!(condition)); \
} while(0)
/* Internal use only: macros to match patterns of error codes in a cross-platformway.Weneedthesemacrosbecauseoftwohistorical reasons:first,nonblockingIOfunctionsaregenerallywrittentogivean erroronthe"blockednow,trylater"case,sosometimesanerrorfroma read,write,connect,oracceptmeans"noerror;justwaitformore data,"andweneedtolookattheerrorcode.Second,Windowsdefines
a different set of error codes for sockets. */
/* True iff e is an error that means a read/write operation can be retried. */ #define EVUTIL_ERR_RW_RETRIABLE(e) \
((e) == EINTR || EVUTIL_ERR_IS_EAGAIN(e)) /* True iff e is an error that means an connect can be retried. */ #define EVUTIL_ERR_CONNECT_RETRIABLE(e) \
((e) == EINTR || (e) == EINPROGRESS) /* True iff e is an error that means a accept can be retried. */ #define EVUTIL_ERR_ACCEPT_RETRIABLE(e) \
((e) == EINTR || EVUTIL_ERR_IS_EAGAIN(e) || (e) == ECONNABORTED)
/* True iff e is an error that means the connection was refused */ #define EVUTIL_ERR_CONNECT_REFUSED(e) \
((e) == ECONNREFUSED)
/* Helper: Verify that all the elements in 'dlist' are internally consistent. *Checksforcircularlistsandbadprev/nextpointers. * *Exampleusage: *EVUTIL_ASSERT_LIST_OK(eventlist,event,ev_next);
*/ #define EVUTIL_ASSERT_LIST_OK(dlist, type, field) do { \ struct type *elm1, *elm2, **nextp; \ if (LIST_EMPTY((dlist))) \ break; \
\ /* Check list for circularity using Floyd's */ \ /* 'Tortoise and Hare' algorithm */ \
elm1 = LIST_FIRST((dlist)); \
elm2 = LIST_NEXT(elm1, field); \ while (elm1 && elm2) { \
EVUTIL_ASSERT(elm1 != elm2); \
elm1 = LIST_NEXT(elm1, field); \
elm2 = LIST_NEXT(elm2, field); \ if (!elm2) \ break; \
EVUTIL_ASSERT(elm1 != elm2); \
elm2 = LIST_NEXT(elm2, field); \
} \
\ /* Now check next and prev pointers for consistency. */ \
nextp = &LIST_FIRST((dlist)); \
elm1 = LIST_FIRST((dlist)); \ while (elm1) { \
EVUTIL_ASSERT(*nextp == elm1); \
EVUTIL_ASSERT(nextp == elm1->field.le_prev); \
nextp = &LIST_NEXT(elm1, field); \
elm1 = *nextp; \
} \
} while (0)
/* Helper: Verify that all the elements in a TAILQ are internally consistent. *Checksforcircularlistsandbadprev/nextpointers. * *Exampleusage: *EVUTIL_ASSERT_TAILQ_OK(activelist,event,ev_active_next);
*/ #define EVUTIL_ASSERT_TAILQ_OK(tailq, type, field) do { \ struct type *elm1, *elm2, **nextp; \ if (TAILQ_EMPTY((tailq))) \ break; \
\ /* Check list for circularity using Floyd's */ \ /* 'Tortoise and Hare' algorithm */ \
elm1 = TAILQ_FIRST((tailq)); \
elm2 = TAILQ_NEXT(elm1, field); \ while (elm1 && elm2) { \
EVUTIL_ASSERT(elm1 != elm2); \
elm1 = TAILQ_NEXT(elm1, field); \
elm2 = TAILQ_NEXT(elm2, field); \ if (!elm2) \ break; \
EVUTIL_ASSERT(elm1 != elm2); \
elm2 = TAILQ_NEXT(elm2, field); \
} \
\ /* Now check next and prev pointers for consistency. */ \
nextp = &TAILQ_FIRST((tailq)); \
elm1 = TAILQ_FIRST((tailq)); \ while (elm1) { \
EVUTIL_ASSERT(*nextp == elm1); \
EVUTIL_ASSERT(nextp == elm1->field.tqe_prev); \
nextp = &TAILQ_NEXT(elm1, field); \
elm1 = *nextp; \
} \
EVUTIL_ASSERT(nextp == (tailq)->tqh_last); \
} while (0)
/* Locale-independent replacements for some ctypes functions. Use these *whenyoucareaboutASCII'snotionofcharactertypes,becauseyouareabout *tosendthosetypesontothewire.
*/
EVENT2_EXPORT_SYMBOL int EVUTIL_ISALPHA_(char c);
EVENT2_EXPORT_SYMBOL int EVUTIL_ISALNUM_(char c); int EVUTIL_ISSPACE_(char c);
EVENT2_EXPORT_SYMBOL int EVUTIL_ISDIGIT_(char c);
EVENT2_EXPORT_SYMBOL int EVUTIL_ISXDIGIT_(char c); int EVUTIL_ISPRINT_(char c); int EVUTIL_ISLOWER_(char c); int EVUTIL_ISUPPER_(char c);
EVENT2_EXPORT_SYMBOL char EVUTIL_TOUPPER_(char c);
EVENT2_EXPORT_SYMBOL char EVUTIL_TOLOWER_(char c);
/** Remove all trailing horizontal whitespace (space or tab) from the end of a
* string */
EVENT2_EXPORT_SYMBOL void evutil_rtrim_lws_(char *);
/** Helper macro. If we know that a given pointer points to a field in a structure,returnapointertothestructureitself.Usedtoimplement ourhalf-bakedCOO.Example:
/* As open(pathname, flags, mode), except that the file is always opened with *theclose-on-execflagset.(Andthemodeargumentismandatory.)
*/ int evutil_open_closeonexec_(constchar *pathname, int flags, unsigned mode);
EVENT2_EXPORT_SYMBOL int evutil_read_file_(constchar *filename, char **content_out, size_t *len_out, int is_binary);
EVENT2_EXPORT_SYMBOL int evutil_socket_connect_(evutil_socket_t *fd_ptr, conststruct sockaddr *sa, int socklen);
int evutil_socket_finished_connecting_(evutil_socket_t fd);
EVENT2_EXPORT_SYMBOL int evutil_ersatz_socketpair_(int, int , int, evutil_socket_t[]);
int evutil_resolve_(int family, constchar *hostname, struct sockaddr *sa,
ev_socklen_t *socklen, int port);
constchar *evutil_getenv_(constchar *name);
/* Structure to hold the state of our weak random number generator.
*/ struct evutil_weakrand_state {
ev_uint32_t seed;
};
#define EVUTIL_WEAKRAND_MAX EV_INT32_MAX
/* Initialize the state of a week random number generator based on 'seed'. If *theseedis0,constructanewseedbasedonnot-very-strongplatform *entropy,likethePIDandthetimeofday. * *Thisfunction,andtheotherevutil_weakrand*functions,aremeantfor *speed,notsecurityorstatisticalstrength.IfyouneedaRNGwhichan *attackercan'tpredict,orwhichpassesstrongstatisticaltests,usethe *evutil_secure_rng*functionsinstead.
*/
EVENT2_EXPORT_SYMBOL
ev_uint32_t evutil_weakrand_seed_(struct evutil_weakrand_state *state, ev_uint32_t seed); /* Return a pseudorandom value between 0 and EVUTIL_WEAKRAND_MAX inclusive. *Updatesthestatein'seed'asneeded--thisvaluemustbeprotectedbya *lock.
*/
EVENT2_EXPORT_SYMBOL
ev_int32_t evutil_weakrand_(struct evutil_weakrand_state *seed); /* Return a pseudorandom value x such that 0 <= x < top. top must be no more *thanEVUTIL_WEAKRAND_MAX.Updatesthestatein'seed'asneeded--this
* value must be proteced by a lock */
EVENT2_EXPORT_SYMBOL
ev_int32_t evutil_weakrand_range_(struct evutil_weakrand_state *seed, ev_int32_t top);
/* Evaluates to the same boolean value as 'p', and hints to the compiler that
* we expect this value to be false. */ #ifdefined(__GNUC__) && __GNUC__ >= 3/* gcc 3.0 or later */ #define EVUTIL_UNLIKELY(p) __builtin_expect(!!(p),0) #else #define EVUTIL_UNLIKELY(p) (p) #endif
/* Replacement for assert() that calls event_errx on failure. */ #ifdef NDEBUG #define EVUTIL_ASSERT(cond) EVUTIL_NIL_CONDITION_(cond) #define EVUTIL_FAILURE_CHECK(cond) 0 #else #define EVUTIL_ASSERT(cond) \ do { \ if (EVUTIL_UNLIKELY(!(cond))) { \
event_errx(EVENT_ERR_ABORT_, \ "%s:%d: Assertion %s failed in %s", \
__FILE__,__LINE__,#cond,__func__); \ /* In case a user-supplied handler tries to */ \ /* return control to us, log and abort here. */ \
(void)fprintf(stderr, \ "%s:%d: Assertion %s failed in %s", \
__FILE__,__LINE__,#cond,__func__); \
abort(); \
} \
} while (0) #define EVUTIL_FAILURE_CHECK(cond) EVUTIL_UNLIKELY(cond) #endif
#ifndef EVENT__HAVE_STRUCT_SOCKADDR_STORAGE /* Replacement for sockaddr storage that we can use internally on platforms *thatlackit.Itisnotspace-efficient,butneitherissockaddr_storage.
*/ struct sockaddr_storage { union { struct sockaddr ss_sa; struct sockaddr_in ss_sin; struct sockaddr_in6 ss_sin6; char ss_padding[128];
} ss_union;
}; #define ss_family ss_union.ss_sa.sa_family #endif
/* Internal addrinfo error code. This one is returned from only from *evutil_getaddrinfo_common_,whenwearesurethatwe'llhavetohitaDNS
* server. */ #define EVUTIL_EAI_NEED_RESOLVE -90002
/** Return true iff sa is a looback address. (That is, it is 127.0.0.1/8, or
* ::1). */
EVENT2_EXPORT_SYMBOL int evutil_sockaddr_is_loopback_(conststruct sockaddr *sa);
EVENT2_EXPORT_SYMBOL
evutil_socket_t evutil_socket_(int domain, int type, int protocol);
evutil_socket_t evutil_accept4_(evutil_socket_t sockfd, struct sockaddr *addr,
ev_socklen_t *addrlen, int flags);
/* used by one of the test programs.. */
EVENT2_EXPORT_SYMBOL int evutil_make_internal_pipe_(evutil_socket_t fd[2]);
evutil_socket_t evutil_eventfd_(unsigned initval, int flags);
/* This is a any, loopback, link-local, multicast */
EVENT2_EXPORT_SYMBOL int evutil_v4addr_is_local_(conststruct in_addr *in); /* This is a reserved, ipv4compat, ipv4map, loopback,
* link-local, multicast, or unspecified address. */
EVENT2_EXPORT_SYMBOL int evutil_v6addr_is_local_(conststruct in6_addr *in);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.