# HG changeset patch # User jbe # Date 1472075422 -7200 # Node ID ba5ed7cf0a30c5498611cdab88b95c0fcb94cf3a # Parent 00e1ee683355790a12c026d6cf2e2861e4c9405e Modifications to poll(...) function in regard to TLS handshake diff -r 00e1ee683355 -r ba5ed7cf0a30 moonbridge_io.c --- a/moonbridge_io.c Mon Aug 22 01:31:48 2016 +0200 +++ b/moonbridge_io.c Wed Aug 24 23:50:22 2016 +0200 @@ -1561,6 +1561,18 @@ if (handle) { if (handle->closed) luaL_error(L, "Attempt to poll a closed connection"); fd = handle->fd; +#if MOONBR_IO_USE_TLS + if (handle->tls && tls_handshake(handle->tls) == TLS_WANT_POLLOUT) { + if (fd < 0) { + // TODO? + lua_pushboolean(L, 1); + return 1; + } + FD_SET(fd, &writefds); + if (fd+1 > nfds) nfds = fd+1; + continue; + } +#endif if ( fd < 0 || /* fake EOF to simulate shutdown if fd < 0 */ handle->readbufin != handle->readbufout /* data pending in buffer */ @@ -1593,6 +1605,13 @@ if (handle->closed) luaL_error(L, "Attempt to poll a closed connection"); if (handle->finished) luaL_error(L, "Attempt to write-poll a finished connection"); fd = handle->fd; +#if MOONBR_IO_USE_TLS + if (handle->tls && tls_handshake(handle->tls) == TLS_WANT_POLLIN) { + FD_SET(fd, &readfds); + if (fd+1 > nfds) nfds = fd+1; + continue; + } +#endif } else { listener = luaL_testudata(L, -2, MOONBR_IO_LISTENER_MT_REGKEY); if (listener) luaL_error(L, "Attempt to write-poll a listener"); @@ -1791,6 +1810,7 @@ tlsconf = luaL_checkudata(L, 2, MOONBR_IO_TLSCONF_MT_REGKEY); if (handle->closed) return luaL_error(L, "Attempt to start TLS on a closed I/O handle"); if (handle->finished) return luaL_error(L, "Attempt to start TLS on a finished I/O handle"); + if (handle->tls) return luaL_error(L, "Attempt to start TLS twice"); if (handle->readbufin || handle->writebufin) { return luaL_error(L, "Attempt to start TLS on an I/O handle with non-empty buffers"); }