This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 0e7d397553d51c70c625843bcd891efb054c887f Author: chao an <[email protected]> AuthorDate: Fri Jan 6 13:50:43 2023 +0800 net/tcp: new api tcp_dataconcat() to concatenate/pack iob chain Signed-off-by: chao an <[email protected]> --- net/tcp/tcp.h | 15 ++++++++++++++ net/tcp/tcp_callback.c | 54 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index f28dd9758a..5637106499 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -1278,6 +1278,21 @@ uint16_t tcp_datahandler(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, uint16_t offset); +/**************************************************************************** + * Name: tcp_dataconcat + * + * Description: + * Concatenate iob_s chain iob2 to iob1, if CONFIG_NET_TCP_RECV_PACK is + * endabled, pack all data in the I/O buffer chain. + * + * Returned Value: + * The number of bytes actually buffered is returned. This will be either + * zero or equal to iob1->io_pktlen. + * + ****************************************************************************/ + +uint16_t tcp_dataconcat(FAR struct iob_s **iob1, FAR struct iob_s **iob2); + /**************************************************************************** * Name: tcp_backlogcreate * diff --git a/net/tcp/tcp_callback.c b/net/tcp/tcp_callback.c index a5f22c4556..3d00cdcc1f 100644 --- a/net/tcp/tcp_callback.c +++ b/net/tcp/tcp_callback.c @@ -196,6 +196,43 @@ uint16_t tcp_callback(FAR struct net_driver_s *dev, return flags; } +/**************************************************************************** + * Name: tcp_dataconcat + * + * Description: + * Concatenate iob_s chain iob2 to iob1, if CONFIG_NET_TCP_RECV_PACK is + * endabled, pack all data in the I/O buffer chain. + * + * Returned Value: + * The number of bytes actually buffered is returned. This will be either + * zero or equal to iob->io_pktlen. + * + ****************************************************************************/ + +uint16_t tcp_dataconcat(FAR struct iob_s **iob1, FAR struct iob_s **iob2) +{ + if (*iob1 == NULL) + { + *iob1 = *iob2; + } + else + { + iob_concat(*iob1, *iob2); + } + + *iob2 = NULL; + +#ifdef CONFIG_NET_TCP_RECV_PACK + /* Merge an iob chain into a continuous space, thereby reducing iob + * consumption. + */ + + *iob1 = iob_pack(*iob1); +#endif + + return (*iob1)->io_pktlen; +} + /**************************************************************************** * Name: tcp_datahandler * @@ -247,22 +284,9 @@ uint16_t tcp_datahandler(FAR struct net_driver_s *dev, /* Concat the iob to readahead */ - if (conn->readahead == NULL) - { - conn->readahead = iob; - } - else - { - iob_concat(conn->readahead, iob); - } - -#ifdef CONFIG_NET_TCP_RECV_PACK - /* Merge an iob chain into a continuous space, thereby reducing iob - * consumption. - */ + tcp_dataconcat(&conn->readahead, &iob); - conn->readahead = iob_pack(conn->readahead); -#endif + /* Clear device buffer */ netdev_iob_clear(dev);
