From afcb4d9df70571af7b9823465409b5ba9985f4e9 Mon Sep 17 00:00:00 2001 From: Deomid Ryabkov Date: Sun, 9 Oct 2022 16:36:51 +0100 Subject: [PATCH] Do not post MG_SIG_CLOSE_CONN if the conn is already closing --- mongoose.c | 6 ++++-- src/common/platforms/lwip/mg_lwip_net_if.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mongoose.c b/mongoose.c index 5471039f..0d779081 100644 --- a/mongoose.c +++ b/mongoose.c @@ -15129,8 +15129,10 @@ static err_t mg_lwip_tcp_sent_cb(void *arg, struct tcp_pcb *tpcb, struct mg_connection *nc = (struct mg_connection *) arg; DBG(("%p %p %u %p %p", nc, tpcb, num_sent, tpcb->unsent, tpcb->unacked)); if (nc == NULL) return ERR_OK; - if ((nc->flags & MG_F_SEND_AND_CLOSE) && !(nc->flags & MG_F_WANT_WRITE) && - nc->send_mbuf.len == 0 && tpcb->unsent == NULL && tpcb->unacked == NULL) { + if ((nc->flags & (MG_F_SEND_AND_CLOSE | MG_F_CLOSE_IMMEDIATELY)) == + MG_F_SEND_AND_CLOSE && + !(nc->flags & MG_F_WANT_WRITE) && nc->send_mbuf.len == 0 && + tpcb->unsent == NULL && tpcb->unacked == NULL) { mg_lwip_post_signal(MG_SIG_CLOSE_CONN, nc); } if (nc->send_mbuf.len > 0 || (nc->flags & MG_F_WANT_WRITE)) { diff --git a/src/common/platforms/lwip/mg_lwip_net_if.c b/src/common/platforms/lwip/mg_lwip_net_if.c index 6b38cceb..cbf98461 100644 --- a/src/common/platforms/lwip/mg_lwip_net_if.c +++ b/src/common/platforms/lwip/mg_lwip_net_if.c @@ -203,8 +203,10 @@ static err_t mg_lwip_tcp_sent_cb(void *arg, struct tcp_pcb *tpcb, struct mg_connection *nc = (struct mg_connection *) arg; DBG(("%p %p %u %p %p", nc, tpcb, num_sent, tpcb->unsent, tpcb->unacked)); if (nc == NULL) return ERR_OK; - if ((nc->flags & MG_F_SEND_AND_CLOSE) && !(nc->flags & MG_F_WANT_WRITE) && - nc->send_mbuf.len == 0 && tpcb->unsent == NULL && tpcb->unacked == NULL) { + if ((nc->flags & (MG_F_SEND_AND_CLOSE | MG_F_CLOSE_IMMEDIATELY)) == + MG_F_SEND_AND_CLOSE && + !(nc->flags & MG_F_WANT_WRITE) && nc->send_mbuf.len == 0 && + tpcb->unsent == NULL && tpcb->unacked == NULL) { mg_lwip_post_signal(MG_SIG_CLOSE_CONN, nc); } if (nc->send_mbuf.len > 0 || (nc->flags & MG_F_WANT_WRITE)) {