Comparison

net/server_epoll.lua @ 11805:2327e03d1f8d

net.server_epoll: Fix indentation messed up in last merge Seems to have happened in 6427e2642976, probably because of Meld
author Kim Alvefur <zash@zash.se>
date Fri, 17 Sep 2021 12:42:04 +0200
parent 11804:22825cb5dcd8
child 11812:42e98179c034
comparison
equal deleted inserted replaced
11804:22825cb5dcd8 11805:2327e03d1f8d
501 local ok, err, partial = self.conn:send(data); 501 local ok, err, partial = self.conn:send(data);
502 self._writable = ok; 502 self._writable = ok;
503 if ok then 503 if ok then
504 self:set(nil, false); 504 self:set(nil, false);
505 if cfg.keep_buffers and type(buffer) == "table" then 505 if cfg.keep_buffers and type(buffer) == "table" then
506 for i = #buffer, 1, -1 do 506 for i = #buffer, 1, -1 do
507 buffer[i] = nil; 507 buffer[i] = nil;
508 end 508 end
509 else 509 else
510 self.writebuffer = nil; 510 self.writebuffer = nil;
511 end 511 end
512 self:setwritetimeout(false); 512 self:setwritetimeout(false);
513 self:ondrain(); -- Be aware of writes in ondrain 513 self:ondrain(); -- Be aware of writes in ondrain
514 return ok; 514 return ok;
515 elseif partial then 515 elseif partial then
516 self:debug("Sent %d out of %d buffered bytes", partial, #data); 516 self:debug("Sent %d out of %d buffered bytes", partial, #data);
517 if cfg.keep_buffers and type(buffer) == "table" then 517 if cfg.keep_buffers and type(buffer) == "table" then
518 buffer[1] = data:sub(partial+1); 518 buffer[1] = data:sub(partial+1);
519 for i = #buffer, 2, -1 do 519 for i = #buffer, 2, -1 do
520 buffer[i] = nil; 520 buffer[i] = nil;
521 end 521 end
522 else 522 else
523 self.writebuffer = data:sub(partial+1); 523 self.writebuffer = data:sub(partial+1);
524 end 524 end
525 self:set(nil, true); 525 self:set(nil, true);
526 self:setwritetimeout(); 526 self:setwritetimeout();
558 if self._writable and cfg.opportunistic_writes and not self._opportunistic_write then 558 if self._writable and cfg.opportunistic_writes and not self._opportunistic_write then
559 self._opportunistic_write = true; 559 self._opportunistic_write = true;
560 local ret, err = self:onwritable(); 560 local ret, err = self:onwritable();
561 self._opportunistic_write = nil; 561 self._opportunistic_write = nil;
562 return ret, err; 562 return ret, err;
563 end 563 end
564 self:setwritetimeout(); 564 self:setwritetimeout();
565 self:set(nil, true); 565 self:set(nil, true);
566 end 566 end
567 return #data; 567 return #data;
568 end 568 end
569 interface.send = interface.write; 569 interface.send = interface.write;
570 570
628 end 628 end
629 629
630 function interface:inittls(tls_ctx, now) 630 function interface:inittls(tls_ctx, now)
631 if self._tls then return end 631 if self._tls then return end
632 if tls_ctx then self.tls_ctx = tls_ctx; end 632 if tls_ctx then self.tls_ctx = tls_ctx; end
633 self._tls = true; 633 self._tls = true;
634 self:debug("Starting TLS now"); 634 self:debug("Starting TLS now");
635 self:updatenames(); -- Can't getpeer/sockname after wrap() 635 self:updatenames(); -- Can't getpeer/sockname after wrap()
636 local ok, conn, err = pcall(luasec.wrap, self.conn, self.tls_ctx); 636 local ok, conn, err = pcall(luasec.wrap, self.conn, self.tls_ctx);
637 if not ok then 637 if not ok then
638 conn, err = ok, conn; 638 conn, err = ok, conn;
639 self:debug("Failed to initialize TLS: %s", err); 639 self:debug("Failed to initialize TLS: %s", err);
640 end 640 end
641 if not conn then 641 if not conn then
642 self:on("disconnect", err); 642 self:on("disconnect", err);
643 self:destroy(); 643 self:destroy();
644 return conn, err; 644 return conn, err;
645 end 645 end
646 conn:settimeout(0); 646 conn:settimeout(0);
647 self.conn = conn; 647 self.conn = conn;
648 if conn.sni then 648 if conn.sni then
649 if self.servername then 649 if self.servername then
650 conn:sni(self.servername); 650 conn:sni(self.servername);
651 elseif self._server and type(self._server.hosts) == "table" and next(self._server.hosts) ~= nil then 651 elseif self._server and type(self._server.hosts) == "table" and next(self._server.hosts) ~= nil then
652 conn:sni(self._server.hosts, true); 652 conn:sni(self._server.hosts, true);
662 for _, tlsa in ipairs(self.extra.tlsa) do 662 for _, tlsa in ipairs(self.extra.tlsa) do
663 self:noise("TLSA: %q", tlsa); 663 self:noise("TLSA: %q", tlsa);
664 conn:settlsa(tlsa.use, tlsa.select, tlsa.match, tlsa.data); 664 conn:settlsa(tlsa.use, tlsa.select, tlsa.match, tlsa.data);
665 end 665 end
666 end 666 end
667 end 667 end
668 self:on("starttls"); 668 self:on("starttls");
669 self.ondrain = nil; 669 self.ondrain = nil;
670 self.onwritable = interface.tlshandshake; 670 self.onwritable = interface.tlshandshake;
671 self.onreadable = interface.tlshandshake; 671 self.onreadable = interface.tlshandshake;
672 if now then 672 if now then
673 return self:tlshandshake() 673 return self:tlshandshake()
674 end 674 end
973 -- Dump all data from one connection into another 973 -- Dump all data from one connection into another
974 local function link(from, to, read_size) 974 local function link(from, to, read_size)
975 from:debug("Linking to %s", to.id); 975 from:debug("Linking to %s", to.id);
976 function from:onincoming(data) 976 function from:onincoming(data)
977 self:pause(); 977 self:pause();
978 to:write(data); 978 to:write(data);
979 end 979 end
980 function to:ondrain() -- luacheck: ignore 212/self 980 function to:ondrain() -- luacheck: ignore 212/self
981 from:resume(); 981 from:resume();
982 end 982 end
983 from:set_mode(read_size); 983 from:set_mode(read_size);
984 from:set(true, nil); 984 from:set(true, nil);
985 to:set(nil, true); 985 to:set(nil, true);
986 end 986 end