You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/06/30 11:40:23 UTC
[incubator-nuttx] 03/04: Add iob_tailroom
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/incubator-nuttx.git
commit 314237588eb0beb5153b434d6af7fc8f690234de
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Wed Jun 30 15:05:06 2021 +0900
Add iob_tailroom
I plan to use this for tcp.
---
include/nuttx/mm/iob.h | 11 +++++++++++
mm/iob/Make.defs | 2 +-
mm/iob/iob_tailroom.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/include/nuttx/mm/iob.h b/include/nuttx/mm/iob.h
index 3b70286..abdce41 100644
--- a/include/nuttx/mm/iob.h
+++ b/include/nuttx/mm/iob.h
@@ -479,6 +479,17 @@ int iob_copyout(FAR uint8_t *dest, FAR const struct iob_s *iob,
unsigned int len, unsigned int offset);
/****************************************************************************
+ * Name: iob_tailroom
+ *
+ * Description:
+ * Return the number of bytes at the tail of the I/O buffer chain which
+ * can be used to append data without additional allocations.
+ *
+ ****************************************************************************/
+
+unsigned int iob_tailroom(FAR struct iob_s *iob);
+
+/****************************************************************************
* Name: iob_clone
*
* Description:
diff --git a/mm/iob/Make.defs b/mm/iob/Make.defs
index e241204..4ae751a 100644
--- a/mm/iob/Make.defs
+++ b/mm/iob/Make.defs
@@ -27,7 +27,7 @@ CSRCS += iob_concat.c iob_copyin.c iob_copyout.c iob_contig.c iob_free.c
CSRCS += iob_free_chain.c iob_free_qentry.c iob_free_queue.c
CSRCS += iob_initialize.c iob_pack.c iob_peek_queue.c iob_remove_queue.c
CSRCS += iob_statistics.c iob_trimhead.c iob_trimhead_queue.c iob_trimtail.c
-CSRCS += iob_navail.c iob_free_queue_qentry.c
+CSRCS += iob_navail.c iob_free_queue_qentry.c iob_tailroom.c
ifeq ($(CONFIG_IOB_NOTIFIER),y)
CSRCS += iob_notifier.c
diff --git a/mm/iob/iob_tailroom.c b/mm/iob/iob_tailroom.c
new file mode 100644
index 0000000..d0c9991
--- /dev/null
+++ b/mm/iob/iob_tailroom.c
@@ -0,0 +1,52 @@
+/****************************************************************************
+ * mm/iob/iob_tailroom.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 <nuttx/config.h>
+
+#include <nuttx/mm/iob.h>
+
+#include "iob.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: iob_tailroom
+ *
+ * Description:
+ * Return the number of bytes at the tail of the I/O buffer chain which
+ * can be used to append data without additional allocations.
+ *
+ ****************************************************************************/
+
+unsigned int iob_tailroom(FAR struct iob_s *iob)
+{
+ while (iob->io_flink != NULL)
+ {
+ iob = iob->io_flink;
+ }
+
+ return CONFIG_IOB_BUFSIZE - (iob->io_offset + iob->io_len);
+}