diff options
author | Steve Bennett <steveb@workware.net.au> | 2017-10-15 13:25:15 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2017-10-21 12:49:17 +1000 |
commit | fd965a0c4f35d959d12d747e2e3162390a1579f2 (patch) | |
tree | 8495c6b685eb7f0aa37f532004c247c65907e329 /jim-aio.c | |
parent | f7552be53efe1366147f6bb772d7a9121a14feec (diff) | |
download | jimtcl-fd965a0c4f35d959d12d747e2e3162390a1579f2.zip jimtcl-fd965a0c4f35d959d12d747e2e3162390a1579f2.tar.gz jimtcl-fd965a0c4f35d959d12d747e2e3162390a1579f2.tar.bz2 |
aio: No need to create a new channel for ssl
Just "promote" the current channel to ssl
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim-aio.c')
-rw-r--r-- | jim-aio.c | 31 |
1 files changed, 11 insertions, 20 deletions
@@ -1187,7 +1187,7 @@ static int aio_cmd_ssl(Jim_Interp *interp, int argc, Jim_Obj *const *argv) AioFile *af = Jim_CmdPrivData(interp); SSL *ssl; SSL_CTX *ssl_ctx; - int fd, server = 0; + int server = 0; if (argc == 5) { if (!Jim_CompareStringImmediate(interp, argv[2], "-server")) { @@ -1200,13 +1200,11 @@ static int aio_cmd_ssl(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return JIM_ERR; } - fd = fileno(af->fp); -#if defined(HAVE_DUP) - fd = dup(fd); - if (fd < 0) { + if (af->ssl) { + Jim_SetResultFormatted(interp, "%#s: stream is already ssl", argv[0]); return JIM_ERR; } -#endif + ssl_ctx = JimAioSslCtx(interp); if (ssl_ctx == NULL) { return JIM_ERR; @@ -1214,11 +1212,7 @@ static int aio_cmd_ssl(Jim_Interp *interp, int argc, Jim_Obj *const *argv) ssl = SSL_new(ssl_ctx); if (ssl == NULL) { -#if defined(HAVE_DUP) - close(fd); -#endif - Jim_SetResultString(interp, ERR_error_string(ERR_get_error(), NULL), -1); - return JIM_ERR; + goto out; } SSL_set_cipher_list(ssl, "ALL"); @@ -1246,21 +1240,18 @@ static int aio_cmd_ssl(Jim_Interp *interp, int argc, Jim_Obj *const *argv) } } - af = JimMakeChannel(interp, NULL, fd, NULL, "aio.sslstream%ld", af->addr_family, "r+"); - if (af == NULL) { - goto out; - } - af->ssl = ssl; af->fops = &ssl_fops; + /* Set the command name as the result */ + Jim_SetResult(interp, argv[0]); + return JIM_OK; out: -#if defined(HAVE_DUP) - close(fd); -#endif - SSL_free(ssl); + if (ssl) { + SSL_free(ssl); + } Jim_SetResultString(interp, ERR_error_string(ERR_get_error(), NULL), -1); return JIM_ERR; } |