diff --git a/net/tcp/Kconfig b/net/tcp/Kconfig index d287271911..290cbb41bd 100644 --- a/net/tcp/Kconfig +++ b/net/tcp/Kconfig @@ -266,20 +266,6 @@ config NET_TCP_WRBUFFER_DUMP endif # NET_TCP_WRITE_BUFFERS -config NET_TCP_RECV_PACK - bool "Enable TCP/IP receive data in a continuous poll" - default y - ---help--- - This option will enable TCP/IP receive data into a continuous iob chain. - Fragmentation of network data will intensify iob consumption, if - the device receives a message storm of fragmented packets, the iob - cache will not be effectively used, this is not allowed on iot devices - since the resources of such devices are limited. Of course, this - also takes some disadvantages: data needs to be copied. - This option will brings some balance on resource-constrained devices, - enable this config to reduce the consumption of iob, the received iob - buffers will be merged into the contiguous iob chain. - config NET_TCPBACKLOG bool "TCP/IP backlog support" default n diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index adfb8313b5..301d5ea722 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -1373,21 +1373,6 @@ 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 d825ba07eb..89077bae8e 100644 --- a/net/tcp/tcp_callback.c +++ b/net/tcp/tcp_callback.c @@ -36,6 +36,7 @@ #include "devif/devif.h" #include "tcp/tcp.h" +#include "utils/utils.h" #ifdef NET_TCP_HAVE_STACK @@ -143,7 +144,7 @@ static uint16_t tcp_ofoseg_data_event(FAR struct net_driver_s *dev, rcvseq = TCP_SEQ_ADD(rcvseq, seg->data->io_pktlen); net_incr32(conn->rcvseq, seg->data->io_pktlen); - tcp_dataconcat(&conn->readahead, &seg->data); + net_iob_concat(&conn->readahead, &seg->data); } else if (TCP_SEQ_GT(rcvseq, seg->left)) { @@ -177,7 +178,7 @@ static uint16_t tcp_ofoseg_data_event(FAR struct net_driver_s *dev, rcvseq = TCP_SEQ_ADD(rcvseq, seg->data->io_pktlen); net_incr32(conn->rcvseq, seg->data->io_pktlen); - tcp_dataconcat(&conn->readahead, &seg->data); + net_iob_concat(&conn->readahead, &seg->data); } } } @@ -350,43 +351,6 @@ 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 * @@ -438,7 +402,7 @@ uint16_t tcp_datahandler(FAR struct net_driver_s *dev, /* Concat the iob to readahead */ - tcp_dataconcat(&conn->readahead, &iob); + net_iob_concat(&conn->readahead, &iob); /* Clear device buffer */ diff --git a/net/tcp/tcp_input.c b/net/tcp/tcp_input.c index fd3a128239..dd34cd369c 100644 --- a/net/tcp/tcp_input.c +++ b/net/tcp/tcp_input.c @@ -315,7 +315,7 @@ static bool tcp_rebuild_ofosegs(FAR struct tcp_conn_s *conn, else if (ofoseg->left == seg->right) { - tcp_dataconcat(&seg->data, &ofoseg->data); + net_iob_concat(&seg->data, &ofoseg->data); seg->right = ofoseg->right; } @@ -338,7 +338,7 @@ static bool tcp_rebuild_ofosegs(FAR struct tcp_conn_s *conn, ofoseg->data = iob_trimhead(ofoseg->data, TCP_SEQ_SUB(seg->right, ofoseg->left)); - tcp_dataconcat(&seg->data, &ofoseg->data); + net_iob_concat(&seg->data, &ofoseg->data); seg->right = ofoseg->right; } } @@ -355,7 +355,7 @@ static bool tcp_rebuild_ofosegs(FAR struct tcp_conn_s *conn, if (ofoseg->right == seg->left) { - tcp_dataconcat(&ofoseg->data, &seg->data); + net_iob_concat(&ofoseg->data, &seg->data); seg->data = ofoseg->data; seg->left = ofoseg->left; ofoseg->data = NULL; @@ -390,7 +390,7 @@ static bool tcp_rebuild_ofosegs(FAR struct tcp_conn_s *conn, ofoseg->data = iob_trimtail(ofoseg->data, ofoseg->right - seg->left); - tcp_dataconcat(&ofoseg->data, &seg->data); + net_iob_concat(&ofoseg->data, &seg->data); seg->data = ofoseg->data; seg->left = ofoseg->left; ofoseg->data = NULL; diff --git a/net/utils/CMakeLists.txt b/net/utils/CMakeLists.txt index 307a348c19..9cbfd8cc89 100644 --- a/net/utils/CMakeLists.txt +++ b/net/utils/CMakeLists.txt @@ -29,7 +29,8 @@ set(SRCS net_incr32.c net_lock.c net_snoop.c - net_cmsg.c) + net_cmsg.c + net_iob_concat.c) # IPv6 utilities diff --git a/net/utils/Kconfig b/net/utils/Kconfig index 6e55134dd9..0bec1c2141 100644 --- a/net/utils/Kconfig +++ b/net/utils/Kconfig @@ -28,3 +28,17 @@ config NET_ARCH_CHKSUM config NET_SNOOP_BUFSIZE int "Snoop buffer size for interrupt" default 4096 + +config NET_RECV_PACK + bool "Enable TCP/IP receive data in a continuous poll" + default y + ---help--- + This option will enable TCP/IP receive data into a continuous iob chain. + Fragmentation of network data will intensify iob consumption, if + the device receives a message storm of fragmented packets, the iob + cache will not be effectively used, this is not allowed on iot devices + since the resources of such devices are limited. Of course, this + also takes some disadvantages: data needs to be copied. + This option will brings some balance on resource-constrained devices, + enable this config to reduce the consumption of iob, the received iob + buffers will be merged into the contiguous iob chain. diff --git a/net/utils/Make.defs b/net/utils/Make.defs index 3782881c60..3ee0274495 100644 --- a/net/utils/Make.defs +++ b/net/utils/Make.defs @@ -22,7 +22,7 @@ NET_CSRCS += net_dsec2tick.c net_dsec2timeval.c net_timeval2dsec.c NET_CSRCS += net_chksum.c net_ipchksum.c net_incr32.c net_lock.c net_snoop.c -NET_CSRCS += net_cmsg.c +NET_CSRCS += net_cmsg.c net_iob_concat.c # IPv6 utilities diff --git a/net/utils/net_iob_concat.c b/net/utils/net_iob_concat.c new file mode 100644 index 0000000000..c2e9b292f5 --- /dev/null +++ b/net/utils/net_iob_concat.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * net/utils/net_iob_concat.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +#ifdef CONFIG_MM_IOB + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: net_iob_concat + * + * Description: + * Concatenate iob_s chain iob2 to iob1, if CONFIG_NET_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 net_iob_concat(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_RECV_PACK + /* Merge an iob chain into a continuous space, thereby reducing iob + * consumption. + */ + + *iob1 = iob_pack(*iob1); +#endif + + return (*iob1)->io_pktlen; +} + +#endif /* CONFIG_MM_IOB */ diff --git a/net/utils/utils.h b/net/utils/utils.h index b08efad7ce..00eae795e5 100644 --- a/net/utils/utils.h +++ b/net/utils/utils.h @@ -192,6 +192,23 @@ uint8_t net_ipv6_mask2pref(FAR const uint16_t *mask); void net_ipv6_pref2mask(uint8_t preflen, net_ipv6addr_t mask); #endif +/**************************************************************************** + * Name: net_iob_concat + * + * Description: + * Concatenate iob_s chain iob2 to iob1, if CONFIG_NET_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. + * + ****************************************************************************/ + +#ifdef CONFIG_MM_IOB +uint16_t net_iob_concat(FAR struct iob_s **iob1, FAR struct iob_s **iob2); +#endif + /**************************************************************************** * Name: net_chksum_adjust *