mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-08-09 17:13:49 +08:00
tcp.h, opt.h, api.h, api_msg.h, tcp.c, tcp_in.c, api_lib.c, api_msg.c, sockets.c, init.c: task #7252: Implement TCP listen backlog: Warning: raw API applications have to call 'tcp_accepted(pcb)' in their accept callback to keep accepting new connections.
This commit is contained in:
@@ -152,6 +152,10 @@
|
||||
#if (MEM_USE_POOLS && !MEMP_USE_CUSTOM_POOLS)
|
||||
#error "MEM_USE_POOLS requires custom pools (MEMP_USE_CUSTOM_POOLS) to be enabled in your lwipopts.h"
|
||||
#endif
|
||||
#if (LWIP_DEFAULT_LISTEN_BACKLOG < 0) || (LWIP_DEFAULT_LISTEN_BACKLOG > 255)
|
||||
#error "LWIP_DEFAULT_LISTEN_BACKLOG must fit into an u8_t"
|
||||
#endif
|
||||
|
||||
|
||||
/* Compile-time checks for deprecated options.
|
||||
*/
|
||||
|
||||
@@ -368,6 +368,10 @@ tcp_listen(struct tcp_pcb *pcb)
|
||||
#if LWIP_CALLBACK_API
|
||||
lpcb->accept = tcp_accept_null;
|
||||
#endif /* LWIP_CALLBACK_API */
|
||||
#if LWIP_LISTEN_BACKLOG
|
||||
lpcb->accepts_pending = 0;
|
||||
lpcb->backlog = LWIP_DEFAULT_LISTEN_BACKLOG;
|
||||
#endif /* LWIP_LISTEN_BACKLOG */
|
||||
TCP_REG(&tcp_listen_pcbs.listen_pcbs, lpcb);
|
||||
return (struct tcp_pcb *)lpcb;
|
||||
}
|
||||
|
||||
@@ -381,6 +381,11 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
|
||||
tcphdr->dest, tcphdr->src);
|
||||
} else if (flags & TCP_SYN) {
|
||||
LWIP_DEBUGF(TCP_DEBUG, ("TCP connection request %"U16_F" -> %"U16_F".\n", tcphdr->src, tcphdr->dest));
|
||||
#if LWIP_LISTEN_BACKLOG
|
||||
if (pcb->accepts_pending >= pcb->backlog) {
|
||||
return ERR_ABRT;
|
||||
}
|
||||
#endif /* LWIP_LISTEN_BACKLOG */
|
||||
npcb = tcp_alloc(pcb->prio);
|
||||
/* If a new PCB could not be created (probably due to lack of memory),
|
||||
we don't do anything, but rely on the sender will retransmit the
|
||||
@@ -390,6 +395,9 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
|
||||
TCP_STATS_INC(tcp.memerr);
|
||||
return ERR_MEM;
|
||||
}
|
||||
#if LWIP_LISTEN_BACKLOG
|
||||
pcb->accepts_pending++;
|
||||
#endif /* LWIP_LISTEN_BACKLOG */
|
||||
/* Set up the new PCB. */
|
||||
ip_addr_set(&(npcb->local_ip), &(iphdr->dest));
|
||||
npcb->local_port = pcb->local_port;
|
||||
|
||||
Reference in New Issue
Block a user