Comparison

net/server_epoll.lua @ 9506:ae6636052be9

net.server_epoll: Graceful handling of registering already added socket
author Kim Alvefur <zash@zash.se>
date Fri, 12 Oct 2018 03:20:09 +0200
parent 9499:36e379f058c8
child 9507:33d21f020b66
comparison
equal deleted inserted replaced
9505:5203b6fd34d4 9506:ae6636052be9
23 local createtable = require "util.table".create; 23 local createtable = require "util.table".create;
24 local inet = require "util.net"; 24 local inet = require "util.net";
25 local inet_pton = inet.pton; 25 local inet_pton = inet.pton;
26 local _SOCKETINVALID = socket._SOCKETINVALID or -1; 26 local _SOCKETINVALID = socket._SOCKETINVALID or -1;
27 27
28 local poll = assert(require "util.poll".new()); 28 local poller = require "util.poll"
29 local EEXIST = poller.EEXIST;
30
31 local poll = assert(poller.new());
29 32
30 local _ENV = nil; 33 local _ENV = nil;
31 -- luacheck: std none 34 -- luacheck: std none
32 35
33 local default_config = { __index = { 36 local default_config = { __index = {
267 end 270 end
268 if r == nil then r = self._wantread; end 271 if r == nil then r = self._wantread; end
269 if w == nil then w = self._wantwrite; end 272 if w == nil then w = self._wantwrite; end
270 local ok, err, errno = poll:add(fd, r, w); 273 local ok, err, errno = poll:add(fd, r, w);
271 if not ok then 274 if not ok then
275 if errno == EEXIST then
276 log("debug", "%s already registered!", self);
277 return self:set(r, w); -- So try to change its flags
278 end
272 log("error", "Could not register %s: %s(%d)", self, err, errno); 279 log("error", "Could not register %s: %s(%d)", self, err, errno);
273 return ok, err; 280 return ok, err;
274 end 281 end
275 self._wantread, self._wantwrite = r, w; 282 self._wantread, self._wantwrite = r, w;
276 fds[fd] = self; 283 fds[fd] = self;