Refactor epoll module.
[apps/pfixtools.git] / epoll.c
diff --git a/epoll.c b/epoll.c
index 3d16789..e3df03e 100644 (file)
--- a/epoll.c
+++ b/epoll.c
@@ -35,7 +35,7 @@
 
 #include "epoll.h"
 
-int epollfd = -1;
+static int epollfd = -1;
 
 static int epoll_initialize(void)
 {
@@ -50,3 +50,26 @@ static void epoll_shutdown(void)
 
 module_init(epoll_initialize);
 module_exit(epoll_shutdown);
+
+void epoll_register(int fd, uint32_t events, void *ptr)
+{
+    struct epoll_event evt = { .events = events, .data.ptr = ptr };
+    if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &evt)) {
+        UNIXERR("epoll_ctl");
+        abort();
+    }
+}
+
+void epoll_modify(int fd, uint32_t events, void *ptr)
+{
+    struct epoll_event evt = { .events = events, .data.ptr = ptr };
+    if (epoll_ctl(epollfd, EPOLL_CTL_MOD, fd, &evt)) {
+        UNIXERR("epoll_ctl");
+        abort();
+    }
+}
+
+int epoll_select(struct epoll_event *events, int maxevents, int timeout)
+{
+    return epoll_wait(epollfd, events, maxevents, timeout);
+}