From 056a240fdced921cda162156fac122cb9f14d0a4 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 20 Jul 2018 13:01:14 +1000 Subject: src/openssl.c: cache SSL_CTX objects --- src/openssl.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/openssl.c b/src/openssl.c index 81c95de..4e7dc8b 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -8341,6 +8341,26 @@ EXPORT int luaopen__openssl_pkcs12(lua_State *L) { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +static void sx_push(lua_State *L, SSL_CTX *ctx) { + lua_rawgetp(L, LUA_REGISTRYINDEX, (void *)&initall); + if (LUA_TNIL == lua_rawgetp(L, -1, ctx)) { + SSL_CTX **ud; + + lua_pop(L, 1); /* pop nil */ + + ud = prepsimple(L, SSL_CTX_CLASS); + + SSL_CTX_up_ref(ctx); + *ud = ctx; + + /* Add to cache */ + lua_pushvalue(L, -1); + lua_rawsetp(L, -3, ctx); + } + lua_remove(L, -2); +} /* sx_push() */ + + static int sx_new(lua_State *L) { static const char *const opts[] = { [0] = "SSL", @@ -8468,6 +8488,12 @@ static int sx_new(lua_State *L) { return auxL_error(L, auxL_EOPENSSL, "ssl.context.new"); #endif + /* Add to cache */ + lua_rawgetp(L, LUA_REGISTRYINDEX, (void *)&initall); + lua_pushvalue(L, -2); + lua_rawsetp(L, -2, *ud); + lua_pop(L, 1); + return 1; } /* sx_new() */ -- cgit v1.2.3-59-g8ed1b