From 24107d7a481b33d9f315cfc189ce3bee2528ace1 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 15 Aug 2012 22:48:56 +0200 Subject: [PATCH] lwip: purge PCBs in time-wait state more quickly Fixes #33. --- libports/include/lwip/lwipopts.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libports/include/lwip/lwipopts.h b/libports/include/lwip/lwipopts.h index d4dea2e54..c3af641af 100644 --- a/libports/include/lwip/lwipopts.h +++ b/libports/include/lwip/lwipopts.h @@ -49,6 +49,19 @@ #define TCP_MSS 1460 #define TCP_SND_BUF (2 * TCP_MSS) +/* + * We reduce the maximum segment lifetime from one minute to one second to + * avoid queuing up PCBs in TIME-WAIT state. This is the state, PCBs end up + * after closing a TCP connection socket at the server side. The number of PCBs + * in this state is apparently not limited by the value of 'MEMP_NUM_TCP_PCB'. + * One allocation costs around 160 bytes. If clients connect to the server at a + * high rate, those allocations accumulate quickly and thereby may exhaust the + * memory of the server. By reducing the segment lifetime, PCBs in TIME-WAIT + * state are cleaned up from the 'tcp_tw_pcbs' queue in a more timely fashion + * (by 'tcp_slowtmr()'). + */ +#define TCP_MSL 1000UL + #define MEMP_NUM_SYS_TIMEOUT 8 #define MEMP_NUM_TCP_PCB 64 #define MEMP_NUM_NETCONN (MEMP_NUM_TCP_PCB + MEMP_NUM_UDP_PCB + MEMP_NUM_RAW_PCB + MEMP_NUM_TCP_PCB_LISTEN - 1)