Software /
code /
prosody
Diff
util-src/poll.c @ 12314:898554323338
util.poll: Restructure to make adding additional system APIs easier
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 23 Feb 2022 20:30:22 +0100 |
parent | 10921:6eb5d2bb11af |
child | 12315:cf2086a1bd45 |
line wrap: on
line diff
--- a/util-src/poll.c Sun Feb 13 16:53:56 2022 +0100 +++ b/util-src/poll.c Wed Feb 23 20:30:22 2022 +0100 @@ -12,8 +12,10 @@ #include <string.h> #include <errno.h> -#ifdef __linux__ +#if defined(__linux__) #define USE_EPOLL +#else +#define USE_SELECT #endif #ifdef USE_EPOLL @@ -21,7 +23,8 @@ #ifndef MAX_EVENTS #define MAX_EVENTS 64 #endif -#else +#endif +#ifdef USE_SELECT #include <sys/select.h> #endif @@ -30,7 +33,8 @@ #ifdef USE_EPOLL #define STATE_MT "util.poll<epoll>" -#else +#endif +#ifdef USE_SELECT #define STATE_MT "util.poll<select>" #endif @@ -49,7 +53,8 @@ #ifdef USE_EPOLL int epoll_fd; struct epoll_event events[MAX_EVENTS]; -#else +#endif +#ifdef USE_SELECT fd_set wantread; fd_set wantwrite; fd_set readable; @@ -96,7 +101,8 @@ lua_pushboolean(L, 1); return 1; -#else +#endif +#ifdef USE_SELECT if(fd > FD_SETSIZE) { luaL_pushfail(L); @@ -169,7 +175,8 @@ return 3; } -#else +#endif +#ifdef USE_SELECT if(!FD_ISSET(fd, &state->all)) { luaL_pushfail(L); @@ -227,7 +234,8 @@ return 3; } -#else +#endif +#ifdef USE_SELECT if(!FD_ISSET(fd, &state->all)) { luaL_pushfail(L); @@ -264,7 +272,8 @@ return 3; } -#else +#endif +#ifdef USE_SELECT for(int fd = state->processed + 1; fd < FD_SETSIZE; fd++) { if(FD_ISSET(fd, &state->readable) || FD_ISSET(fd, &state->writable) || FD_ISSET(fd, &state->err)) { @@ -300,7 +309,8 @@ #ifdef USE_EPOLL ret = epoll_wait(state->epoll_fd, state->events, MAX_EVENTS, timeout * 1000); -#else +#endif +#ifdef USE_SELECT /* * select(2) mutates the fd_sets passed to it so in order to not * have to recreate it manually every time a copy is made. @@ -341,7 +351,8 @@ */ #ifdef USE_EPOLL state->processed = ret; -#else +#endif +#ifdef USE_SELECT state->processed = -1; #endif return Lpushevent(L, state); @@ -411,7 +422,8 @@ } state->epoll_fd = epoll_fd; -#else +#endif +#ifdef USE_SELECT FD_ZERO(&state->wantread); FD_ZERO(&state->wantwrite); FD_ZERO(&state->readable);