# HG changeset patch # User jbe # Date 1474240358 -7200 # Node ID 1dc7293438303daaef6be510afebc9acc9520b8c # Parent 385b6607785ab55feee2f27877bfb782d0e64918 Use (blocking) tls_close() on :finish() and :close() diff -r 385b6607785a -r 1dc729343830 moonbridge_io.c --- a/moonbridge_io.c Mon Sep 19 01:05:30 2016 +0200 +++ b/moonbridge_io.c Mon Sep 19 01:12:38 2016 +0200 @@ -722,11 +722,27 @@ } } handle->finished = 1; +#ifdef MOONBR_IO_USE_TLS + if ((handle->addrfam == AF_INET6 || handle->addrfam == AF_INET) && !handle->tls) { +#else if (handle->addrfam == AF_INET6 || handle->addrfam == AF_INET) { +#endif if (shutdown(handle->fd, SHUT_WR)) moonbr_io_return_errmsg(); } else { #ifdef MOONBR_IO_USE_TLS - if (handle->tls) tls_close(handle->tls); + if (handle->tls) { + int status; + if (moonbr_io_handle_set_nonblocking(L, handle, 1)) moonbr_io_return_errmsg(); + do status = tls_close(handle->tls); + while (status == TLS_WANT_POLLIN || status == TLS_WANT_POLLOUT); + if (status) { + close(handle->fd); + handle->fd = -1; + lua_pushnil(L); + lua_pushstring(L, tls_error(handle->tls)); + return 2; + } + } #endif if (close(handle->fd)) { handle->fd = -1; @@ -761,6 +777,21 @@ } else { handle->closed = 1; } +#ifdef MOONBR_IO_USE_TLS + if (handle->tls) { + int status; + if (moonbr_io_handle_set_nonblocking(L, handle, 1)) moonbr_io_return_errmsg(); + do status = tls_close(handle->tls); + while (status == TLS_WANT_POLLIN || status == TLS_WANT_POLLOUT); + if (status) { + close(handle->fd); + handle->fd = -1; + lua_pushnil(L); + lua_pushstring(L, tls_error(handle->tls)); + return 2; + } + } +#endif if (moonbr_io_handle_set_linger(L, handle, -1)) { moonbr_io_prepare_errmsg(); close(handle->fd); @@ -771,9 +802,6 @@ handle->closed = 1; } if (handle->fd >= 0) { -#ifdef MOONBR_IO_USE_TLS - if (handle->tls) tls_close(handle->tls); -#endif if (close(handle->fd)) { handle->fd = -1; moonbr_io_return_errmsg();