@@ -4769,9 +4769,8 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
4769
4769
}
4770
4770
tx_tcp(c->mgr->ifp, s->mac, rem_ip, flags, c->loc.port, c->rem.port,
4771
4771
mg_htonl(s->seq), mg_htonl(s->ack), "", 0);
4772
- } else if (pkt->pay.len == 0) { // this is an ACK
4773
- if (s->fin_rcvd && s->ttype == MIP_TTYPE_FIN)
4774
- s->twclosure = true;
4772
+ } else if (pkt->pay.len == 0) { // this is an ACK
4773
+ if (s->fin_rcvd && s->ttype == MIP_TTYPE_FIN) s->twclosure = true;
4775
4774
} else if (seq != s->ack) {
4776
4775
uint32_t ack = (uint32_t) (mg_htonl(pkt->tcp->seq) + pkt->pay.len);
4777
4776
if (s->ack == ack) {
@@ -5242,17 +5241,20 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
5242
5241
tmp = c->next;
5243
5242
struct connstate *s = (struct connstate *) (c + 1);
5244
5243
mg_call(c, MG_EV_POLL, &now);
5245
- MG_VERBOSE(("%lu .. %c%c%c%c%c", c->id, c->is_tls ? 'T' : 't',
5244
+ MG_VERBOSE(("%lu .. %c%c%c%c%c %lu %lu ", c->id, c->is_tls ? 'T' : 't',
5246
5245
c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h',
5247
- c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c'));
5248
- // order is important, TLS conn close with > 1 record in buffer
5249
- if (c->is_tls && mg_tls_pending(c) > 0) handle_tls_recv(c);
5246
+ c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c',
5247
+ mg_tls_pending(c), c->rtls.len));
5248
+ // order is important, TLS conn close with > 1 record in buffer (below)
5249
+ if (c->is_tls && (c->rtls.len > 0 || mg_tls_pending(c) > 0))
5250
+ handle_tls_recv(c);
5250
5251
if (can_write(c)) write_conn(c);
5251
5252
if (c->is_draining && c->send.len == 0 && s->ttype != MIP_TTYPE_FIN)
5252
5253
init_closure(c);
5253
5254
// For non-TLS, close immediately upon completing the 3-way closure
5254
- // For TLS, process any pending data until MIP_TTYPE_FIN timeout expires
5255
- if (s->twclosure && (!c->is_tls || mg_tls_pending(c) == 0))
5255
+ // For TLS, handle any pending data (above) until MIP_TTYPE_FIN expires
5256
+ if (s->twclosure &&
5257
+ (!c->is_tls || (c->rtls.len == 0 && mg_tls_pending(c) == 0)))
5256
5258
c->is_closing = 1;
5257
5259
if (c->is_closing) close_conn(c);
5258
5260
}
0 commit comments