summaryrefslogtreecommitdiff
path: root/nuttx/net/iob
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-06-05 11:39:17 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-06-05 11:39:17 -0600
commit60742e0110844abb95fd5507519e5c48937f8780 (patch)
tree31218f4f9fa8bc804d0887feb2592327813b234a /nuttx/net/iob
parentabc90e32bca2aaa656be97df704c6037a9f86365 (diff)
downloadpx4-nuttx-60742e0110844abb95fd5507519e5c48937f8780.tar.gz
px4-nuttx-60742e0110844abb95fd5507519e5c48937f8780.tar.bz2
px4-nuttx-60742e0110844abb95fd5507519e5c48937f8780.zip
IOB: More clean based on change of the last commit
Diffstat (limited to 'nuttx/net/iob')
-rw-r--r--nuttx/net/iob/iob_pack.c12
-rw-r--r--nuttx/net/iob/iob_trimhead.c56
2 files changed, 29 insertions, 39 deletions
diff --git a/nuttx/net/iob/iob_pack.c b/nuttx/net/iob/iob_pack.c
index ce60f96c5..7533cf857 100644
--- a/nuttx/net/iob/iob_pack.c
+++ b/nuttx/net/iob/iob_pack.c
@@ -91,19 +91,7 @@ FAR struct iob_s *iob_pack(FAR struct iob_s *iob)
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);
-
- /* 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) */
diff --git a/nuttx/net/iob/iob_trimhead.c b/nuttx/net/iob/iob_trimhead.c
index 40fb270d2..5c5df758e 100644
--- a/nuttx/net/iob/iob_trimhead.c
+++ b/nuttx/net/iob/iob_trimhead.c
@@ -39,6 +39,8 @@
#include <nuttx/config.h>
+#include <assert.h>
+
#include <nuttx/net/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 *entry;
- uint8_t flags;
uint16_t pktlen;
- void *priv;
unsigned int len;
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 */
+ pktlen = iob->io_pktlen;
entry = iob;
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)
{
- /* Decrement the trim length by the full data size */
+ FAR struct iob_s *next;
- pktlen -= entry->io_len;
- len -= entry->io_len;
+ /* Decrement the trim length and packet length by the full
+ * 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;
- iob = (FAR struct iob_s *)entry->io_link.flink;
- iob_free(entry);
+ /* 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.
+ */
- /* Continue with the new buffer head */
+ DEBUGASSERT(pktlen == 0);
+ break;
+ }
- entry = iob;
+ /* Free this entry and set the next I/O buffer as the head */
+
+ iob_free(entry);
+ entry = next;
}
else
{
@@ -124,21 +132,15 @@ FAR struct iob_s *iob_trimhead(FAR struct iob_s *iob, unsigned int trimlen)
pktlen -= len;
entry->io_len -= len;
entry->io_offset += len;
- len = 0;
+ len = 0;
}
}
- /* Restore the state to the head of the chain (which may not be
- * the same I/O buffer chain head that we started with).
- *
- * 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.
+ /* Adjust the pktlen by the number of bytes removed from the head
+ * of the I/O buffer chain.
*/
- iob->io_flags = flags;
iob->io_pktlen = pktlen;
- iob->io_priv = priv;
}
return iob;