aboutsummaryrefslogtreecommitdiffstats
path: root/net/server_epoll.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-05-09 16:15:40 +0200
committerKim Alvefur <zash@zash.se>2018-05-09 16:15:40 +0200
commit7fa2aa0007e5bdae55ff0ced57ba193154302312 (patch)
treeea76a040fa49fccc3bc0669effd781d0382c34cd /net/server_epoll.lua
parent814f998b90f4b214f7b89f3d8d1d0032f9a2e78a (diff)
downloadprosody-7fa2aa0007e5bdae55ff0ced57ba193154302312.tar.gz
prosody-7fa2aa0007e5bdae55ff0ced57ba193154302312.zip
net.server: Add watchfd, a simple API for watching file descriptors
Diffstat (limited to 'net/server_epoll.lua')
-rw-r--r--net/server_epoll.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/net/server_epoll.lua b/net/server_epoll.lua
index 564444f8..0881f797 100644
--- a/net/server_epoll.lua
+++ b/net/server_epoll.lua
@@ -15,6 +15,7 @@ local t_concat = table.concat;
local setmetatable = setmetatable;
local tostring = tostring;
local pcall = pcall;
+local type = type;
local next = next;
local pairs = pairs;
local log = require "util.logger".init("server_epoll");
@@ -586,6 +587,25 @@ local function addclient(addr, port, listeners, pattern, tls)
return client, conn;
end
+local function watchfd(fd, onreadable, onwriteable)
+ local conn = setmetatable({
+ conn = fd;
+ onreadable = onreadable;
+ onwriteable = onwriteable;
+ close = function (self)
+ self:setflags(false, false);
+ end
+ }, interface_mt);
+ if type(fd) == "number" then
+ conn.getfd = function ()
+ return fd;
+ end;
+ -- Otherwise it'll need to be something LuaSocket-compatible
+ end
+ conn:setflags(onreadable, onwriteable);
+ return conn;
+end;
+
-- Dump all data from one connection into another
local function link(from, to)
from.listeners = setmetatable({
@@ -663,6 +683,7 @@ return {
closeall = closeall;
setquitting = setquitting;
wrapclient = wrapclient;
+ watchfd = watchfd;
link = link;
set_config = function (newconfig)
cfg = setmetatable(newconfig, default_config);