Comparison

net/server_epoll.lua @ 7554:c2decf88e249

net.server_epoll: Use first writable event to signal onconnect
author Kim Alvefur <zash@zash.se>
date Wed, 10 Aug 2016 20:59:54 +0200
parent 7553:4f3e4a092348
child 7555:f3abb5f891eb
comparison
equal deleted inserted replaced
7553:4f3e4a092348 7554:c2decf88e249
372 conn = client; 372 conn = client;
373 server = server; 373 server = server;
374 created = gettime(); 374 created = gettime();
375 listeners = listeners; 375 listeners = listeners;
376 _pattern = pattern or server._pattern; 376 _pattern = pattern or server._pattern;
377 onwriteable = interface.onconnect;
377 writebuffer = {}; 378 writebuffer = {};
378 tls = tls; 379 tls = tls;
379 }, interface_mt); 380 }, interface_mt);
380 if client.getpeername then 381 if client.getpeername then
381 conn.peer = {client:getpeername()} 382 conn.peer = {client:getpeername()}
395 local client = wrapsocket(conn, self, nil, self.listeners, self.tls); 396 local client = wrapsocket(conn, self, nil, self.listeners, self.tls);
396 if self.tls then 397 if self.tls then
397 client._tls = false; 398 client._tls = false;
398 client:starttls(); 399 client:starttls();
399 else 400 else
400 self.listeners.onconnect(client); 401 client:setflags(false, true);
401 client:setflags(true);
402 end 402 end
403 client:setreadtimeout(); 403 client:setreadtimeout();
404 end 404 end
405 405
406 function interface:pause() 406 function interface:pause()
417 addtimer(t, function () self:setflags(true); end); 417 addtimer(t, function () self:setflags(true); end);
418 end 418 end
419 end 419 end
420 420
421 function interface:onconnect() 421 function interface:onconnect()
422 self.onreadable = nil;
423 self.onwriteable = nil; 422 self.onwriteable = nil;
424 self.listeners.onconnect(self); 423 self.listeners.onconnect(self);
424 self:setflags(true);
425 return self:onwriteable();
425 end 426 end
426 427
427 local function addserver(addr, port, listeners, pattern, tls) 428 local function addserver(addr, port, listeners, pattern, tls)
428 local conn, err = socket.bind(addr, port, cfg.tcp_backlog); 429 local conn, err = socket.bind(addr, port, cfg.tcp_backlog);
429 if not conn then return conn, err; end 430 if not conn then return conn, err; end
449 created = gettime(); 450 created = gettime();
450 listeners = listeners; 451 listeners = listeners;
451 _pattern = pattern; 452 _pattern = pattern;
452 writebuffer = {}; 453 writebuffer = {};
453 tls = tls; 454 tls = tls;
454 onreadable = interface.onconnect;
455 onwriteable = interface.onconnect; 455 onwriteable = interface.onconnect;
456 peer = { addr, port }; 456 peer = { addr, port };
457 }, interface_mt); 457 }, interface_mt);
458 fds[client:getfd()] = client; 458 fds[client:getfd()] = client;
459 client:setflags(false, true); 459 client:setflags(false, true);