Prepare a new, already-allocated event structure to be added.
The function event_assign() prepares the event structure ev to be used
in future calls to event_add() and event_del(). Unlike event_new(), it
doesn't allocate memory itself: it requires that you have already
allocated a struct event, probably on the heap. Doing this will
typically make your code depend on the size of the event structure, and
thereby create incompatibility with future versions of Libevent.
The easiest way to avoid this problem is just to use event_new() and
event_free() instead.
A slightly harder way to future-proof your code is to use
event_get_struct_event_size() to determine the required size of an event
at runtime.
Note that it is NOT safe to call this function on an event that is
active or pending. Doing so WILL corrupt internal data structures in
Libevent, and lead to strange, hard-to-diagnose bugs. You _can_ use
event_assign to change an existing event, but only if it is not active
or pending!
The arguments for this function, and the behavior of the events that it
makes, are as for event_new().
@param ev an event to be modified
@param base the event base to which ev should be attached.
@param fd the file descriptor to be monitored
@param events desired events to monitor; can be EV_READ and/or EV_WRITE
@param callback callback function to be invoked when the event occurs
@param callback_arg an argument to be passed to the callback function
Prepare a new, already-allocated event structure to be added.
The function event_assign() prepares the event structure ev to be used in future calls to event_add() and event_del(). Unlike event_new(), it doesn't allocate memory itself: it requires that you have already allocated a struct event, probably on the heap. Doing this will typically make your code depend on the size of the event structure, and thereby create incompatibility with future versions of Libevent.
The easiest way to avoid this problem is just to use event_new() and event_free() instead.
A slightly harder way to future-proof your code is to use event_get_struct_event_size() to determine the required size of an event at runtime.
Note that it is NOT safe to call this function on an event that is active or pending. Doing so WILL corrupt internal data structures in Libevent, and lead to strange, hard-to-diagnose bugs. You _can_ use event_assign to change an existing event, but only if it is not active or pending!
The arguments for this function, and the behavior of the events that it makes, are as for event_new().
@param ev an event to be modified @param base the event base to which ev should be attached. @param fd the file descriptor to be monitored @param events desired events to monitor; can be EV_READ and/or EV_WRITE @param callback callback function to be invoked when the event occurs @param callback_arg an argument to be passed to the callback function
@return 0 if success, or -1 on invalid arguments.
@see event_new(), event_add(), event_del(), event_base_once(), event_get_struct_event_size()