diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-11-07 06:01:57 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-11-07 06:01:57 +0000 |
commit | f74e7258fd29a341b4ecf08dfdb83e50aaee3255 (patch) | |
tree | 8cf870c606114b9bd242ac88ea01b50c7192a8a2 /evutil.h | |
parent | d0ce7d4ed7f6f269fdc93039d739fecf28495c24 (diff) | |
download | libevent-f74e7258fd29a341b4ecf08dfdb83e50aaee3255.tar.gz |
r16501@catbus: nickm | 2007-11-07 01:00:31 -0500
This is one of those patches which will either make matters far
simpler after the bugs shake out, or will get reverted pretty quick
once we realize that it is a stupid idea.
We now post-process the config.h file into a new event-config.h file,
whose macros are prefixed with _EVENT_ and which is thus safe for
headers to include. Using this, we can define replacement timeval
manipulation functions in evutil.h, and use them uniformly through our
code. We can also detect which headers are needful in event.h, and
include them as required.
This is also the perfect time to remove the long-deprecated acconfig.h
file, so that autoheader no longer warns.
Should resolve the following issues:
[ 1826530 ] Header files should have access to autoconf output.
[ 1826545 ] acconfig.h is deprecated.
[ 1826564 ] On some platforms, event.h can't be included alone.
svn:r492
Diffstat (limited to 'evutil.h')
-rw-r--r-- | evutil.h | 53 |
1 files changed, 53 insertions, 0 deletions
@@ -38,6 +38,11 @@ extern "C" { #endif +#include <event-config.h> +#ifdef _EVENT_HAVE_SYS_TIME_H +#include <sys/time.h> +#endif + int evutil_socketpair(int d, int type, int protocol, int sv[2]); int evutil_make_socket_nonblocking(int sock); #ifdef WIN32 @@ -56,6 +61,54 @@ int evutil_make_socket_nonblocking(int sock); do { errno = (errcode); } while (0) #endif +/* + * Manipulation functions for struct timeval + */ +#ifdef _EVENT_HAVE_TIMERADD +#define evutil_timeradd(tvp, uvp, vvp) timeradd((tvp), (uvp), (vvp)) +#define evutil_timersub(tvp, uvp, vvp) timersub((tvp), (uvp), (vvp)) +#else +#define evutil_timeradd(tvp, uvp, vvp) \ + 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) +#define evutil_timersub(tvp, uvp, vvp) \ + 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) +#endif /* !_EVENT_HAVE_HAVE_TIMERADD */ + +#ifdef _EVENT_HAVE_TIMERCLEAR +#define evutil_timerclear(tvp) timerclear(tvp) +#else +#define evutil_timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 +#endif + +#ifdef _EVENT_HAVE_TIMERCMP +#define evutil_timercmp(tvp, uvp, cmp) timercmp((tvp), (uvp), cmp) +#else +#define evutil_timercmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) +#endif + +#ifdef _EVENT_HAVE_TIMERISSET +#define evutil_timerisset(tvp) timerisset(tvp) +#else +#define evutil_timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#endif + #ifdef __cplusplus } #endif |