Merge pull request #2587 from cesanta/tls

Fix #2570: close only when TLS buffers drained
This commit is contained in:
Sergio R. Caprile 2024-01-23 14:03:33 -03:00 committed by GitHub
commit 8dc62c25ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 10 deletions

View File

@ -7299,15 +7299,13 @@ static void read_conn(struct mg_connection *c) {
n = recv_raw(c, (char *) &c->rtls.buf[c->rtls.len],
c->rtls.size - c->rtls.len);
// MG_DEBUG(("%lu %ld", c->id, n));
if (n == MG_IO_ERR) {
if (n == MG_IO_ERR && mg_tls_pending(c) == 0 && c->rtls.len == 0) {
c->is_closing = 1;
} else if (n > 0) {
c->rtls.len += (size_t) n;
} else {
if (n > 0) c->rtls.len += (size_t) n;
if (c->is_tls_hs) mg_tls_handshake(c);
if (c->is_tls_hs) return;
n = mg_tls_recv(c, buf, len);
} else if (n == MG_IO_WAIT) {
n = mg_tls_recv(c, buf, len);
}
} else {
n = recv_raw(c, buf, len);

View File

@ -282,15 +282,14 @@ static void read_conn(struct mg_connection *c) {
n = recv_raw(c, (char *) &c->rtls.buf[c->rtls.len],
c->rtls.size - c->rtls.len);
// MG_DEBUG(("%lu %ld", c->id, n));
if (n == MG_IO_ERR) {
if (n == MG_IO_ERR && mg_tls_pending(c) == 0 && c->rtls.len == 0) {
// Close only if we have fully drained both raw (rtls) and TLS buffers
c->is_closing = 1;
} else if (n > 0) {
c->rtls.len += (size_t) n;
} else {
if (n > 0) c->rtls.len += (size_t) n;
if (c->is_tls_hs) mg_tls_handshake(c);
if (c->is_tls_hs) return;
n = mg_tls_recv(c, buf, len);
} else if (n == MG_IO_WAIT) {
n = mg_tls_recv(c, buf, len);
}
} else {
n = recv_raw(c, buf, len);