changeset 5395:82207f936f1f

mod_inotify_reload: Update to use FD watching method This removes the need to present a fake socket interface, simplifying everything.
author Kim Alvefur <zash@zash.se>
date Sun, 30 Apr 2023 20:34:36 +0200
parents 434ee49b04de
children ac7c5669e5f5
files mod_inotify_reload/mod_inotify_reload.lua
diffstat 1 files changed, 11 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/mod_inotify_reload/mod_inotify_reload.lua	Sun Apr 30 17:16:47 2023 +0200
+++ b/mod_inotify_reload/mod_inotify_reload.lua	Sun Apr 30 20:34:36 2023 +0200
@@ -12,31 +12,19 @@
 local watches = {};
 local watch_ids = {};
 
--- Fake socket object around inotify
-local inh_conn = {
-	getfd = function () return inh:fileno(); end;
-	dirty = function (self) return false; end;
-	settimeout = function () end;
-	send = function (_, d) return #d, 0; end;
-	close = function () end;
-	receive = function ()
-		local events = inh:read();
-		for _, event in ipairs(events) do
-			local mod = watches[watch_ids[event.wd]];
-			if mod then
-				local host, name = mod.host, mod.name;
-				module:log("debug", "Reloading changed module mod_%s on %s", name, host);
-				modulemanager.reload(host, name);
-			else
-				module:log("warn", "no watch for %d", event.wd);
-			end
+require"net.server".watchfd(inh:fileno(), function()
+	local events = inh:read();
+	for _, event in ipairs(events) do
+		local mod = watches[watch_ids[event.wd]];
+		if mod then
+			local host, name = mod.host, mod.name;
+			module:log("debug", "Reloading changed module mod_%s on %s", name, host);
+			modulemanager.reload(host, name);
+		else
+			module:log("warn", "no watch for %d", event.wd);
 		end
-		return "";
 	end
-};
-require "net.server".wrapclient(inh_conn, "inotify", inh:fileno(), {
-	onincoming = function () end, ondisconnect = function () end
-}, "*a");
+end);
 
 function watch_module(name, host, path)
 	local id, err = inh:addwatch(path, inotify.IN_CLOSE_WRITE);