aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2018-07-20 13:01:14 +1000
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2018-07-20 13:12:49 +1000
commit056a240fdced921cda162156fac122cb9f14d0a4 (patch)
tree5b05fb06d192a0c53bc16391086dea2b48961f71
parent357a7f6da9e6ae442b3c3b9e43396b3cf2e1a91d (diff)
downloadluaossl-056a240fdced921cda162156fac122cb9f14d0a4.tar.gz
luaossl-056a240fdced921cda162156fac122cb9f14d0a4.tar.bz2
luaossl-056a240fdced921cda162156fac122cb9f14d0a4.zip
src/openssl.c: cache SSL_CTX objects
-rw-r--r--src/openssl.c26
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() */