From 30070b06dfff52c05ff2f2f0f6c1d7eebd1af365 Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Mon, 18 Dec 2017 12:11:52 +0000 Subject: [PATCH] Merged in masayuki2009/nuttx.nuttx/tcp_rcvwnd_control (pull request #555) net/tcp: Introduce tcp receive window control based on I/O buffer NOTE: The algorithm is still experimental but useful for http streaming. Signed-off-by: Masayuki Ishikawa Approved-by: Gregory Nutt --- net/tcp/Kconfig | 9 +++++++++ net/tcp/tcp_send.c | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/net/tcp/Kconfig b/net/tcp/Kconfig index fac41794dcf..77cebe81fbe 100644 --- a/net/tcp/Kconfig +++ b/net/tcp/Kconfig @@ -192,4 +192,13 @@ config NET_SENDFILE files out a TCP connection. endif # NET_TCP && !NET_TCP_NO_STACK + +config NET_TCP_RWND_CONTROL + bool "Receive window control based on IOBuffer" + default n + depends on MM_IOB && EXPERIMENTAL + ---help--- + Support receive window control based on I/O buffer. This feature + is still experimental. + endmenu # TCP/IP Networking diff --git a/net/tcp/tcp_send.c b/net/tcp/tcp_send.c index 6797c9d279a..b4e833aa9b0 100644 --- a/net/tcp/tcp_send.c +++ b/net/tcp/tcp_send.c @@ -54,6 +54,10 @@ #include #include +#ifdef CONFIG_NET_TCP_RWND_CONTROL +# include +#endif + #include "devif/devif.h" #include "inet/inet.h" #include "tcp/tcp.h" @@ -309,6 +313,12 @@ static void tcp_sendcommon(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, FAR struct tcp_hdr_s *tcp) { +#ifdef CONFIG_NET_TCP_RWND_CONTROL + extern sem_t g_qentry_sem; + int qentry_sem_count; + uint32_t rwnd; +#endif + /* Copy the IP address into the IPv6 header */ #ifdef CONFIG_NET_IPv6 @@ -341,6 +351,19 @@ static void tcp_sendcommon(FAR struct net_driver_s *dev, tcp->srcport = conn->lport; tcp->destport = conn->rport; +#ifdef CONFIG_NET_TCP_RWND_CONTROL + /* Update the TCP received window based on I/O buffer */ + /* NOTE: This algorithm is still experimental */ + + if (OK == nxsem_getvalue(&g_qentry_sem, &qentry_sem_count)) + { + rwnd = (qentry_sem_count * CONFIG_NET_ETH_TCP_RECVWNDO) + / CONFIG_IOB_NCHAINS; + + NET_DEV_RCVWNDO(dev) = (uint16_t)rwnd; + } +#endif + /* Set the TCP window */ if (conn->tcpstateflags & TCP_STOPPED)