aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-10-12 03:20:09 +0200
committerKim Alvefur <zash@zash.se>2018-10-12 03:20:09 +0200
commit6f088c5034203780bad167533158c89718b4bf6e (patch)
tree4571d78b3e61ea7756150d06476858aa67cc8aa3
parent86247abe7864894ba30caf07beee1b53df5ab07c (diff)
downloadprosody-6f088c5034203780bad167533158c89718b4bf6e.tar.gz
prosody-6f088c5034203780bad167533158c89718b4bf6e.zip
net.server_epoll: Graceful handling of registering already added socket
-rw-r--r--net/server_epoll.lua9
-rw-r--r--util-src/poll.c8
2 files changed, 15 insertions, 2 deletions
diff --git a/net/server_epoll.lua b/net/server_epoll.lua
index e0189179..fc939675 100644
--- a/net/server_epoll.lua
+++ b/net/server_epoll.lua
@@ -25,7 +25,10 @@ local inet = require "util.net";
local inet_pton = inet.pton;
local _SOCKETINVALID = socket._SOCKETINVALID or -1;
-local poll = assert(require "util.poll".new());
+local poller = require "util.poll"
+local EEXIST = poller.EEXIST;
+
+local poll = assert(poller.new());
local _ENV = nil;
-- luacheck: std none
@@ -269,6 +272,10 @@ function interface:add(r, w)
if w == nil then w = self._wantwrite; end
local ok, err, errno = poll:add(fd, r, w);
if not ok then
+ if errno == EEXIST then
+ log("debug", "%s already registered!", self);
+ return self:set(r, w); -- So try to change its flags
+ end
log("error", "Could not register %s: %s(%d)", self, err, errno);
return ok, err;
end
diff --git a/util-src/poll.c b/util-src/poll.c
index 7fd28524..58f29041 100644
--- a/util-src/poll.c
+++ b/util-src/poll.c
@@ -452,10 +452,16 @@ int luaopen_util_poll(lua_State *L) {
#endif
}
- lua_createtable(L, 0, 1);
+ lua_createtable(L, 0, 2);
{
lua_pushcfunction(L, Lnew);
lua_setfield(L, -2, "new");
+
+#define push_errno(named_error) lua_pushinteger(L, named_error);\
+ lua_setfield(L, -2, #named_error);
+
+ push_errno(EEXIST);
+
}
return 1;
}