aboutsummaryrefslogtreecommitdiff
path: root/evloop.h
diff options
context:
space:
mode:
authorGuangxiong Lin <[email protected]>2022-12-09 16:46:49 +0800
committerGuangxiong Lin <[email protected]>2022-12-09 19:39:08 +0800
commit49839c88a98d3798f7b18c58f54f26f36cacff38 (patch)
tree5cb4ee13f9bdb0ef25e39a07a628f6f16da18e87 /evloop.h
parent0457119acb36b89b6f2f4534fe8ad94b19540bbd (diff)
downloadtinyserver-49839c88a98d3798f7b18c58f54f26f36cacff38.tar.gz
tinyserver-49839c88a98d3798f7b18c58f54f26f36cacff38.tar.bz2
tinyserver-49839c88a98d3798f7b18c58f54f26f36cacff38.zip
Implement a simple thread pool and refactor
Refactor
Diffstat (limited to 'evloop.h')
-rw-r--r--evloop.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/evloop.h b/evloop.h
new file mode 100644
index 0000000..f0d4f72
--- /dev/null
+++ b/evloop.h
@@ -0,0 +1,32 @@
+#include "tsocket.h"
+
+#ifndef __EVLOOP_H
+#define __EVLOOP_H
+
+#define EVENT_LOOP_MAX_EVENTS 1024
+
+struct evloop;
+typedef struct evloop evloop_t;
+
+typedef void (*evloop_process_func_t)(void *data);
+typedef void (*evloop_destroy_func_t)(void *data);
+
+struct event {
+ int fd;
+ void *data;
+ evloop_destroy_func_t destroy;
+ evloop_process_func_t process;
+};
+typedef struct event event_t;
+
+evloop_t *evloop_create();
+int evloop_wait(evloop_t *el, int timeout);
+int evloop_add(evloop_t *el, event_t *ev, int flag);
+int evloop_remove(evloop_t *el, event_t *ev);
+event_t *evloop_get(evloop_t *el, int index);
+void evloop_loop(evloop_t *el);
+event_t *event_create(void *data, int fd,
+ evloop_process_func_t process,
+ evloop_destroy_func_t destroy);
+
+#endif