mirror of
https://github.com/apache/nuttx.git
synced 2026-06-01 07:45:16 +08:00
IOB: Fix bugs in trimming logic
This commit is contained in:
+12
-1
@@ -74,21 +74,32 @@ uint8_t buffer2[16384];
|
|||||||
|
|
||||||
static void dump_chain(struct iob_s *iob)
|
static void dump_chain(struct iob_s *iob)
|
||||||
{
|
{
|
||||||
|
struct iob_s *head = iob;
|
||||||
|
unsigned int pktlen;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
printf("=========================================================\n");
|
printf("=========================================================\n");
|
||||||
printf("pktlen: %d flags: %02x\n", iob->io_pktlen, iob->io_flags);
|
printf("pktlen: %d flags: %02x\n", iob->io_pktlen, iob->io_flags);
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
|
pktlen = 0;
|
||||||
|
|
||||||
while (iob)
|
while (iob)
|
||||||
{
|
{
|
||||||
printf("%d. len=%d, offset=%d, priv=%p\n",
|
printf("%d. len=%d, offset=%d, priv=%p\n",
|
||||||
n, iob->io_len, iob->io_offset, iob->io_priv);
|
n, iob->io_len, iob->io_offset, iob->io_priv);
|
||||||
|
|
||||||
|
pktlen += iob->io_len;
|
||||||
iob = (struct iob_s *)iob->io_link.flink;
|
iob = (struct iob_s *)iob->io_link.flink;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pktlen != head->io_pktlen)
|
||||||
|
{
|
||||||
|
printf("ERROR: Bad packet length=%u, actual=%u\n",
|
||||||
|
head->io_pktlen, pktlen);
|
||||||
|
}
|
||||||
|
|
||||||
printf("=========================================================\n");
|
printf("=========================================================\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +175,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
iob = iob_pack(iob);
|
iob = iob_pack(iob);
|
||||||
printf("Packed\n", nbytes);
|
printf("Packed\n");
|
||||||
dump_chain(iob);
|
dump_chain(iob);
|
||||||
|
|
||||||
nbytes = iob_copyout(buffer2, iob, 4096, 0);
|
nbytes = iob_copyout(buffer2, iob, 4096, 0);
|
||||||
|
|||||||
@@ -120,8 +120,9 @@ FAR struct iob_s *iob_trimhead(FAR struct iob_s *iob, unsigned int trimlen)
|
|||||||
|
|
||||||
/* Free this entry and set the next I/O buffer as the head */
|
/* Free this entry and set the next I/O buffer as the head */
|
||||||
|
|
||||||
iob_free(entry);
|
(void)iob_free(entry);
|
||||||
entry = next;
|
entry = next;
|
||||||
|
iob = next;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -76,7 +76,6 @@
|
|||||||
|
|
||||||
FAR struct iob_s *iob_trimtail(FAR struct iob_s *iob, unsigned int trimlen)
|
FAR struct iob_s *iob_trimtail(FAR struct iob_s *iob, unsigned int trimlen)
|
||||||
{
|
{
|
||||||
FAR struct iob_s *head = iob;
|
|
||||||
FAR struct iob_s *entry;
|
FAR struct iob_s *entry;
|
||||||
FAR struct iob_s *penultimate;
|
FAR struct iob_s *penultimate;
|
||||||
FAR struct iob_s *last;
|
FAR struct iob_s *last;
|
||||||
@@ -121,7 +120,7 @@ FAR struct iob_s *iob_trimtail(FAR struct iob_s *iob, unsigned int trimlen)
|
|||||||
{
|
{
|
||||||
/* Yes.. Consume the entire buffer */
|
/* Yes.. Consume the entire buffer */
|
||||||
|
|
||||||
head->io_pktlen -= last->io_len;
|
iob->io_pktlen -= last->io_len;
|
||||||
len -= last->io_len;
|
len -= last->io_len;
|
||||||
last->io_len = 0;
|
last->io_len = 0;
|
||||||
|
|
||||||
@@ -149,7 +148,7 @@ FAR struct iob_s *iob_trimtail(FAR struct iob_s *iob, unsigned int trimlen)
|
|||||||
* stop the trim.
|
* stop the trim.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
head->io_pktlen -= last->io_len;
|
iob->io_pktlen -= len;
|
||||||
last->io_len -= len;
|
last->io_len -= len;
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user