diff --git a/net/tcp/tcp_recvwindow.c b/net/tcp/tcp_recvwindow.c index 8de655dce9d..1b0d80ead49 100644 --- a/net/tcp/tcp_recvwindow.c +++ b/net/tcp/tcp_recvwindow.c @@ -52,6 +52,48 @@ #include "tcp/tcp.h" +/**************************************************************************** + * Static Functions + ****************************************************************************/ + +static int tcp_iob_navail(FAR struct net_driver_s *dev, + FAR struct tcp_conn_s *conn) +{ + FAR struct tcp_conn_s *next = NULL; + int avail = iob_navail(true); + int count = 0; + + while ((next = tcp_nextconn(next)) != NULL) + { + if (!IOB_QEMPTY(&next->readahead)) + { + count++; + } + } + + if (count == 0) + { + return avail; + } + + if (avail > CONFIG_IOB_NBUFFERS / count) + { + avail = CONFIG_IOB_NBUFFERS / count; + } + + count = iob_get_queue_count(&conn->readahead); + if (avail > count) + { + avail -= count; + } + else + { + avail = 0; + } + + return avail; +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -112,7 +154,7 @@ uint16_t tcp_get_recvwindow(FAR struct net_driver_s *dev, * (ignoring competition with other IOB consumers). */ - niob_avail = iob_navail(true); + niob_avail = tcp_iob_navail(dev, conn); nqentry_avail = iob_qentry_navail(); /* Is there a a queue entry and IOBs available for read-ahead buffering? */