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:
goldsimon
2007-12-21 16:47:56 +00:00
parent 48e62e25e9
commit 1ed34774c8
11 changed files with 93 additions and 11 deletions

View File

@@ -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.
*/

View File

@@ -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;
}

View File

@@ -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;