moonbridge

changeset 247:ba5ed7cf0a30

Modifications to poll(...) function in regard to TLS handshake
author jbe
date Wed Aug 24 23:50:22 2016 +0200 (2016-08-24)
parents 00e1ee683355
children 4c9102fb77eb
files moonbridge_io.c
line diff
     1.1 --- a/moonbridge_io.c	Mon Aug 22 01:31:48 2016 +0200
     1.2 +++ b/moonbridge_io.c	Wed Aug 24 23:50:22 2016 +0200
     1.3 @@ -1561,6 +1561,18 @@
     1.4          if (handle) {
     1.5            if (handle->closed) luaL_error(L, "Attempt to poll a closed connection");
     1.6            fd = handle->fd;
     1.7 +#if MOONBR_IO_USE_TLS
     1.8 +          if (handle->tls && tls_handshake(handle->tls) == TLS_WANT_POLLOUT) {
     1.9 +            if (fd < 0) {
    1.10 +              // TODO?
    1.11 +              lua_pushboolean(L, 1);
    1.12 +              return 1;
    1.13 +            }
    1.14 +            FD_SET(fd, &writefds);
    1.15 +            if (fd+1 > nfds) nfds = fd+1;
    1.16 +            continue;
    1.17 +          }
    1.18 +#endif
    1.19            if (
    1.20              fd < 0 ||  /* fake EOF to simulate shutdown if fd < 0 */
    1.21              handle->readbufin != handle->readbufout  /* data pending in buffer */
    1.22 @@ -1593,6 +1605,13 @@
    1.23            if (handle->closed) luaL_error(L, "Attempt to poll a closed connection");
    1.24            if (handle->finished) luaL_error(L, "Attempt to write-poll a finished connection");
    1.25            fd = handle->fd;
    1.26 +#if MOONBR_IO_USE_TLS
    1.27 +          if (handle->tls && tls_handshake(handle->tls) == TLS_WANT_POLLIN) {
    1.28 +            FD_SET(fd, &readfds);
    1.29 +            if (fd+1 > nfds) nfds = fd+1;
    1.30 +            continue;
    1.31 +          }
    1.32 +#endif
    1.33          } else {
    1.34            listener = luaL_testudata(L, -2, MOONBR_IO_LISTENER_MT_REGKEY);
    1.35            if (listener) luaL_error(L, "Attempt to write-poll a listener");
    1.36 @@ -1791,6 +1810,7 @@
    1.37    tlsconf = luaL_checkudata(L, 2, MOONBR_IO_TLSCONF_MT_REGKEY);
    1.38    if (handle->closed) return luaL_error(L, "Attempt to start TLS on a closed I/O handle");
    1.39    if (handle->finished) return luaL_error(L, "Attempt to start TLS on a finished I/O handle");
    1.40 +  if (handle->tls) return luaL_error(L, "Attempt to start TLS twice");
    1.41    if (handle->readbufin || handle->writebufin) {
    1.42      return luaL_error(L, "Attempt to start TLS on an I/O handle with non-empty buffers");
    1.43    }

Impressum / About Us