From a9501d10847d7993fad2e0778fe9c11317b4f7be Mon Sep 17 00:00:00 2001 From: Guangxiong Lin Date: Thu, 1 Dec 2022 23:20:33 +0800 Subject: Simplify logic by structure --- eventloop.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 eventloop.h (limited to 'eventloop.h') diff --git a/eventloop.h b/eventloop.h new file mode 100644 index 0000000..39c05d5 --- /dev/null +++ b/eventloop.h @@ -0,0 +1,22 @@ +#include + +#include "tsocket.h" + +#ifndef __EVENT_LOOP_H +#define __EVENT_LOOP_H + +#define EVENT_LOOP_MAX_EVENTS 1024 + +struct eventLoop { + int epollfd; + struct epoll_event events[EVENT_LOOP_MAX_EVENTS]; + struct tsocket *socks[EVENT_LOOP_MAX_EVENTS]; + int size; +}; + +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); + +#endif -- cgit v1.2.3