Diff

net/server_epoll.lua @ 7817:4e3654031693

net.server_epoll: Reuse interface metatable for event compat layer
author Kim Alvefur <zash@zash.se>
date Fri, 06 Jan 2017 17:01:48 +0100
parent 7811:24f99d11b792
child 7910:91db637be237
line wrap: on
line diff
--- a/net/server_epoll.lua	Thu Jan 05 06:21:31 2017 +0100
+++ b/net/server_epoll.lua	Fri Jan 06 17:01:48 2017 +0100
@@ -671,23 +671,23 @@
 		local function onevent(self)
 			local ret = self:callback();
 			if ret == -1 then
-				epoll.ctl("del", fd);
+				self:setflags(false, false);
 			elseif ret then
-				epoll.ctl("mod", fd, mode);
+				self:setflags(mode == "r" or mode == "rw", mode == "w" or mode == "rw");
 			end
 		end
 
-		local conn = {
+		local conn = setmetatable({
+			getfd = function () return fd; end;
 			callback = callback;
 			onreadable = onevent;
 			onwriteable = onevent;
-			close = function ()
+			close = function (self)
+				self:setflags(false, false);
 				fds[fd] = nil;
-				return epoll.ctl("del", fd);
 			end;
-		};
-		fds[fd] = conn;
-		local ok, err = epoll.ctl("add", fd, mode or "r");
+		}, interface_mt);
+		local ok, err = conn:setflags(mode == "r" or mode == "rw", mode == "w" or mode == "rw");
 		if not ok then return ok, err; end
 		return conn;
 	end;