Merge 0.11->trunk

This commit is contained in:
Kim Alvefur 2021-08-31 13:03:44 +02:00
commit 4ddf47aaf0

View file

@ -155,8 +155,8 @@ local function runtimers(next_delay, min_wait)
end end
if readd then if readd then
for _, timer in pairs(readd) do for id, timer in pairs(readd) do
timers:insert(timer[1], timer[2]); timers:insert(timer[1], timer[2], id);
end end
peek = timers:peek(); peek = timers:peek();
end end
@ -489,9 +489,9 @@ function interface:onwritable()
if ok then if ok then
self:set(nil, false); self:set(nil, false);
if cfg.keep_buffers and type(buffer) == "table" then if cfg.keep_buffers and type(buffer) == "table" then
for i = #buffer, 1, -1 do for i = #buffer, 1, -1 do
buffer[i] = nil; buffer[i] = nil;
end end
else else
self.writebuffer = nil; self.writebuffer = nil;
end end
@ -501,10 +501,10 @@ function interface:onwritable()
elseif partial then elseif partial then
self:debug("Sent %d out of %d buffered bytes", partial, #data); self:debug("Sent %d out of %d buffered bytes", partial, #data);
if cfg.keep_buffers and type(buffer) == "table" then if cfg.keep_buffers and type(buffer) == "table" then
buffer[1] = data:sub(partial+1); buffer[1] = data:sub(partial+1);
for i = #buffer, 2, -1 do for i = #buffer, 2, -1 do
buffer[i] = nil; buffer[i] = nil;
end end
else else
self.writebuffer = data:sub(partial+1); self.writebuffer = data:sub(partial+1);
end end
@ -546,9 +546,9 @@ function interface:write(data)
local ret, err = self:onwritable(); local ret, err = self:onwritable();
self._opportunistic_write = nil; self._opportunistic_write = nil;
return ret, err; return ret, err;
end end
self:setwritetimeout(); self:setwritetimeout();
self:set(nil, true); self:set(nil, true);
end end
return #data; return #data;
end end
@ -616,21 +616,21 @@ end
function interface:inittls(tls_ctx, now) function interface:inittls(tls_ctx, now)
if self._tls then return end if self._tls then return end
if tls_ctx then self.tls_ctx = tls_ctx; end if tls_ctx then self.tls_ctx = tls_ctx; end
self._tls = true; self._tls = true;
self:debug("Starting TLS now"); self:debug("Starting TLS now");
self:updatenames(); -- Can't getpeer/sockname after wrap() self:updatenames(); -- Can't getpeer/sockname after wrap()
local ok, conn, err = pcall(luasec.wrap, self.conn, self.tls_ctx); local ok, conn, err = pcall(luasec.wrap, self.conn, self.tls_ctx);
if not ok then if not ok then
conn, err = ok, conn; conn, err = ok, conn;
self:debug("Failed to initialize TLS: %s", err); self:debug("Failed to initialize TLS: %s", err);
end end
if not conn then if not conn then
self:on("disconnect", err); self:on("disconnect", err);
self:destroy(); self:destroy();
return conn, err; return conn, err;
end end
conn:settimeout(0); conn:settimeout(0);
self.conn = conn; self.conn = conn;
if conn.sni then if conn.sni then
if self.servername then if self.servername then
conn:sni(self.servername); conn:sni(self.servername);
@ -650,9 +650,9 @@ function interface:inittls(tls_ctx, now)
conn:settlsa(tlsa.use, tlsa.select, tlsa.match, tlsa.data); conn:settlsa(tlsa.use, tlsa.select, tlsa.match, tlsa.data);
end end
end end
end end
self:on("starttls"); self:on("starttls");
self.ondrain = nil; self.ondrain = nil;
self.onwritable = interface.tlshandshake; self.onwritable = interface.tlshandshake;
self.onreadable = interface.tlshandshake; self.onreadable = interface.tlshandshake;
if now then if now then
@ -961,10 +961,10 @@ local function link(from, to, read_size)
from:debug("Linking to %s", to.id); from:debug("Linking to %s", to.id);
function from:onincoming(data) function from:onincoming(data)
self:pause(); self:pause();
to:write(data); to:write(data);
end end
function to:ondrain() -- luacheck: ignore 212/self function to:ondrain() -- luacheck: ignore 212/self
from:resume(); from:resume();
end end
from:set_mode(read_size); from:set_mode(read_size);
from:set(true, nil); from:set(true, nil);