# HG changeset patch # User Kim Alvefur # Date 1539307209 -7200 # Node ID ae6636052be9bfbbb6394e3bf81373a8d094fe84 # Parent 5203b6fd34d4346db00bb151e97e6a9cb8848331 net.server_epoll: Graceful handling of registering already added socket diff -r 5203b6fd34d4 -r ae6636052be9 net/server_epoll.lua --- a/net/server_epoll.lua Sun Oct 14 14:32:02 2018 +0200 +++ b/net/server_epoll.lua Fri Oct 12 03:20:09 2018 +0200 @@ -25,7 +25,10 @@ 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 @@ 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 -r 5203b6fd34d4 -r ae6636052be9 util-src/poll.c --- a/util-src/poll.c Sun Oct 14 14:32:02 2018 +0200 +++ b/util-src/poll.c Fri Oct 12 03:20:09 2018 +0200 @@ -452,10 +452,16 @@ #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; }