1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

Subject: ssl: stop spinning on close

This commit is contained in:
Martin Milata 2017-04-06 19:37:14 +02:00 committed by Andy Green
parent ca6242a1d3
commit aeb3397c8f
2 changed files with 55 additions and 23 deletions

View file

@ -510,14 +510,28 @@ just_kill_connection:
!wsi->socket_is_permanently_unusable) {
#ifdef LWS_OPENSSL_SUPPORT
if (lws_is_ssl(wsi) && wsi->ssl)
{
lwsl_info("%s: shutting down SSL connection: %p (ssl %p, sock %d, state %d)\n", __func__, wsi, wsi->ssl, (int)(long)wsi->desc.sockfd, wsi->state);
{
lwsl_info("%s: shutting down SSL connection: %p (ssl %p, sock %d, state %d)\n", __func__, wsi, wsi->ssl, (int)(long)wsi->desc.sockfd, wsi->state);
n = SSL_shutdown(wsi->ssl);
if (n == 1) /* If finished the SSL shutdown, then do socket shutdown, else need to retry SSL shutdown */
n = shutdown(wsi->desc.sockfd, SHUT_WR);
else
lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLIN);
}
if (n == 1) /* If finished the SSL shutdown, then do socket shutdown, else need to retry SSL shutdown */
n = shutdown(wsi->desc.sockfd, SHUT_WR);
else if (n == 0)
lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLIN);
else /* n < 0 */
{
int shutdown_error = SSL_get_error(wsi->ssl, n);
lwsl_debug("SSL_shutdown returned %d, SSL_get_error: %d\n", n, shutdown_error);
if (shutdown_error == SSL_ERROR_WANT_READ) {
lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLIN);
n = 0;
} else if (shutdown_error == SSL_ERROR_WANT_WRITE) {
lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLOUT);
n = 0;
} else { // actual error occurred, just close the connection
n = shutdown(wsi->desc.sockfd, SHUT_WR);
}
}
}
else
#endif
{

View file

@ -911,22 +911,40 @@ lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd, int t
#ifdef LWS_OPENSSL_SUPPORT
if ((wsi->state == LWSS_SHUTDOWN) && lws_is_ssl(wsi) && wsi->ssl)
{
n = SSL_shutdown(wsi->ssl);
lwsl_debug("SSH_shutdown=%d for fd %d\n", n, wsi->desc.sockfd);
if (n == 1)
{
n = shutdown(wsi->desc.sockfd, SHUT_WR);
goto close_and_handled;
}
else
{
lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLIN);
n = 0;
goto handled;
}
}
if ((wsi->state == LWSS_SHUTDOWN) && lws_is_ssl(wsi) && wsi->ssl)
{
n = SSL_shutdown(wsi->ssl);
lwsl_debug("SSL_shutdown=%d for fd %d\n", n, wsi->desc.sockfd);
if (n == 1)
{
n = shutdown(wsi->desc.sockfd, SHUT_WR);
goto close_and_handled;
}
else if (n == 0)
{
lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLIN);
n = 0;
goto handled;
}
else /* n < 0 */
{
int shutdown_error = SSL_get_error(wsi->ssl, n);
lwsl_debug("SSL_shutdown returned %d, SSL_get_error: %d\n", n, shutdown_error);
if (shutdown_error == SSL_ERROR_WANT_READ) {
lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLIN);
n = 0;
goto handled;
} else if (shutdown_error == SSL_ERROR_WANT_WRITE) {
lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLOUT);
n = 0;
goto handled;
}
// actual error occurred, just close the connection
n = shutdown(wsi->desc.sockfd, SHUT_WR);
goto close_and_handled;
}
}
#endif
/* okay, what we came here to do... */