From f888b30863af689530adca59d2239ba3902f80fb Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Tue, 23 Apr 2024 11:24:47 -0300 Subject: [PATCH] TLS corner cases --- src/sock.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sock.c b/src/sock.c index d993dae4..ce53b750 100644 --- a/src/sock.c +++ b/src/sock.c @@ -480,7 +480,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) { size_t max = 1; for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next) { c->is_readable = c->is_writable = 0; - if (mg_tls_pending(c) > 0) ms = 1, c->is_readable = 1; + if (c->rtls.len > 0 || mg_tls_pending(c) > 0) ms = 1, c->is_readable = 1; if (can_write(c)) MG_EPOLL_MOD(c, 1); if (c->is_closing) ms = 1; max++; @@ -496,7 +496,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) { bool wr = evs[i].events & EPOLLOUT; c->is_readable = can_read(c) && rd ? 1U : 0; c->is_writable = can_write(c) && wr ? 1U : 0; - if (mg_tls_pending(c) > 0) c->is_readable = 1; + if (c->rtls.len > 0 || mg_tls_pending(c) > 0) c->is_readable = 1; } } (void) skip_iotest; @@ -510,7 +510,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) { c->is_readable = c->is_writable = 0; if (skip_iotest(c)) { // Socket not valid, ignore - } else if (mg_tls_pending(c) > 0) { + } else if (c->rtls.len > 0 || mg_tls_pending(c) > 0) { ms = 1; // Don't wait if TLS is ready } else { fds[n].fd = FD(c); @@ -532,7 +532,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) { for (struct mg_connection *c = mgr->conns; c != NULL; c = c->next) { if (skip_iotest(c)) { // Socket not valid, ignore - } else if (mg_tls_pending(c) > 0) { + } else if (c->rtls.len > 0 || mg_tls_pending(c) > 0) { c->is_readable = 1; } else { if (fds[n].revents & POLLERR) { @@ -541,7 +541,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) { c->is_readable = (unsigned) (fds[n].revents & (POLLIN | POLLHUP) ? 1 : 0); c->is_writable = (unsigned) (fds[n].revents & POLLOUT ? 1 : 0); - if (mg_tls_pending(c) > 0) c->is_readable = 1; + if (c->rtls.len > 0 || mg_tls_pending(c) > 0) c->is_readable = 1; } n++; } @@ -563,7 +563,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) { FD_SET(FD(c), &eset); if (can_read(c)) FD_SET(FD(c), &rset); if (can_write(c)) FD_SET(FD(c), &wset); - if (mg_tls_pending(c) > 0) tvp = &tv_zero; + if (c->rtls.len > 0 || mg_tls_pending(c) > 0) tvp = &tv_zero; if (FD(c) > maxfd) maxfd = FD(c); if (c->is_closing) ms = 1; } @@ -585,7 +585,7 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) { } else { c->is_readable = FD(c) != MG_INVALID_SOCKET && FD_ISSET(FD(c), &rset); c->is_writable = FD(c) != MG_INVALID_SOCKET && FD_ISSET(FD(c), &wset); - if (mg_tls_pending(c) > 0) c->is_readable = 1; + if (c->rtls.len > 0 || mg_tls_pending(c) > 0) c->is_readable = 1; } } #endif