Add iob_tailroom

I plan to use this for tcp.
This commit is contained in:
YAMAMOTO Takashi 2021-06-30 15:05:06 +09:00 committed by Xiang Xiao
parent 7599ca4e95
commit 314237588e
3 changed files with 64 additions and 1 deletions

View File

@ -478,6 +478,17 @@ int iob_trycopyin(FAR struct iob_s *iob, FAR const uint8_t *src,
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
*

View File

@ -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

52
mm/iob/iob_tailroom.c Normal file
View File

@ -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);
}