event2/event.h中定义了evtimer和evsignal各六个宏定义,方便使用
/**
@name evtimer_* macros
Aliases for working with one-shot timer events */
/**@{*/
#define evtimer_assign(ev, b, cb, arg) \
event_assign((ev), (b), -1, 0, (cb), (arg))
#define evtimer_new(b, cb, arg) event_new((b), -1, 0, (cb), (arg))
#define evtimer_add(ev, tv) event_add((ev), (tv))
#define evtimer_del(ev) event_del(ev)
#define evtimer_pending(ev, tv) event_pending((ev), EV_TIMEOUT, (tv))
#define evtimer_initialized(ev) event_initialized(ev)
/**@}*/
/**
@name evsignal_* macros
Aliases for working with signal events
*/
/**@{*/
#define evsignal_add(ev, tv) event_add((ev), (tv))
#define evsignal_assign(ev, b, x, cb, arg) \
event_assign((ev), (b), (x), EV_SIGNAL|EV_PERSIST, cb, (arg))
#define evsignal_new(b, x, cb, arg) \
event_new((b), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg))
#define evsignal_del(ev) event_del(ev)
#define evsignal_pending(ev, tv) event_pending((ev), EV_SIGNAL, (tv))
#define evsignal_initialized(ev) event_initialized(ev)
/**@}*/
/**
A callback function for an event.
It receives three arguments:
@param fd An fd or signal
@param events One or more EV_* flags
@param arg A user-supplied argument.
@see event_new()
*/
typedef void (*event_callback_fn)(evutil_socket_t, short, void *);
/**
Return a value used to specify that the event itself must be used as the callback argument.
The function event_new() takes a callback argument which is passed
to the event's callback function. To specify that the argument to be
passed to the callback function is the event that event_new() returns,
pass in the return value of event_self_cbarg() as the callback argument
for event_new().
For example:
<pre>
struct event *ev = event_new(base, sock, events, callback, %event_self_cbarg());
</pre>
For consistency with event_new(), it is possible to pass the return value
of this function as the callback argument for event_assign() – this
achieves the same result as passing the event in directly.
@return a value to be passed as the callback argument to event_new() or
event_assign().
@see event_new(), event_assign()
*/
EVENT2_EXPORT_SYMBOL
void *event_self_cbarg(void);