From 7bb3515bc303a2a35fe859bcdba2795fbe06643d Mon Sep 17 00:00:00 2001 From: Guangxiong Lin Date: Sat, 17 Dec 2022 09:33:30 +0800 Subject: Make server as a library --- src/evloop.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/evloop.c') diff --git a/src/evloop.c b/src/evloop.c index 5bed1e9..5002b24 100644 --- a/src/evloop.c +++ b/src/evloop.c @@ -1,5 +1,6 @@ #include #include +#include #include "evloop.h" #include "util.h" @@ -25,6 +26,12 @@ evloop_t *evloop_create() return eventLoop; } +void evloop_destroy(evloop_t *evloop) +{ + close(evloop->epollfd); + free(evloop); +} + int evloop_wait(evloop_t *el, int timeout) { return epoll_wait(el->epollfd, el->events, el->size, timeout); @@ -56,9 +63,8 @@ void evloop_loop(evloop_t *el) for (int i = 0; i < nevents; i++) { ev = evloop_get(el, i); - // TODO: detect if there is any issue of the handle function - // and delete the event when issues happen - tpool_add_work(tpool, ev->process, ev->data); + if (ev->process(ev->data) == -1) + evloop_remove(el, ev); } } } -- cgit v1.2.3