moonbridge

changeset 260:1dc729343830

Use (blocking) tls_close() on :finish() and :close()
author jbe
date Mon Sep 19 01:12:38 2016 +0200 (2016-09-19)
parents 385b6607785a
children 6c634c96805b
files moonbridge_io.c
line diff
     1.1 --- a/moonbridge_io.c	Mon Sep 19 01:05:30 2016 +0200
     1.2 +++ b/moonbridge_io.c	Mon Sep 19 01:12:38 2016 +0200
     1.3 @@ -722,11 +722,27 @@
     1.4      }
     1.5    }
     1.6    handle->finished = 1;
     1.7 +#ifdef MOONBR_IO_USE_TLS
     1.8 +  if ((handle->addrfam == AF_INET6 || handle->addrfam == AF_INET) && !handle->tls) {
     1.9 +#else
    1.10    if (handle->addrfam == AF_INET6 || handle->addrfam == AF_INET) {
    1.11 +#endif
    1.12      if (shutdown(handle->fd, SHUT_WR)) moonbr_io_return_errmsg();
    1.13    } else {
    1.14  #ifdef MOONBR_IO_USE_TLS
    1.15 -    if (handle->tls) tls_close(handle->tls);
    1.16 +    if (handle->tls) {
    1.17 +      int status;
    1.18 +      if (moonbr_io_handle_set_nonblocking(L, handle, 1)) moonbr_io_return_errmsg();
    1.19 +      do status = tls_close(handle->tls);
    1.20 +      while (status == TLS_WANT_POLLIN || status == TLS_WANT_POLLOUT);
    1.21 +      if (status) {
    1.22 +        close(handle->fd);
    1.23 +        handle->fd = -1;
    1.24 +        lua_pushnil(L);
    1.25 +        lua_pushstring(L, tls_error(handle->tls));
    1.26 +        return 2;
    1.27 +      }
    1.28 +    }
    1.29  #endif
    1.30      if (close(handle->fd)) {
    1.31        handle->fd = -1;
    1.32 @@ -761,6 +777,21 @@
    1.33      } else {
    1.34        handle->closed = 1;
    1.35      }
    1.36 +#ifdef MOONBR_IO_USE_TLS
    1.37 +    if (handle->tls) {
    1.38 +      int status;
    1.39 +      if (moonbr_io_handle_set_nonblocking(L, handle, 1)) moonbr_io_return_errmsg();
    1.40 +      do status = tls_close(handle->tls);
    1.41 +      while (status == TLS_WANT_POLLIN || status == TLS_WANT_POLLOUT);
    1.42 +      if (status) {
    1.43 +        close(handle->fd);
    1.44 +        handle->fd = -1;
    1.45 +        lua_pushnil(L);
    1.46 +        lua_pushstring(L, tls_error(handle->tls));
    1.47 +        return 2;
    1.48 +      }
    1.49 +    }
    1.50 +#endif
    1.51      if (moonbr_io_handle_set_linger(L, handle, -1)) {
    1.52        moonbr_io_prepare_errmsg();
    1.53        close(handle->fd);
    1.54 @@ -771,9 +802,6 @@
    1.55      handle->closed = 1;
    1.56    }
    1.57    if (handle->fd >= 0) {
    1.58 -#ifdef MOONBR_IO_USE_TLS
    1.59 -    if (handle->tls) tls_close(handle->tls);
    1.60 -#endif
    1.61      if (close(handle->fd)) {
    1.62        handle->fd = -1;
    1.63        moonbr_io_return_errmsg();

Impressum / About Us