diff --git a/include/sys/socket.h b/include/sys/socket.h index 770f29b916..b66c1783bc 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -220,6 +220,14 @@ * operations */ +/* The maximum backlog queue length */ + +#ifdef CONFIG_NET_TCPBACKLOG_CONNS +# define SOMAXCONN CONFIG_NET_TCPBACKLOG_CONNS +#else +# define SOMAXCONN 0 +#endif + /**************************************************************************** * Type Definitions ****************************************************************************/ diff --git a/net/tcp/Kconfig b/net/tcp/Kconfig index 8cc7dcf55c..88c6de20cf 100644 --- a/net/tcp/Kconfig +++ b/net/tcp/Kconfig @@ -147,6 +147,16 @@ config NET_TCPBACKLOG Incoming connections pend in a backlog until accept() is called. The size of the backlog is selected when listen() is called. +if NET_TCPBACKLOG + +config NET_TCPBACKLOG_CONNS + int "TCP backlog conns threshold" + default 8 + ---help--- + Maximum number of TCP backlog connections (all tasks). + +endif # NET_TCPBACKLOG + config NET_TCP_SPLIT bool "Enable packet splitting" default n diff --git a/net/tcp/tcp_backlog.c b/net/tcp/tcp_backlog.c index 22e4af0e0f..745cd94d85 100644 --- a/net/tcp/tcp_backlog.c +++ b/net/tcp/tcp_backlog.c @@ -89,6 +89,13 @@ int tcp_backlogcreate(FAR struct tcp_conn_s *conn, int nblg) if (nblg > 0) { + /* nblog value must less than SOMAXCONN */ + + if (nblg > SOMAXCONN) + { + nblg = SOMAXCONN; + } + /* Align the list of backlog structures to 32-bit boundaries. This * may be excessive on 24-16-bit address machines; and insufficient * on 64-bit address machines -- REVISIT