4 #include <sys/eventfd.h> 8 #define EVENT_EPOLL_DEFMAX (4096) 10 #define EVENT_EPOLL_TIMEOUT (50) 48 EventEpoll instance = calloc(1,
sizeof(*instance));
49 if(!instance)
return NULL;
54 if(instance->
epfd == -1) {
86 struct epoll_event ev;
88 ev.data.ptr = instance;
91 if(epoll_ctl(base->
epfd, EPOLL_CTL_ADD, subscriber->
fd, &ev) == -1) {
112 struct epoll_event event;
114 event.data.ptr = handler;
115 if(epoll_ctl(base->
epfd, EPOLL_CTL_MOD, subscriber->
fd, &event)==-1) {
148 struct epoll_event *events = malloc(base->
maxevents *
sizeof(
struct epoll_event));
152 memset(events, 0, base->
maxevents *
sizeof(
struct epoll_event));
155 int cnt=0, i=0,
loop=0;
161 memset(events, 0, base->
maxevents *
sizeof(
struct epoll_event));
171 if(!events[i].data.ptr)
continue;
197 if(!instance)
return;
198 if(instance->
epfd) close(instance->
epfd);
event_subscriber_t subscriber
int event_if_getfd(EventHandler handler)
get fd related to handler
struct event_epoll_handler_t * EventEpollHandler
void(* free)(EventInstance this)
void event_if_loopbreak(EventInstance this)
break event
static int convert_etpoll_eveid2own(int eventflag)
EventInstance event_if_new(void)
event new
void(* event_callback)(int socketfd, int eventflag, void *event_arg)
void * EventHandler
Event handler related to fd.
struct event_epoll_t * EventEpoll
int(* loop)(EventInstance this)
static short convert_etpoll_ownid2eve(int eventflag)
EventSubscriber class instance definition, this is storaged in any threads.
int event_if_loop(EventInstance this)
main loop of this event
int eventflag
OR value of EV_TPOOL_XXX definition.
int fd
file descripter of this subscriber
void * EventInstance
Event management instance which get from event_if_new.
void event_if_free(EventInstance this)
free event if instance
void event_if_exit(EventInstance this)
exit after main loop
#define DEBUG_ERRPRINT(...)
#define EVENT_EPOLL_TIMEOUT
#define EVENT_EPOLL_DEFMAX
EventHandler event_if_add(EventInstance this, EventSubscriber subscriber, void *arg)
add new event
void * event_if_update(EventInstance this, EventHandler handler, EventSubscriber subscriber, void *arg)
update registered event
void event_if_del(EventInstance this, EventHandler handler)
delete event