summaryrefslogtreecommitdiffhomepage
path: root/libs/nixio/src/tls-context.c
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2009-02-24 17:54:48 +0000
committerSteven Barth <steven@midlink.org>2009-02-24 17:54:48 +0000
commitff2bc9081bb24e42dec9ccd46cdb4c377333dc59 (patch)
treeea14c5b622e9d79f149e5d3e3f2490bf4f5331ce /libs/nixio/src/tls-context.c
parentcebe6f031bc475e8e21102c4b5e378e1fa7bcf54 (diff)
nixio: Finetuning of TLS-support
httpclient: HTTPS support axTLS: enable diagnostic mode
Diffstat (limited to 'libs/nixio/src/tls-context.c')
-rw-r--r--libs/nixio/src/tls-context.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/libs/nixio/src/tls-context.c b/libs/nixio/src/tls-context.c
index ff3feeb4d..c55517630 100644
--- a/libs/nixio/src/tls-context.c
+++ b/libs/nixio/src/tls-context.c
@@ -74,6 +74,7 @@ static int nixio_tls_ctx_create(lua_State *L) {
SSL_CTX *ctx = nixio__checktlsctx(L);
int fd = nixio__checkfd(L, 2);
+ lua_createtable(L, 0, 3);
nixio_tls_sock *sock = lua_newuserdata(L, sizeof(nixio_tls_sock));
if (!sock) {
return luaL_error(L, "out of memory");
@@ -82,7 +83,8 @@ static int nixio_tls_ctx_create(lua_State *L) {
/* create userdata */
luaL_getmetatable(L, NIXIO_TLS_SOCK_META);
- lua_setmetatable(L, -2);
+ lua_pushvalue(L, -1);
+ lua_setmetatable(L, -3);
sock->socket = SSL_new(ctx);
if (!sock->socket) {
@@ -93,6 +95,16 @@ static int nixio_tls_ctx_create(lua_State *L) {
return nixio__tls_perror(L, 0);
}
+ /* save context and socket to prevent GC from collecting them */
+ lua_setmetatable(L, -3);
+ lua_setfield(L, -2, "connection");
+
+ lua_pushvalue(L, 1);
+ lua_setfield(L, -2, "context");
+
+ lua_pushvalue(L, 2);
+ lua_setfield(L, -2, "socket");
+
return 1;
}