#include<event2/event.h>#include<event2/event_struct.h>#include<stdlib.h>voidcb(evutil_socket_t fd,short what,void*ptr){ /* We pass 'NULL' as the callback pointer for the heap allocated * event, and we pass the event itself as the callback pointer * for the stack-allocated event. */structevent*ev= ptr;if (ev)event_debug_unassign(ev);}/* Here's a simple mainloop that waits until fd1 and fd2 are both * ready to read. */voidmainloop(evutil_socket_t fd1,evutil_socket_t fd2,int debug_mode){structevent_base*base;structeventevent_on_stack,*event_on_heap;if (debug_mode)event_enable_debug_mode(); base =event_base_new(); event_on_heap =event_new(base, fd1, EV_READ, cb,NULL);event_assign(&event_on_stack, base, fd2, EV_READ, cb,&event_on_stack);event_add(event_on_heap,NULL);event_add(&event_on_stack,NULL);event_base_dispatch(base);event_free(event_on_heap);event_base_free(base);}