Comparison

net/server_epoll.lua @ 9301:2f9687c09e6e

net.server_epoll: Remove coercion of connections to strings No longer needed since util.logger does this now
author Kim Alvefur <zash@zash.se>
date Thu, 13 Sep 2018 17:02:26 +0200
parent 9300:1df8832bd29e
child 9306:35c128b42509
comparison
equal deleted inserted replaced
9300:1df8832bd29e 9301:2f9687c09e6e
388 -- Close, possibly after writing is done 388 -- Close, possibly after writing is done
389 function interface:close() 389 function interface:close()
390 if self.writebuffer and self.writebuffer[1] then 390 if self.writebuffer and self.writebuffer[1] then
391 self:setflags(false, true); -- Flush final buffer contents 391 self:setflags(false, true); -- Flush final buffer contents
392 self.write, self.send = noop, noop; -- No more writing 392 self.write, self.send = noop, noop; -- No more writing
393 log("debug", "Close %s after writing", tostring(self)); 393 log("debug", "Close %s after writing", self);
394 self.ondrain = interface.close; 394 self.ondrain = interface.close;
395 else 395 else
396 log("debug", "Close %s now", tostring(self)); 396 log("debug", "Close %s now", self);
397 self.write, self.send = noop, noop; 397 self.write, self.send = noop, noop;
398 self.close = noop; 398 self.close = noop;
399 self:on("disconnect"); 399 self:on("disconnect");
400 self:destroy(); 400 self:destroy();
401 end 401 end
419 end 419 end
420 420
421 function interface:starttls(tls_ctx) 421 function interface:starttls(tls_ctx)
422 if tls_ctx then self.tls_ctx = tls_ctx; end 422 if tls_ctx then self.tls_ctx = tls_ctx; end
423 if self.writebuffer and self.writebuffer[1] then 423 if self.writebuffer and self.writebuffer[1] then
424 log("debug", "Start TLS on %s after write", tostring(self)); 424 log("debug", "Start TLS on %s after write", self);
425 self.ondrain = interface.starttls; 425 self.ondrain = interface.starttls;
426 self.starttls = false; 426 self.starttls = false;
427 self:setflags(nil, true); -- make sure wantwrite is set 427 self:setflags(nil, true); -- make sure wantwrite is set
428 else 428 else
429 log("debug", "Start TLS on %s now", tostring(self)); 429 log("debug", "Start TLS on %s now", self);
430 self:setflags(false, false); 430 self:setflags(false, false);
431 local conn, err = luasec.wrap(self.conn, tls_ctx or self.tls_ctx); 431 local conn, err = luasec.wrap(self.conn, tls_ctx or self.tls_ctx);
432 if not conn then 432 if not conn then
433 self:on("disconnect", err); 433 self:on("disconnect", err);
434 self:destroy(); 434 self:destroy();
447 function interface:tlshandskake() 447 function interface:tlshandskake()
448 self:setwritetimeout(false); 448 self:setwritetimeout(false);
449 self:setreadtimeout(false); 449 self:setreadtimeout(false);
450 local ok, err = self.conn:dohandshake(); 450 local ok, err = self.conn:dohandshake();
451 if ok then 451 if ok then
452 log("debug", "TLS handshake on %s complete", tostring(self)); 452 log("debug", "TLS handshake on %s complete", self);
453 self.onwritable = nil; 453 self.onwritable = nil;
454 self.onreadable = nil; 454 self.onreadable = nil;
455 self._tls = true; 455 self._tls = true;
456 self:on("status", "ssl-handshake-complete"); 456 self:on("status", "ssl-handshake-complete");
457 self:init(); 457 self:init();
458 elseif err == "wantread" then 458 elseif err == "wantread" then
459 log("debug", "TLS handshake on %s to wait until readable", tostring(self)); 459 log("debug", "TLS handshake on %s to wait until readable", self);
460 self:setflags(true, false); 460 self:setflags(true, false);
461 self:setreadtimeout(cfg.handshake_timeout); 461 self:setreadtimeout(cfg.handshake_timeout);
462 elseif err == "wantwrite" then 462 elseif err == "wantwrite" then
463 log("debug", "TLS handshake on %s to wait until writable", tostring(self)); 463 log("debug", "TLS handshake on %s to wait until writable", self);
464 self:setflags(false, true); 464 self:setflags(false, true);
465 self:setwritetimeout(cfg.handshake_timeout); 465 self:setwritetimeout(cfg.handshake_timeout);
466 else 466 else
467 log("debug", "TLS handshake error on %s: %s", tostring(self), err); 467 log("debug", "TLS handshake error on %s: %s", self, err);
468 self:on("disconnect", err); 468 self:on("disconnect", err);
469 self:destroy(); 469 self:destroy();
470 end 470 end
471 end 471 end
472 472