mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-08 02:40:28 +00:00
Updated redbean Fetch to remove open connections on error
This commit is contained in:
parent
0a7b1718c2
commit
d73b465c6b
1 changed files with 5 additions and 4 deletions
|
@ -185,12 +185,13 @@ static int LuaFetch(lua_State *L) {
|
||||||
if (lua_isinteger(L, -1)) {
|
if (lua_isinteger(L, -1)) {
|
||||||
sock = lua_tointeger(L, -1);
|
sock = lua_tointeger(L, -1);
|
||||||
keepalive = lua_toboolean(L, -2) ? kaCLOSE : kaKEEP;
|
keepalive = lua_toboolean(L, -2) ? kaCLOSE : kaKEEP;
|
||||||
|
// remove host mapping, as the socket is ether being closed
|
||||||
|
// (so needs to be removed) or will be added after the request is done;
|
||||||
|
// this also helps to keep the mapping clean in case of an error
|
||||||
|
lua_pushnil(L); // aft: -4=tbl, -3=close, -2=hosthdr, -1=nil
|
||||||
|
lua_setfield(L, -4, hosthdr);
|
||||||
VERBOSEF("(ftch) reuse socket %d for host %s (and %s)",
|
VERBOSEF("(ftch) reuse socket %d for host %s (and %s)",
|
||||||
sock, hosthdr, keepalive == kaCLOSE ? "close" : "keep");
|
sock, hosthdr, keepalive == kaCLOSE ? "close" : "keep");
|
||||||
if (keepalive == kaCLOSE) { // remove socket being closed
|
|
||||||
lua_pushnil(L); // aft: -4=tbl, -3=close, -2=hosthdr, -1=nil
|
|
||||||
lua_setfield(L, -4, hosthdr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
lua_settop(L, 2); // drop all added elements to keep the stack balanced
|
lua_settop(L, 2); // drop all added elements to keep the stack balanced
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue