Skip to content

Commit

Permalink
tcp: Apply faster PCB recycling in FIN_WAIT_1 or FIN_WAIT_2 state
Browse files Browse the repository at this point in the history
  • Loading branch information
udoudou authored and david-cermak committed Nov 21, 2024
1 parent 5be5d89 commit d2e3d21
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/core/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,9 @@ tcp_kill_state(enum tcp_state state)
struct tcp_pcb *pcb, *inactive;
u32_t inactivity;

#if !ESP_LWIP
LWIP_ASSERT("invalid state", (state == CLOSING) || (state == LAST_ACK));
#endif

inactivity = 0;
inactive = NULL;
Expand Down Expand Up @@ -1870,17 +1872,41 @@ tcp_alloc(u8_t prio)
tcp_kill_state(CLOSING);
/* Try to allocate a tcp_pcb again. */
pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);
#if ESP_LWIP
if (pcb == NULL) {
/* Try killing oldest active connection with lower priority than the new one. */
LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing oldest connection with prio lower than %d\n", prio));
tcp_kill_prio(prio);
/* Try to allocate a tcp_pcb again. */
/* Try killing oldest connection in FIN_WAIT_2. */
LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest FIN_WAIT_2 connection\n"));
tcp_kill_state(FIN_WAIT_2);
pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);
if (pcb == NULL) {
/* Try killing oldest connection in FIN_WAIT_1. */
LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest FIN_WAIT_1 connection\n"));
tcp_kill_state(FIN_WAIT_1);
pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);
#endif
if (pcb == NULL) {
/* Try killing oldest active connection with lower priority than the new one. */
LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing oldest connection with prio lower than %d\n", prio));
tcp_kill_prio(prio);
/* Try to allocate a tcp_pcb again. */
pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);
if (pcb != NULL) {
/* adjust err stats: memp_malloc failed multiple times before */
MEMP_STATS_DEC(err, MEMP_TCP_PCB);
}
}
#if ESP_LWIP
if (pcb != NULL) {
/* adjust err stats: memp_malloc failed multiple times before */
MEMP_STATS_DEC(err, MEMP_TCP_PCB);
}
}
if (pcb != NULL) {
/* adjust err stats: memp_malloc failed multiple times before */
MEMP_STATS_DEC(err, MEMP_TCP_PCB);
}
}
#endif
if (pcb != NULL) {
/* adjust err stats: memp_malloc failed multiple times before */
MEMP_STATS_DEC(err, MEMP_TCP_PCB);
Expand Down

0 comments on commit d2e3d21

Please sign in to comment.