#include<event2/event.h>#include<stdio.h>/* Change the callback and callback_arg of 'ev', which must not be * pending. */intreplace_callback(structevent*ev,event_callback_fn new_callback,void*new_callback_arg){structevent_base*base;evutil_socket_t fd;short events;int pending; pending =event_pending(ev, EV_READ|EV_WRITE|EV_SIGNAL|EV_TIMEOUT,NULL);if (pending) { /* We want to catch this here so that we do not re-assign a * pending event. That would be very very bad. */fprintf(stderr,"Error! replace_callback called on a pending event!\n");return-1; }event_get_assignment(ev,&base,&fd,&events,NULL /* ignore old callback */,NULL /* ignore old callback argument */);event_assign(ev, base, fd, events, new_callback, new_callback_arg);return0;}