evutil(3) | Library Functions Manual | evutil(3) |
#include <event2/util.h>
#include <event2/visibility.h>
#include <event2/event-config.h>
#include <stdarg.h>
#include <sys/socket.h>
#include <time.h>
Standard integer types.
Integer type definitions for types that are supposed to be defined in the
C99-specified stdint.h.
Shamefully, some platforms do not include stdint.h, so we need to replace it. (If you are on a platform like this, your C headers are now over 10 years out of date. You should bug them to do something about this.)
We define:
#define ev_uint64_t ...
#define ev_int64_t ...
#define ev_uint32_t ...
#define ev_int32_t ...
#define ev_uint16_t ...
#define ev_int16_t ...
#define ev_uint8_t ...
#define ev_int8_t ...
#define ev_uintptr_t ev_uint32_t
#define ev_intptr_t ev_int32_t
#define ev_ssize_t ssize_t
#define ev_off_t ...
Limits for integer types
These macros hold the largest or smallest values possible for the ev_[u]int*_t
types.
#define EV_UINT64_MAX ((((ev_uint64_t)0xffffffffUL) << 32) |
0xffffffffUL)
#define EV_INT64_MAX ((((ev_int64_t) 0x7fffffffL) << 32) |
0xffffffffL)
#define EV_INT64_MIN ((-EV_INT64_MAX) - 1)
#define EV_UINT32_MAX ((ev_uint32_t)0xffffffffUL)
#define EV_INT32_MAX ((ev_int32_t) 0x7fffffffL)
#define EV_INT32_MIN ((-EV_INT32_MAX) - 1)
#define EV_UINT16_MAX ((ev_uint16_t)0xffffUL)
#define EV_INT16_MAX ((ev_int16_t) 0x7fffL)
#define EV_INT16_MIN ((-EV_INT16_MAX) - 1)
#define EV_UINT8_MAX 255
#define EV_INT8_MAX 127
#define EV_INT8_MIN ((-EV_INT8_MAX) - 1)
Limits for SIZE_T and SSIZE_T
#define EV_SIZE_MAX ...
#define EV_SSIZE_MAX ...
#define EV_SSIZE_MIN ((-EV_SSIZE_MAX) - 1)
Socket error functions
These functions are needed for making programs compatible between Windows and
Unix-like platforms.
You see, Winsock handles socket errors differently from the rest of the world. Elsewhere, a socket error is like any other error and is stored in errno. But winsock functions require you to retrieve the error with a special function, and don't let you use strerror for the error codes. And handling EWOULDBLOCK is ... different.
#define EVUTIL_SOCKET_ERROR() ...
Return the most recent socket error. #define
EVUTIL_SET_SOCKET_ERROR(errcode) ...
Replace the most recent socket error with errcode. #define
evutil_socket_geterror(sock) ...
Return the most recent socket error to occur on sock. #define
evutil_socket_error_to_string(errcode) ...
Convert a socket error to a string.
Manipulation macros for struct timeval.
We define replacements for timeradd, timersub, timerclear, timercmp, and
timerisset.
#define evutil_timeradd(tvp, uvp, vvp)
#define evutil_timersub(tvp, uvp, vvp)
#define evutil_timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
evutil_getaddrinfo() error codes
These values are possible error codes for evutil_getaddrinfo() and
related functions.
#define EVUTIL_EAI_ADDRFAMILY -901
#define EVUTIL_EAI_AGAIN -902
#define EVUTIL_EAI_BADFLAGS -903
#define EVUTIL_EAI_FAIL -904
#define EVUTIL_EAI_FAMILY -905
#define EVUTIL_EAI_MEMORY -906
#define EVUTIL_EAI_NODATA -907
#define EVUTIL_EAI_NONAME -908
#define EVUTIL_EAI_SERVICE -909
#define EVUTIL_EAI_SOCKTYPE -910
#define EVUTIL_EAI_SYSTEM -911
#define EVUTIL_EAI_CANCEL -90001
#define EVUTIL_AI_PASSIVE 0x1000
#define EVUTIL_AI_CANONNAME 0x2000
#define EVUTIL_AI_NUMERICHOST 0x4000
#define EVUTIL_AI_NUMERICSERV 0x8000
#define EVUTIL_AI_V4MAPPED 0x10000
#define EVUTIL_AI_ALL 0x20000
#define EVUTIL_AI_ADDRCONFIG 0x40000
do { (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; if ((vvp)->tv_usec >= 1000000) { (vvp)->tv_sec++; (vvp)->tv_usec -= 1000000; } } while (0)
(((tvp)->tv_sec == (uvp)->tv_sec) ? ((tvp)->tv_usec cmp (uvp)->tv_usec) : ((tvp)->tv_sec cmp (uvp)->tv_sec))
Return true iff the tvp is related to uvp according to the relational operator cmp. Recognized values for cmp are ==, <=, <, >=, and >.
do { (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; if ((vvp)->tv_usec < 0) { (vvp)->tv_sec--; (vvp)->tv_usec += 1000000; } } while (0)
Parameters:
Returns:
Limitations:
For a nonblocking variant, see evdns_getaddrinfo.
It is not safe to use this funtion on the same timer from multiple threads.
This differs from Windows's interpretation of 'reusable', which allows multiple listeners to bind the same address at the same time.
Parameters:
Returns:
This is a feature available only to Linux 3.9+
Parameters:
Returns:
Parameters:
Returns:
Parameters:
Returns:
Parameters:
Returns:
If no port is specified, the port in the output is set to 0.
Parameters:
Returns:
If you call this function as a replacement for the regular entropy sources, then you need to be sure that your input contains a fairly large amount of strong entropy. Doing so is notoriously hard: most people who try get it wrong. Watch out!
Parameters:
Ordinarily you don't need to call this function from your own code; Libevent will seed the RNG itself the first time it needs good random numbers. You only need to call it if (a) you want to double-check that one of the seeding methods did succeed, or (b) you plan to drop the capability to seed (by chrooting, or dropping capabilities, or whatever), and you want to make sure that seeding happens before your program loses the ability to do it.
Call this function BEFORE calling any other initialization or RNG functions.
(This string will NOT be copied internally. Do not free it while any user of the secure RNG might be running. Don't pass anything other than a real /dev/...random device file here, or you might lose security.)
This API is unstable, and might change in a future libevent version.
(This may fail on some Windows hosts where firewall software has cleverly decided to keep 127.0.0.1 from talking to itself.)
Parameters and return values are as for socketpair()
Tue Jan 31 2017 | libevent |