Comparison

net/server_epoll.lua @ 7625:6afafd6d4ef0

net.server_epoll: Move management of fd registry to :setflags
author Kim Alvefur <zash@zash.se>
date Mon, 22 Aug 2016 17:19:49 +0200
parent 7624:23fb3a084956
child 7626:e56343d50293
comparison
equal deleted inserted replaced
7624:23fb3a084956 7625:6afafd6d4ef0
261 end 261 end
262 local ok, err = epoll.ctl(op, fd, flags); 262 local ok, err = epoll.ctl(op, fd, flags);
263 -- log("debug", "epoll_ctl(%q, %d, %q) -> %s" .. (err and ", %q" or ""), 263 -- log("debug", "epoll_ctl(%q, %d, %q) -> %s" .. (err and ", %q" or ""),
264 -- op, fd, flags or "", tostring(ok), err); 264 -- op, fd, flags or "", tostring(ok), err);
265 if not ok then return ok, err end 265 if not ok then return ok, err end
266 if op == "add" then
267 fds[fd] = self;
268 elseif op == "del" then
269 fds[fd] = nil;
270 end
266 self._flags = flags; 271 self._flags = flags;
267 return true; 272 return true;
268 end 273 end
269 274
270 -- Called when socket is readable 275 -- Called when socket is readable
365 self.onreadable = noop; 370 self.onreadable = noop;
366 self.onwriteable = noop; 371 self.onwriteable = noop;
367 self.destroy = noop; 372 self.destroy = noop;
368 self.close = noop; 373 self.close = noop;
369 self.on = noop; 374 self.on = noop;
370 fds[self:getfd()] = nil;
371 self.conn:close(); 375 self.conn:close();
372 self.conn = nil; 376 self.conn = nil;
373 end 377 end
374 378
375 function interface:ssl() 379 function interface:ssl()
453 conn.peername, conn.peerport = client:getpeername(); 457 conn.peername, conn.peerport = client:getpeername();
454 end 458 end
455 if client.getsockname then 459 if client.getsockname then
456 conn.sockname, conn.sockport = client:getsockname(); 460 conn.sockname, conn.sockport = client:getsockname();
457 end 461 end
458
459 fds[conn:getfd()] = conn;
460 return conn; 462 return conn;
461 end 463 end
462 464
463 function interface:onacceptable() 465 function interface:onacceptable()
464 local conn, err = self.conn:accept(); 466 local conn, err = self.conn:accept();
526 tls = tls; 528 tls = tls;
527 sockname = addr; 529 sockname = addr;
528 sockport = port; 530 sockport = port;
529 }, interface_mt); 531 }, interface_mt);
530 server:setflags(true, false); 532 server:setflags(true, false);
531 fds[server:getfd()] = server;
532 return server; 533 return server;
533 end 534 end
534 535
535 -- COMPAT 536 -- COMPAT
536 local function wrapclient(conn, addr, port, listeners, pattern, tls) 537 local function wrapclient(conn, addr, port, listeners, pattern, tls)