From 104106b9cff5692a49849f405ec095427403a81a Mon Sep 17 00:00:00 2001
From: Deomid Ryabkov <rojer@cesanta.com>
Date: Tue, 20 Jun 2017 19:25:43 +0100
Subject: [PATCH] Invoke tcp_accepted() on the listening pcb

As required by the LWIP API

PUBLISHED_FROM=7bfc6d816aa69f8fdd7592ade48b2d52e2d4991a
---
 mongoose.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/mongoose.c b/mongoose.c
index 7cafda28f..7de66e913 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -14481,15 +14481,27 @@ void mg_lwip_handle_accept(struct mg_connection *nc) {
 }
 
 static err_t mg_lwip_accept_cb(void *arg, struct tcp_pcb *newtpcb, err_t err) {
-  struct mg_connection *lc = (struct mg_connection *) arg;
-  DBG(("%p conn %p from %s:%u", lc, newtpcb,
+  struct mg_connection *lc = (struct mg_connection *) arg, *nc;
+  struct mg_lwip_conn_state *lcs, *cs;
+  struct tcp_pcb_listen *lpcb;
+  LOG(LL_INFO,
+      ("%p conn %p from %s:%u", lc, newtpcb,
        IPADDR_NTOA(ipX_2_ip(&newtpcb->remote_ip)), newtpcb->remote_port));
-  struct mg_connection *nc = mg_if_accept_new_conn(lc);
+  if (lc == NULL) {
+    tcp_abort(newtpcb);
+    return ERR_ABRT;
+  }
+  lcs = (struct mg_lwip_conn_state *) lc->sock;
+  lpcb = (struct tcp_pcb_listen *) lcs->pcb.tcp;
+#if TCP_LISTEN_BACKLOG
+  tcp_accepted(lpcb);
+#endif
+  nc = mg_if_accept_new_conn(lc);
   if (nc == NULL) {
     tcp_abort(newtpcb);
     return ERR_ABRT;
   }
-  struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
+  cs = (struct mg_lwip_conn_state *) nc->sock;
   cs->lc = lc;
   cs->pcb.tcp = newtpcb;
   /* We need to set up callbacks before returning because data may start
@@ -14503,6 +14515,7 @@ static err_t mg_lwip_accept_cb(void *arg, struct tcp_pcb *newtpcb, err_t err) {
 #endif
   mg_lwip_post_signal(MG_SIG_ACCEPT, nc);
   (void) err;
+  (void) lpcb;
   return ERR_OK;
 }
 
-- 
GitLab