diff options
author | daurnimator <quae@daurnimator.com> | 2018-07-20 13:01:14 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2018-07-20 13:12:49 +1000 |
commit | 056a240fdced921cda162156fac122cb9f14d0a4 (patch) | |
tree | 5b05fb06d192a0c53bc16391086dea2b48961f71 | |
parent | 357a7f6da9e6ae442b3c3b9e43396b3cf2e1a91d (diff) | |
download | luaossl-056a240fdced921cda162156fac122cb9f14d0a4.tar.gz luaossl-056a240fdced921cda162156fac122cb9f14d0a4.tar.bz2 luaossl-056a240fdced921cda162156fac122cb9f14d0a4.zip |
src/openssl.c: cache SSL_CTX objects
-rw-r--r-- | src/openssl.c | 26 |
1 files changed, 26 insertions, 0 deletions
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() */ |