IOB: More clean based on change of the last commit
This commit is contained in:
parent
c92645017b
commit
cbb26a9991
@ -91,19 +91,7 @@ FAR struct iob_s *iob_pack(FAR struct iob_s *iob)
|
|||||||
|
|
||||||
while (iob->io_len <= 0)
|
while (iob->io_len <= 0)
|
||||||
{
|
{
|
||||||
/* Save elements that are only valid on the first entry */
|
|
||||||
|
|
||||||
uint8_t flags = iob->io_flags;
|
|
||||||
uint16_t pktlen = iob->io_pktlen;
|
|
||||||
void *priv = iob->io_priv;
|
|
||||||
|
|
||||||
iob = iob_free(iob);
|
iob = iob_free(iob);
|
||||||
|
|
||||||
/* Restore saved settings */
|
|
||||||
|
|
||||||
iob->io_flags = flags;
|
|
||||||
iob->io_pktlen = pktlen;
|
|
||||||
iob->io_priv = priv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now remember the head of the chain (for the return value) */
|
/* Now remember the head of the chain (for the return value) */
|
||||||
|
@ -39,6 +39,8 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include <nuttx/net/iob.h>
|
#include <nuttx/net/iob.h>
|
||||||
|
|
||||||
#include "iob.h"
|
#include "iob.h"
|
||||||
@ -75,23 +77,14 @@
|
|||||||
FAR struct iob_s *iob_trimhead(FAR struct iob_s *iob, unsigned int trimlen)
|
FAR struct iob_s *iob_trimhead(FAR struct iob_s *iob, unsigned int trimlen)
|
||||||
{
|
{
|
||||||
FAR struct iob_s *entry;
|
FAR struct iob_s *entry;
|
||||||
uint8_t flags;
|
|
||||||
uint16_t pktlen;
|
uint16_t pktlen;
|
||||||
void *priv;
|
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
|
|
||||||
if (iob && trimlen > 0)
|
if (iob && trimlen > 0)
|
||||||
{
|
{
|
||||||
/* Save information from the head of the chain (in case the
|
|
||||||
* head is removed).
|
|
||||||
*/
|
|
||||||
|
|
||||||
flags = iob->io_flags;
|
|
||||||
pktlen = iob->io_pktlen;
|
|
||||||
priv = iob->io_priv;
|
|
||||||
|
|
||||||
/* Trim from the head of the I/IO buffer chain */
|
/* Trim from the head of the I/IO buffer chain */
|
||||||
|
|
||||||
|
pktlen = iob->io_pktlen;
|
||||||
entry = iob;
|
entry = iob;
|
||||||
len = trimlen;
|
len = trimlen;
|
||||||
|
|
||||||
@ -101,19 +94,34 @@ FAR struct iob_s *iob_trimhead(FAR struct iob_s *iob, unsigned int trimlen)
|
|||||||
|
|
||||||
if (entry->io_len <= len)
|
if (entry->io_len <= len)
|
||||||
{
|
{
|
||||||
/* Decrement the trim length by the full data size */
|
FAR struct iob_s *next;
|
||||||
|
|
||||||
pktlen -= entry->io_len;
|
/* Decrement the trim length and packet length by the full
|
||||||
len -= entry->io_len;
|
* data size.
|
||||||
|
*/
|
||||||
|
|
||||||
/* Free this one and set the next I/O buffer as the head */
|
pktlen -= entry->io_len;
|
||||||
|
len -= entry->io_len;
|
||||||
|
entry->io_len = 0;
|
||||||
|
entry->io_offset = 0;
|
||||||
|
|
||||||
|
/* Check if this was the last entry in the chain */
|
||||||
|
|
||||||
|
next = (FAR struct iob_s *)entry->io_link.flink;
|
||||||
|
if (!next)
|
||||||
|
{
|
||||||
|
/* Yes.. break out of the loop returning the empty
|
||||||
|
* I/O buffer chain containing only one empty entry.
|
||||||
|
*/
|
||||||
|
|
||||||
|
DEBUGASSERT(pktlen == 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free this entry and set the next I/O buffer as the head */
|
||||||
|
|
||||||
iob = (FAR struct iob_s *)entry->io_link.flink;
|
|
||||||
iob_free(entry);
|
iob_free(entry);
|
||||||
|
entry = next;
|
||||||
/* Continue with the new buffer head */
|
|
||||||
|
|
||||||
entry = iob;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -124,21 +132,15 @@ FAR struct iob_s *iob_trimhead(FAR struct iob_s *iob, unsigned int trimlen)
|
|||||||
pktlen -= len;
|
pktlen -= len;
|
||||||
entry->io_len -= len;
|
entry->io_len -= len;
|
||||||
entry->io_offset += len;
|
entry->io_offset += len;
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restore the state to the head of the chain (which may not be
|
/* Adjust the pktlen by the number of bytes removed from the head
|
||||||
* the same I/O buffer chain head that we started with).
|
* of the I/O buffer chain.
|
||||||
*
|
|
||||||
* Adjust the pktlen by the number of bytes removed from the head
|
|
||||||
* of the I/O buffer chain. A special case is where we delete the
|
|
||||||
* entire chain: len > 0 and iob == NULL.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
iob->io_flags = flags;
|
|
||||||
iob->io_pktlen = pktlen;
|
iob->io_pktlen = pktlen;
|
||||||
iob->io_priv = priv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return iob;
|
return iob;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user