From 8cb64698aad3e34aa45f0c6cb9592563d24c3cd0 Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Thu, 18 Feb 2016 09:33:21 -0600 Subject: [PATCH] Allow backlog to be updated This commit adds support to the sockets and netconn layer to update the backlog by calling listen when the netconn is already in the listen state. When backlog is not enabled, the call returns successfully This commit also introduces a macro for setting the backlog value that prevents a 0 sized (invalid) backlog --- src/api/api_msg.c | 6 ++++++ src/core/tcp.c | 2 +- src/include/lwip/tcp.h | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 198085f6..a9ff802b 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -1308,6 +1308,12 @@ lwip_netconn_do_listen(struct api_msg_msg *msg) } } } + } else if (msg->conn->state == NETCONN_LISTEN) { + /* already listening, allow updating of the backlog */ + msg->err = ERR_OK; +#if TCP_LISTEN_BACKLOG + tcp_backlog_set(msg->conn->pcb.tcp, msg->msg.lb.backlog); +#endif /* TCP_LISTEN_BACKLOG */ } } else { msg->err = ERR_ARG; diff --git a/src/core/tcp.c b/src/core/tcp.c index 58315d74..46f29808 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -587,7 +587,7 @@ tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog) #endif /* LWIP_CALLBACK_API */ #if TCP_LISTEN_BACKLOG lpcb->accepts_pending = 0; - lpcb->backlog = (backlog ? backlog : 1); + tcp_backlog_set(lpcb, backlog); #endif /* TCP_LISTEN_BACKLOG */ TCP_REG(&tcp_listen_pcbs.pcbs, (struct tcp_pcb *)lpcb); return (struct tcp_pcb *)lpcb; diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h index 1c7440f4..dddd0fbc 100644 --- a/src/include/lwip/tcp.h +++ b/src/include/lwip/tcp.h @@ -362,6 +362,9 @@ void tcp_err (struct tcp_pcb *pcb, tcp_err_fn err); #define tcp_accepted(pcb) do { \ LWIP_ASSERT("pcb->state == LISTEN (called for wrong pcb?)", pcb->state == LISTEN); \ (((struct tcp_pcb_listen *)(pcb))->accepts_pending--); } while(0) +#define tcp_backlog_set(pcb, new_backlog) do { \ + LWIP_ASSERT("pcb->state == LISTEN (called for wrong pcb?)", (pcb)->state == LISTEN); \ + ((struct tcp_pcb_listen *)(pcb))->backlog = ((new_backlog) ? (new_backlog) : 1); } while(0) #else /* TCP_LISTEN_BACKLOG */ #define tcp_accepted(pcb) LWIP_ASSERT("pcb->state == LISTEN (called for wrong pcb?)", \ (pcb)->state == LISTEN)