From 8f9dfe0be13b223bec19c2bd3ae687df1e66ec16 Mon Sep 17 00:00:00 2001 From: Fotis Panagiotopoulos Date: Fri, 4 Nov 2022 12:38:07 +0200 Subject: [PATCH] Improvements in TCP connections allocation. --- .../c5471/c5471evm/configs/httpd/defconfig | 2 +- .../lincoln60/configs/thttpd-binfs/defconfig | 2 +- .../configs/thttpd/defconfig | 2 +- .../olimex-lpc1766stk/configs/ftpc/defconfig | 2 +- .../configs/slip-httpd/defconfig | 2 +- .../configs/thttpd-binfs/defconfig | 2 +- .../configs/thttpd-nxflat/defconfig | 2 +- .../zkit-arm-1769/configs/hello/defconfig | 2 +- .../zkit-arm-1769/configs/thttpd/defconfig | 2 +- .../bambino-200e/configs/netnsh/defconfig | 2 +- .../arm/sam34/sam4e-ek/configs/nsh/defconfig | 2 +- .../arm/sam34/sam4e-ek/configs/nxwm/defconfig | 2 +- .../sam34/sam4e-ek/configs/usbnsh/defconfig | 2 +- .../arm/stm32/cloudctrl/configs/nsh/defconfig | 2 +- .../stm32/fire-stm32v2/configs/nsh/defconfig | 2 +- .../configs/discover/defconfig | 2 +- .../configs/netnsh/defconfig | 2 +- .../configs/telnetd/defconfig | 2 +- .../configs/webserver/defconfig | 2 +- .../olimex-stm32-p107/configs/nsh/defconfig | 2 +- .../arm/stm32/shenzhou/configs/nsh/defconfig | 2 +- .../arm/stm32/shenzhou/configs/nxwm/defconfig | 2 +- .../stm32/shenzhou/configs/thttpd/defconfig | 2 +- .../stm3220g-eval/configs/nettest/defconfig | 2 +- .../stm32/stm3220g-eval/configs/nsh/defconfig | 2 +- .../stm3220g-eval/configs/nsh2/defconfig | 2 +- .../stm3220g-eval/configs/nxwm/defconfig | 2 +- .../stm3220g-eval/configs/telnetd/defconfig | 2 +- .../stm3240g-eval/configs/discover/defconfig | 2 +- .../stm3240g-eval/configs/nettest/defconfig | 2 +- .../stm32/stm3240g-eval/configs/nsh/defconfig | 2 +- .../stm3240g-eval/configs/nsh2/defconfig | 2 +- .../stm3240g-eval/configs/nxterm/defconfig | 2 +- .../stm3240g-eval/configs/nxwm/defconfig | 2 +- .../stm3240g-eval/configs/telnetd/defconfig | 2 +- .../stm3240g-eval/configs/webserver/defconfig | 2 +- .../stm3240g-eval/configs/xmlrpc/defconfig | 2 +- .../configs/ether_w5500/defconfig | 2 +- .../configs/netnsh/defconfig | 2 +- .../configs/tcpblaster/defconfig | 2 +- .../arm/tiva/eagle100/configs/httpd/defconfig | 2 +- .../tiva/eagle100/configs/thttpd/defconfig | 2 +- .../lm3s6965-ek/configs/tcpecho/defconfig | 2 +- .../pic32mx-starterkit/configs/nsh2/defconfig | 2 +- .../pic32mx/pic32mx7mmb/configs/nsh/defconfig | 2 +- .../misoc/lm32/misoc/configs/hello/defconfig | 2 +- boards/sim/sim/sim/configs/nettest/defconfig | 2 +- .../ez80f910200zco/configs/httpd/defconfig | 2 +- include/nuttx/net/netconfig.h | 18 +------ net/tcp/Kconfig | 41 +++++++++++++-- net/tcp/tcp_conn.c | 51 +++++++++++++++---- 51 files changed, 128 insertions(+), 78 deletions(-) diff --git a/boards/arm/c5471/c5471evm/configs/httpd/defconfig b/boards/arm/c5471/c5471evm/configs/httpd/defconfig index b43a7d58ea..66740d662e 100644 --- a/boards/arm/c5471/c5471evm/configs/httpd/defconfig +++ b/boards/arm/c5471/c5471evm/configs/httpd/defconfig @@ -29,7 +29,7 @@ CONFIG_NET_MAX_LISTENPORTS=8 CONFIG_NET_SOCKOPTS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_PTHREAD_STACK_DEFAULT=4096 CONFIG_RAM_SIZE=285212672 CONFIG_RAM_START=0 diff --git a/boards/arm/lpc17xx_40xx/lincoln60/configs/thttpd-binfs/defconfig b/boards/arm/lpc17xx_40xx/lincoln60/configs/thttpd-binfs/defconfig index 7e0bdebf5d..a1f7992624 100644 --- a/boards/arm/lpc17xx_40xx/lincoln60/configs/thttpd-binfs/defconfig +++ b/boards/arm/lpc17xx_40xx/lincoln60/configs/thttpd-binfs/defconfig @@ -48,7 +48,7 @@ CONFIG_NET_NACTIVESOCKETS=12 CONFIG_NET_SOCKOPTS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=12 +CONFIG_NET_TCP_PREALLOC_CONNS=12 CONFIG_NET_TCP_WRITE_BUFFERS=y CONFIG_NUNGET_CHARS=0 CONFIG_PIPES=y diff --git a/boards/arm/lpc17xx_40xx/lpcxpresso-lpc1768/configs/thttpd/defconfig b/boards/arm/lpc17xx_40xx/lpcxpresso-lpc1768/configs/thttpd/defconfig index 22b441e171..86eeac0d18 100644 --- a/boards/arm/lpc17xx_40xx/lpcxpresso-lpc1768/configs/thttpd/defconfig +++ b/boards/arm/lpc17xx_40xx/lpcxpresso-lpc1768/configs/thttpd/defconfig @@ -37,7 +37,7 @@ CONFIG_NET_MAX_LISTENPORTS=8 CONFIG_NET_SOCKOPTS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NUNGET_CHARS=0 CONFIG_NXFLAT=y CONFIG_PIPES=y diff --git a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/ftpc/defconfig b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/ftpc/defconfig index a8fc9195c2..f272656176 100644 --- a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/ftpc/defconfig +++ b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/ftpc/defconfig @@ -45,7 +45,7 @@ CONFIG_NET_ICMP_SOCKET=y CONFIG_NET_MAX_LISTENPORTS=8 CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_ARCHINIT=y diff --git a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/slip-httpd/defconfig b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/slip-httpd/defconfig index d8b0c31d6d..f2b1645b0a 100644 --- a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/slip-httpd/defconfig +++ b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/slip-httpd/defconfig @@ -36,7 +36,7 @@ CONFIG_NET_SLIP=y CONFIG_NET_SOCKOPTS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NUNGET_CHARS=0 CONFIG_NXFLAT=y CONFIG_PIPES=y diff --git a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-binfs/defconfig b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-binfs/defconfig index 5f501b8e90..788f09d5fb 100644 --- a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-binfs/defconfig +++ b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-binfs/defconfig @@ -41,7 +41,7 @@ CONFIG_NET_MAX_LISTENPORTS=8 CONFIG_NET_SOCKOPTS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NUNGET_CHARS=0 CONFIG_PIPES=y CONFIG_RAM_SIZE=32768 diff --git a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-nxflat/defconfig b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-nxflat/defconfig index 3678528bed..d52666745d 100644 --- a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-nxflat/defconfig +++ b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-nxflat/defconfig @@ -38,7 +38,7 @@ CONFIG_NET_MAX_LISTENPORTS=8 CONFIG_NET_SOCKOPTS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NUNGET_CHARS=0 CONFIG_NXFLAT=y CONFIG_PIPES=y diff --git a/boards/arm/lpc17xx_40xx/zkit-arm-1769/configs/hello/defconfig b/boards/arm/lpc17xx_40xx/zkit-arm-1769/configs/hello/defconfig index 7fd413782b..df15f119da 100644 --- a/boards/arm/lpc17xx_40xx/zkit-arm-1769/configs/hello/defconfig +++ b/boards/arm/lpc17xx_40xx/zkit-arm-1769/configs/hello/defconfig @@ -35,7 +35,7 @@ CONFIG_NET_MAX_LISTENPORTS=8 CONFIG_NET_SOCKOPTS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NUNGET_CHARS=0 CONFIG_NXFLAT=y CONFIG_RAM_SIZE=32768 diff --git a/boards/arm/lpc17xx_40xx/zkit-arm-1769/configs/thttpd/defconfig b/boards/arm/lpc17xx_40xx/zkit-arm-1769/configs/thttpd/defconfig index 7374e372fa..9dc91ac32f 100644 --- a/boards/arm/lpc17xx_40xx/zkit-arm-1769/configs/thttpd/defconfig +++ b/boards/arm/lpc17xx_40xx/zkit-arm-1769/configs/thttpd/defconfig @@ -40,7 +40,7 @@ CONFIG_NET_MAX_LISTENPORTS=8 CONFIG_NET_SOCKOPTS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NUNGET_CHARS=0 CONFIG_NXFLAT=y CONFIG_PIPES=y diff --git a/boards/arm/lpc43xx/bambino-200e/configs/netnsh/defconfig b/boards/arm/lpc43xx/bambino-200e/configs/netnsh/defconfig index e0eeec8cd0..8a07b2527c 100644 --- a/boards/arm/lpc43xx/bambino-200e/configs/netnsh/defconfig +++ b/boards/arm/lpc43xx/bambino-200e/configs/netnsh/defconfig @@ -59,7 +59,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_ARCHINIT=y diff --git a/boards/arm/sam34/sam4e-ek/configs/nsh/defconfig b/boards/arm/sam34/sam4e-ek/configs/nsh/defconfig index 0aed921c2f..4776c8c52b 100644 --- a/boards/arm/sam34/sam4e-ek/configs/nsh/defconfig +++ b/boards/arm/sam34/sam4e-ek/configs/nsh/defconfig @@ -43,7 +43,7 @@ CONFIG_NET_ICMP_SOCKET=y CONFIG_NET_MAX_LISTENPORTS=16 CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NET_TCP_WRITE_BUFFERS=y CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y diff --git a/boards/arm/sam34/sam4e-ek/configs/nxwm/defconfig b/boards/arm/sam34/sam4e-ek/configs/nxwm/defconfig index d1fbf78e32..71b1032981 100644 --- a/boards/arm/sam34/sam4e-ek/configs/nxwm/defconfig +++ b/boards/arm/sam34/sam4e-ek/configs/nxwm/defconfig @@ -61,7 +61,7 @@ CONFIG_NET_ICMP_SOCKET=y CONFIG_NET_MAX_LISTENPORTS=16 CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_ARCHINIT=y diff --git a/boards/arm/sam34/sam4e-ek/configs/usbnsh/defconfig b/boards/arm/sam34/sam4e-ek/configs/usbnsh/defconfig index ba40da82ea..82f1189e39 100644 --- a/boards/arm/sam34/sam4e-ek/configs/usbnsh/defconfig +++ b/boards/arm/sam34/sam4e-ek/configs/usbnsh/defconfig @@ -51,7 +51,7 @@ CONFIG_NET_ICMP_SOCKET=y CONFIG_NET_MAX_LISTENPORTS=16 CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_ARCHINIT=y diff --git a/boards/arm/stm32/cloudctrl/configs/nsh/defconfig b/boards/arm/stm32/cloudctrl/configs/nsh/defconfig index 5cd72b7a98..7f311a346a 100644 --- a/boards/arm/stm32/cloudctrl/configs/nsh/defconfig +++ b/boards/arm/stm32/cloudctrl/configs/nsh/defconfig @@ -40,7 +40,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_ARCHINIT=y diff --git a/boards/arm/stm32/fire-stm32v2/configs/nsh/defconfig b/boards/arm/stm32/fire-stm32v2/configs/nsh/defconfig index 1bb005f364..ef74b86197 100644 --- a/boards/arm/stm32/fire-stm32v2/configs/nsh/defconfig +++ b/boards/arm/stm32/fire-stm32v2/configs/nsh/defconfig @@ -46,7 +46,7 @@ CONFIG_NET_ICMP_SOCKET=y CONFIG_NET_MAX_LISTENPORTS=16 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_ARCHINIT=y diff --git a/boards/arm/stm32/olimex-stm32-e407/configs/discover/defconfig b/boards/arm/stm32/olimex-stm32-e407/configs/discover/defconfig index eaee0aa150..57f01c3656 100644 --- a/boards/arm/stm32/olimex-stm32-e407/configs/discover/defconfig +++ b/boards/arm/stm32/olimex-stm32-e407/configs/discover/defconfig @@ -38,7 +38,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_PREALLOC_TIMERS=4 diff --git a/boards/arm/stm32/olimex-stm32-e407/configs/netnsh/defconfig b/boards/arm/stm32/olimex-stm32-e407/configs/netnsh/defconfig index e76a865267..a28eec4dd3 100644 --- a/boards/arm/stm32/olimex-stm32-e407/configs/netnsh/defconfig +++ b/boards/arm/stm32/olimex-stm32-e407/configs/netnsh/defconfig @@ -41,7 +41,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_BUILTIN_APPS=y diff --git a/boards/arm/stm32/olimex-stm32-e407/configs/telnetd/defconfig b/boards/arm/stm32/olimex-stm32-e407/configs/telnetd/defconfig index 8bd778e9a1..618fc0d513 100644 --- a/boards/arm/stm32/olimex-stm32-e407/configs/telnetd/defconfig +++ b/boards/arm/stm32/olimex-stm32-e407/configs/telnetd/defconfig @@ -44,7 +44,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_PREALLOC_TIMERS=4 diff --git a/boards/arm/stm32/olimex-stm32-e407/configs/webserver/defconfig b/boards/arm/stm32/olimex-stm32-e407/configs/webserver/defconfig index 2d489b8832..8fcb418f92 100644 --- a/boards/arm/stm32/olimex-stm32-e407/configs/webserver/defconfig +++ b/boards/arm/stm32/olimex-stm32-e407/configs/webserver/defconfig @@ -40,7 +40,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_PREALLOC_TIMERS=4 diff --git a/boards/arm/stm32/olimex-stm32-p107/configs/nsh/defconfig b/boards/arm/stm32/olimex-stm32-p107/configs/nsh/defconfig index 9c9d8811d5..0c2215bad8 100644 --- a/boards/arm/stm32/olimex-stm32-p107/configs/nsh/defconfig +++ b/boards/arm/stm32/olimex-stm32-p107/configs/nsh/defconfig @@ -37,7 +37,7 @@ CONFIG_NET_ICMP=y CONFIG_NET_ICMP_SOCKET=y CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_TCP=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_READLINE=y diff --git a/boards/arm/stm32/shenzhou/configs/nsh/defconfig b/boards/arm/stm32/shenzhou/configs/nsh/defconfig index b0193bda35..b8e9ee196a 100644 --- a/boards/arm/stm32/shenzhou/configs/nsh/defconfig +++ b/boards/arm/stm32/shenzhou/configs/nsh/defconfig @@ -39,7 +39,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_ARCHINIT=y diff --git a/boards/arm/stm32/shenzhou/configs/nxwm/defconfig b/boards/arm/stm32/shenzhou/configs/nxwm/defconfig index 2d88512d76..8e80c6f95a 100644 --- a/boards/arm/stm32/shenzhou/configs/nxwm/defconfig +++ b/boards/arm/stm32/shenzhou/configs/nxwm/defconfig @@ -53,7 +53,7 @@ CONFIG_NET_MAX_LISTENPORTS=16 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_ARCHINIT=y diff --git a/boards/arm/stm32/shenzhou/configs/thttpd/defconfig b/boards/arm/stm32/shenzhou/configs/thttpd/defconfig index 70414c06bb..2df9a74f5e 100644 --- a/boards/arm/stm32/shenzhou/configs/thttpd/defconfig +++ b/boards/arm/stm32/shenzhou/configs/thttpd/defconfig @@ -46,7 +46,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_ARCHINIT=y diff --git a/boards/arm/stm32/stm3220g-eval/configs/nettest/defconfig b/boards/arm/stm32/stm3220g-eval/configs/nettest/defconfig index 06254e4bb2..dd5f3d9790 100644 --- a/boards/arm/stm32/stm3220g-eval/configs/nettest/defconfig +++ b/boards/arm/stm32/stm3220g-eval/configs/nettest/defconfig @@ -33,7 +33,7 @@ CONFIG_NET_ICMP=y CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_SOCKOPTS=y CONFIG_NET_TCP=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NUNGET_CHARS=0 CONFIG_RAM_SIZE=196608 CONFIG_RAM_START=0x20000000 diff --git a/boards/arm/stm32/stm3220g-eval/configs/nsh/defconfig b/boards/arm/stm32/stm3220g-eval/configs/nsh/defconfig index 5cfce6c8da..c2f3c17ef1 100644 --- a/boards/arm/stm32/stm3220g-eval/configs/nsh/defconfig +++ b/boards/arm/stm32/stm3220g-eval/configs/nsh/defconfig @@ -42,7 +42,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_BUILTIN_APPS=y diff --git a/boards/arm/stm32/stm3220g-eval/configs/nsh2/defconfig b/boards/arm/stm32/stm3220g-eval/configs/nsh2/defconfig index e71af6c3a8..1078fb44fe 100644 --- a/boards/arm/stm32/stm3220g-eval/configs/nsh2/defconfig +++ b/boards/arm/stm32/stm3220g-eval/configs/nsh2/defconfig @@ -52,7 +52,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_ARCHINIT=y diff --git a/boards/arm/stm32/stm3220g-eval/configs/nxwm/defconfig b/boards/arm/stm32/stm3220g-eval/configs/nxwm/defconfig index fb1ce1a428..1eb3b205b7 100644 --- a/boards/arm/stm32/stm3220g-eval/configs/nxwm/defconfig +++ b/boards/arm/stm32/stm3220g-eval/configs/nxwm/defconfig @@ -52,7 +52,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_FILEIOSIZE=512 diff --git a/boards/arm/stm32/stm3220g-eval/configs/telnetd/defconfig b/boards/arm/stm32/stm3220g-eval/configs/telnetd/defconfig index cf1cbed82b..f37f078a50 100644 --- a/boards/arm/stm32/stm3220g-eval/configs/telnetd/defconfig +++ b/boards/arm/stm32/stm3220g-eval/configs/telnetd/defconfig @@ -36,7 +36,7 @@ CONFIG_NET_ICMP=y CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_SOCKOPTS=y CONFIG_NET_TCP=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NUNGET_CHARS=0 CONFIG_RAM_SIZE=196608 CONFIG_RAM_START=0x20000000 diff --git a/boards/arm/stm32/stm3240g-eval/configs/discover/defconfig b/boards/arm/stm32/stm3240g-eval/configs/discover/defconfig index c91b073c9c..4f50a036ce 100644 --- a/boards/arm/stm32/stm3240g-eval/configs/discover/defconfig +++ b/boards/arm/stm32/stm3240g-eval/configs/discover/defconfig @@ -40,7 +40,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_PREALLOC_TIMERS=4 diff --git a/boards/arm/stm32/stm3240g-eval/configs/nettest/defconfig b/boards/arm/stm32/stm3240g-eval/configs/nettest/defconfig index 377286c799..507834a9a5 100644 --- a/boards/arm/stm32/stm3240g-eval/configs/nettest/defconfig +++ b/boards/arm/stm32/stm3240g-eval/configs/nettest/defconfig @@ -35,7 +35,7 @@ CONFIG_NET_ICMP=y CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_SOCKOPTS=y CONFIG_NET_TCP=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NUNGET_CHARS=0 CONFIG_RAM_SIZE=196608 CONFIG_RAM_START=0x20000000 diff --git a/boards/arm/stm32/stm3240g-eval/configs/nsh/defconfig b/boards/arm/stm32/stm3240g-eval/configs/nsh/defconfig index f2b16548e8..a5421e4fa8 100644 --- a/boards/arm/stm32/stm3240g-eval/configs/nsh/defconfig +++ b/boards/arm/stm32/stm3240g-eval/configs/nsh/defconfig @@ -46,7 +46,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_BUILTIN_APPS=y diff --git a/boards/arm/stm32/stm3240g-eval/configs/nsh2/defconfig b/boards/arm/stm32/stm3240g-eval/configs/nsh2/defconfig index e0a0c734da..1296ac118a 100644 --- a/boards/arm/stm32/stm3240g-eval/configs/nsh2/defconfig +++ b/boards/arm/stm32/stm3240g-eval/configs/nsh2/defconfig @@ -53,7 +53,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_ARCHINIT=y diff --git a/boards/arm/stm32/stm3240g-eval/configs/nxterm/defconfig b/boards/arm/stm32/stm3240g-eval/configs/nxterm/defconfig index 4b1f17f303..43ec247269 100644 --- a/boards/arm/stm32/stm3240g-eval/configs/nxterm/defconfig +++ b/boards/arm/stm32/stm3240g-eval/configs/nxterm/defconfig @@ -55,7 +55,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_BUILTIN_APPS=y diff --git a/boards/arm/stm32/stm3240g-eval/configs/nxwm/defconfig b/boards/arm/stm32/stm3240g-eval/configs/nxwm/defconfig index 271233fb6f..1f0cb71624 100644 --- a/boards/arm/stm32/stm3240g-eval/configs/nxwm/defconfig +++ b/boards/arm/stm32/stm3240g-eval/configs/nxwm/defconfig @@ -52,7 +52,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_FILEIOSIZE=512 diff --git a/boards/arm/stm32/stm3240g-eval/configs/telnetd/defconfig b/boards/arm/stm32/stm3240g-eval/configs/telnetd/defconfig index 11b4d672f9..5c2429c491 100644 --- a/boards/arm/stm32/stm3240g-eval/configs/telnetd/defconfig +++ b/boards/arm/stm32/stm3240g-eval/configs/telnetd/defconfig @@ -37,7 +37,7 @@ CONFIG_NET_ICMP=y CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_SOCKOPTS=y CONFIG_NET_TCP=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NUNGET_CHARS=0 CONFIG_RAM_SIZE=196608 CONFIG_RAM_START=0x20000000 diff --git a/boards/arm/stm32/stm3240g-eval/configs/webserver/defconfig b/boards/arm/stm32/stm3240g-eval/configs/webserver/defconfig index 478006924c..ba3d6964d6 100644 --- a/boards/arm/stm32/stm3240g-eval/configs/webserver/defconfig +++ b/boards/arm/stm32/stm3240g-eval/configs/webserver/defconfig @@ -41,7 +41,7 @@ CONFIG_NET_SOCKOPTS=y CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_FILEIOSIZE=512 diff --git a/boards/arm/stm32/stm3240g-eval/configs/xmlrpc/defconfig b/boards/arm/stm32/stm3240g-eval/configs/xmlrpc/defconfig index e1703134b7..73473c20cc 100644 --- a/boards/arm/stm32/stm3240g-eval/configs/xmlrpc/defconfig +++ b/boards/arm/stm32/stm3240g-eval/configs/xmlrpc/defconfig @@ -40,7 +40,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_PREALLOC_TIMERS=4 diff --git a/boards/arm/stm32/stm32f4discovery/configs/ether_w5500/defconfig b/boards/arm/stm32/stm32f4discovery/configs/ether_w5500/defconfig index 5daa1d19ee..ecca5b2c5f 100644 --- a/boards/arm/stm32/stm32f4discovery/configs/ether_w5500/defconfig +++ b/boards/arm/stm32/stm32f4discovery/configs/ether_w5500/defconfig @@ -42,7 +42,7 @@ CONFIG_NET_ICMP_SOCKET=y CONFIG_NET_MAX_LISTENPORTS=16 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NET_W5500=y diff --git a/boards/arm/stm32/viewtool-stm32f107/configs/netnsh/defconfig b/boards/arm/stm32/viewtool-stm32f107/configs/netnsh/defconfig index 4dfbe472be..03d5b72c9e 100644 --- a/boards/arm/stm32/viewtool-stm32f107/configs/netnsh/defconfig +++ b/boards/arm/stm32/viewtool-stm32f107/configs/netnsh/defconfig @@ -43,7 +43,7 @@ CONFIG_NET_IPv6=y CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_ROUTE=y CONFIG_NET_TCP=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_TCP_WRITE_BUFFERS=y CONFIG_NET_UDP=y CONFIG_NSH_ARCHINIT=y diff --git a/boards/arm/stm32/viewtool-stm32f107/configs/tcpblaster/defconfig b/boards/arm/stm32/viewtool-stm32f107/configs/tcpblaster/defconfig index caa2c442a0..d5c556005c 100644 --- a/boards/arm/stm32/viewtool-stm32f107/configs/tcpblaster/defconfig +++ b/boards/arm/stm32/viewtool-stm32f107/configs/tcpblaster/defconfig @@ -38,7 +38,7 @@ CONFIG_NET_SOCKOPTS=y CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_TCP_WRITE_BUFFERS=y CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y diff --git a/boards/arm/tiva/eagle100/configs/httpd/defconfig b/boards/arm/tiva/eagle100/configs/httpd/defconfig index 8993b172ac..3888433b9b 100644 --- a/boards/arm/tiva/eagle100/configs/httpd/defconfig +++ b/boards/arm/tiva/eagle100/configs/httpd/defconfig @@ -30,7 +30,7 @@ CONFIG_NET_SOCKOPTS=y CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NUNGET_CHARS=0 CONFIG_RAM_SIZE=65536 CONFIG_RAM_START=0x20000000 diff --git a/boards/arm/tiva/eagle100/configs/thttpd/defconfig b/boards/arm/tiva/eagle100/configs/thttpd/defconfig index b724af6798..531b8e7b64 100644 --- a/boards/arm/tiva/eagle100/configs/thttpd/defconfig +++ b/boards/arm/tiva/eagle100/configs/thttpd/defconfig @@ -31,7 +31,7 @@ CONFIG_NET_MAX_LISTENPORTS=8 CONFIG_NET_SOCKOPTS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NUNGET_CHARS=0 CONFIG_NXFLAT=y CONFIG_PIPES=y diff --git a/boards/arm/tiva/lm3s6965-ek/configs/tcpecho/defconfig b/boards/arm/tiva/lm3s6965-ek/configs/tcpecho/defconfig index c63aecafeb..c0c55edb03 100644 --- a/boards/arm/tiva/lm3s6965-ek/configs/tcpecho/defconfig +++ b/boards/arm/tiva/lm3s6965-ek/configs/tcpecho/defconfig @@ -38,7 +38,7 @@ CONFIG_NET_MAX_LISTENPORTS=8 CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_PREALLOC_TIMERS=4 diff --git a/boards/mips/pic32mx/pic32mx-starterkit/configs/nsh2/defconfig b/boards/mips/pic32mx/pic32mx-starterkit/configs/nsh2/defconfig index 412ac92ce6..51f63ed9a3 100644 --- a/boards/mips/pic32mx/pic32mx-starterkit/configs/nsh2/defconfig +++ b/boards/mips/pic32mx/pic32mx-starterkit/configs/nsh2/defconfig @@ -45,7 +45,7 @@ CONFIG_NET_ICMP_SOCKET=y CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_ARCHINIT=y diff --git a/boards/mips/pic32mx/pic32mx7mmb/configs/nsh/defconfig b/boards/mips/pic32mx/pic32mx7mmb/configs/nsh/defconfig index f4650acc55..59196ad95d 100644 --- a/boards/mips/pic32mx/pic32mx7mmb/configs/nsh/defconfig +++ b/boards/mips/pic32mx/pic32mx7mmb/configs/nsh/defconfig @@ -47,7 +47,7 @@ CONFIG_NET_ICMP_SOCKET=y CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y CONFIG_NSH_ARCHINIT=y diff --git a/boards/misoc/lm32/misoc/configs/hello/defconfig b/boards/misoc/lm32/misoc/configs/hello/defconfig index af50b096d4..98fefeb189 100644 --- a/boards/misoc/lm32/misoc/configs/hello/defconfig +++ b/boards/misoc/lm32/misoc/configs/hello/defconfig @@ -59,7 +59,7 @@ CONFIG_NET_ICMP=y CONFIG_NET_ICMP_SOCKET=y CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_TCP=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_NET_TCP_WRITE_BUFFERS=y CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y diff --git a/boards/sim/sim/sim/configs/nettest/defconfig b/boards/sim/sim/sim/configs/nettest/defconfig index d19c646b6c..e40363dc78 100644 --- a/boards/sim/sim/sim/configs/nettest/defconfig +++ b/boards/sim/sim/sim/configs/nettest/defconfig @@ -23,7 +23,7 @@ CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_SOCKOPTS=y CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y -CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_TCP_PREALLOC_CONNS=40 CONFIG_SCHED_LPWORK=y CONFIG_START_DAY=16 CONFIG_START_MONTH=8 diff --git a/boards/z80/ez80/ez80f910200zco/configs/httpd/defconfig b/boards/z80/ez80/ez80f910200zco/configs/httpd/defconfig index 4fe7bd471d..5fe1851e79 100644 --- a/boards/z80/ez80/ez80f910200zco/configs/httpd/defconfig +++ b/boards/z80/ez80/ez80f910200zco/configs/httpd/defconfig @@ -35,7 +35,7 @@ CONFIG_NET_SOCKOPTS=y CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_CONNS=16 +CONFIG_NET_TCP_PREALLOC_CONNS=16 CONFIG_NUNGET_CHARS=0 CONFIG_RAM_SIZE=65536 CONFIG_RR_INTERVAL=200 diff --git a/include/nuttx/net/netconfig.h b/include/nuttx/net/netconfig.h index b2e1b072d2..93e8e80cb8 100644 --- a/include/nuttx/net/netconfig.h +++ b/include/nuttx/net/netconfig.h @@ -416,21 +416,6 @@ /* TCP configuration options */ -/* The maximum number of simultaneously open TCP connections. - * - * Since the TCP connections are statically allocated, turning this - * configuration knob down results in less RAM used. Each TCP - * connection requires approximately 30 bytes of memory. - */ - -#ifndef CONFIG_NET_TCP_CONNS -# ifdef CONFIG_NET_TCP -# define CONFIG_NET_TCP_CONNS 10 -# else -# define CONFIG_NET_TCP_CONNS 0 -# endif -#endif - /* The maximum number of simultaneously listening TCP ports. * * Each listening TCP port requires 2 bytes of memory. @@ -446,7 +431,8 @@ */ #ifndef CONFIG_NET_NACTIVESOCKETS -# define CONFIG_NET_NACTIVESOCKETS (CONFIG_NET_TCP_CONNS + CONFIG_NET_UDP_CONNS) +# define CONFIG_NET_NACTIVESOCKETS (CONFIG_NET_TCP_PREALLOC_CONNS + \ + CONFIG_NET_UDP_CONNS) #endif /* The initial retransmission timeout counted in timer pulses. diff --git a/net/tcp/Kconfig b/net/tcp/Kconfig index b53c20da74..900fea25b2 100644 --- a/net/tcp/Kconfig +++ b/net/tcp/Kconfig @@ -50,11 +50,46 @@ config NET_TCPURGDATA compiled in. Urgent data (out-of-band data) is a rarely used TCP feature that is very seldom would be required. -config NET_TCP_CONNS - int "Number of TCP/IP connections" +config NET_TCP_PREALLOC_CONNS + int "Preallocated TCP/IP connections" default 8 ---help--- - Maximum number of TCP/IP connections (all tasks) + Number of TCP/IP connections (all tasks). + + This number of connections will be pre-allocated during system boot. + If dynamic connections allocation is enabled, more connections may + be allocated at a later time, as the system needs them. Else this + will be the maximum number of connections available to the system + at all times. + + Set to 0 to disable (and rely only on dynamic allocations). + +config NET_TCP_ALLOC_CONNS + int "Dynamic TCP/IP connections allocation" + default 0 + ---help--- + Dynamic memory allocations for TCP/IP. + + When set to 0 all dynamic allocations are disabled. + + When set to 1 a new connection will be allocated every time, + and it will be free'd when no longer needed. + + Setting this to 2 or more will allocate the connections in + batches (with batch size equal to this config). When a + connection is no longer needed, it will be returned to the + free connections pool, and it will never be deallocated! + +config NET_TCP_MAX_CONNS + int "Maximum number of TCP/IP connections" + default 0 + depends on NET_TCP_ALLOC_CONNS > 0 + ---help--- + If dynamic connections allocation is selected (NET_TCP_ALLOC_CONNS > 0) + this will limit the number of connections that can be allocated. + + This is useful in case the system is under very heavy load (or + under attack), ensuring that the heap will not be exhausted. config NET_TCP_NPOLLWAITERS int "Number of TCP poll waiters" diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index 28b2d9c749..e71592b78b 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -76,8 +76,8 @@ /* The array containing all TCP connections. */ -#ifndef CONFIG_NET_ALLOC_CONNS -static struct tcp_conn_s g_tcp_connections[CONFIG_NET_TCP_CONNS]; +#if CONFIG_NET_TCP_PREALLOC_CONNS > 0 +static struct tcp_conn_s g_tcp_connections[CONFIG_NET_TCP_PREALLOC_CONNS]; #endif /* A list of all free TCP connections */ @@ -439,7 +439,7 @@ static inline int tcp_ipv6_bind(FAR struct tcp_conn_s *conn, * ****************************************************************************/ -#ifdef CONFIG_NET_ALLOC_CONNS +#if CONFIG_NET_TCP_ALLOC_CONNS > 0 FAR struct tcp_conn_s *tcp_alloc_conn(void) { FAR struct tcp_conn_s *conn; @@ -449,8 +449,16 @@ FAR struct tcp_conn_s *tcp_alloc_conn(void) if (dq_peek(&g_free_tcp_connections) == NULL) { +#if CONFIG_NET_TCP_MAX_CONNS > 0 + if (dq_count(&g_active_tcp_connections) + CONFIG_NET_TCP_ALLOC_CONNS + >= CONFIG_NET_TCP_MAX_CONNS) + { + return NULL; + } +#endif + conn = kmm_zalloc(sizeof(struct tcp_conn_s) * - CONFIG_NET_TCP_CONNS); + CONFIG_NET_TCP_ALLOC_CONNS); if (conn == NULL) { return conn; @@ -458,7 +466,7 @@ FAR struct tcp_conn_s *tcp_alloc_conn(void) /* Now initialize each connection structure */ - for (i = 0; i < CONFIG_NET_TCP_CONNS; i++) + for (i = 0; i < CONFIG_NET_TCP_ALLOC_CONNS; i++) { /* Mark the connection closed and move it to the free list */ @@ -597,10 +605,10 @@ int tcp_selectport(uint8_t domain, void tcp_initialize(void) { -#ifndef CONFIG_NET_ALLOC_CONNS +#if CONFIG_NET_TCP_PREALLOC_CONNS > 0 int i; - for (i = 0; i < CONFIG_NET_TCP_CONNS; i++) + for (i = 0; i < CONFIG_NET_TCP_PREALLOC_CONNS; i++) { /* Mark the connection closed and move it to the free list */ @@ -700,7 +708,12 @@ FAR struct tcp_conn_s *tcp_alloc(uint8_t domain) tcp_free(conn); - /* Now there is guaranteed to be one free connection. Get it! */ + /* Now there should be one free connection. If dynamic connections + * allocation is disabled, it is guaranteed so. In case that + * dynamic connections are used, it may be already in the free + * list, or at least there should be enough space in the heap for + * a new connection. + */ conn = (FAR struct tcp_conn_s *) dq_remfirst(&g_free_tcp_connections); @@ -710,7 +723,7 @@ FAR struct tcp_conn_s *tcp_alloc(uint8_t domain) /* Allocate the connect entry from heap */ -#ifdef CONFIG_NET_ALLOC_CONNS +#if CONFIG_NET_TCP_ALLOC_CONNS > 0 if (conn == NULL) { conn = tcp_alloc_conn(); @@ -876,10 +889,26 @@ void tcp_free(FAR struct tcp_conn_s *conn) } #endif - /* Mark the connection available and put it into the free list */ + /* Mark the connection available. */ conn->tcpstateflags = TCP_CLOSED; - dq_addlast(&conn->sconn.node, &g_free_tcp_connections); + + /* If this is a preallocated or a batch allocated connection store it in + * the free connections list. Else free it. + */ + +#if CONFIG_NET_TCP_ALLOC_CONNS == 1 + if (conn < g_tcp_connections || conn >= (g_tcp_connections + + CONFIG_NET_TCP_PREALLOC_CONNS)) + { + kmm_free(conn); + } + else +#endif + { + dq_addlast(&conn->sconn.node, &g_free_tcp_connections); + } + net_unlock(); }