Changeset

12315:cf2086a1bd45

util.poll: Expose API (epoll or select) used Could he handy to know for debugging or decisions
author Kim Alvefur <zash@zash.se>
date Sun, 27 Feb 2022 14:36:43 +0100
parents 12314:898554323338
children 12316:6bb2f660f689
files teal-src/util/poll.d.tl util-src/poll.c
diffstat 2 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/teal-src/util/poll.d.tl	Wed Feb 23 20:30:22 2022 +0100
+++ b/teal-src/util/poll.d.tl	Sun Feb 27 14:36:43 2022 +0100
@@ -19,6 +19,11 @@
 	new : function () : state
 	ENOENT : integer
 	EEXIST : integer
+	enum api_backend
+		"epoll"
+		"select"
+	end
+	api : api_backend
 end
 
 return lib
--- a/util-src/poll.c	Wed Feb 23 20:30:22 2022 +0100
+++ b/util-src/poll.c	Sun Feb 27 14:36:43 2022 +0100
@@ -14,8 +14,10 @@
 
 #if defined(__linux__)
 #define USE_EPOLL
+#define POLL_BACKEND "epoll"
 #else
 #define USE_SELECT
+#define POLL_BACKEND "select"
 #endif
 
 #ifdef USE_EPOLL
@@ -31,12 +33,7 @@
 #include <lualib.h>
 #include <lauxlib.h>
 
-#ifdef USE_EPOLL
-#define STATE_MT "util.poll<epoll>"
-#endif
-#ifdef USE_SELECT
-#define STATE_MT "util.poll<select>"
-#endif
+#define STATE_MT "util.poll<" POLL_BACKEND ">"
 
 #if (LUA_VERSION_NUM == 501)
 #define luaL_setmetatable(L, tname) luaL_getmetatable(L, tname); lua_setmetatable(L, -2)
@@ -487,6 +484,9 @@
 		push_errno(EEXIST);
 		push_errno(ENOENT);
 
+		lua_pushliteral(L, POLL_BACKEND);
+		lua_setfield(L, -2, "api");
+
 	}
 	return 1;
 }