From 14eb75c7f5e90f3c1174cdf700753d74bbd358a8 Mon Sep 17 00:00:00 2001 From: Guangxiong Lin Date: Fri, 2 Dec 2022 01:04:51 +0800 Subject: Abstract accept and handle as event --- eventloop.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'eventloop.h') diff --git a/eventloop.h b/eventloop.h index 4dd7f6e..490d515 100644 --- a/eventloop.h +++ b/eventloop.h @@ -13,9 +13,19 @@ struct eventLoop { int size; }; +struct event { + int fd; + struct eventLoop *el; + void *data; + void (*handle)(struct event *ev); + void (*delete)(struct event *ev); +}; + struct eventLoop *eventLoopNew(); -int eventLoopAddSocket(struct eventLoop *el, struct tsocket *sock, int flag); int eventLoopWait(struct eventLoop *el, int timeout); -struct tsocket *eventLoopGetSocket(struct eventLoop *el, int index); +int eventLoopAdd(struct eventLoop *el, struct event *ev, int flag); +int eventLoopDel(struct eventLoop *el, struct event *ev); +struct event *eventLoopGet(struct eventLoop *el, int index); +void eventLoopLoop(struct eventLoop *el); #endif -- cgit v1.2.3