IOB: Fix bugs in trimming logic
This commit is contained in:
parent
c8e63fe909
commit
fc9b45f39f
|
@ -74,21 +74,32 @@ uint8_t buffer2[16384];
|
|||
|
||||
static void dump_chain(struct iob_s *iob)
|
||||
{
|
||||
struct iob_s *head = iob;
|
||||
unsigned int pktlen;
|
||||
int n;
|
||||
|
||||
printf("=========================================================\n");
|
||||
printf("pktlen: %d flags: %02x\n", iob->io_pktlen, iob->io_flags);
|
||||
|
||||
n = 0;
|
||||
pktlen = 0;
|
||||
|
||||
while (iob)
|
||||
{
|
||||
printf("%d. len=%d, offset=%d, priv=%p\n",
|
||||
n, iob->io_len, iob->io_offset, iob->io_priv);
|
||||
|
||||
pktlen += iob->io_len;
|
||||
iob = (struct iob_s *)iob->io_link.flink;
|
||||
n++;
|
||||
}
|
||||
|
||||
if (pktlen != head->io_pktlen)
|
||||
{
|
||||
printf("ERROR: Bad packet length=%u, actual=%u\n",
|
||||
head->io_pktlen, pktlen);
|
||||
}
|
||||
|
||||
printf("=========================================================\n");
|
||||
}
|
||||
|
||||
|
@ -164,7 +175,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
iob = iob_pack(iob);
|
||||
printf("Packed\n", nbytes);
|
||||
printf("Packed\n");
|
||||
dump_chain(iob);
|
||||
|
||||
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 */
|
||||
|
||||
iob_free(entry);
|
||||
(void)iob_free(entry);
|
||||
entry = next;
|
||||
iob = next;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -76,7 +76,6 @@
|
|||
|
||||
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 *penultimate;
|
||||
FAR struct iob_s *last;
|
||||
|
@ -121,9 +120,9 @@ FAR struct iob_s *iob_trimtail(FAR struct iob_s *iob, unsigned int trimlen)
|
|||
{
|
||||
/* Yes.. Consume the entire buffer */
|
||||
|
||||
head->io_pktlen -= last->io_len;
|
||||
len -= last->io_len;
|
||||
last->io_len = 0;
|
||||
iob->io_pktlen -= last->io_len;
|
||||
len -= last->io_len;
|
||||
last->io_len = 0;
|
||||
|
||||
/* Free the last, empty buffer in the list */
|
||||
|
||||
|
@ -149,9 +148,9 @@ FAR struct iob_s *iob_trimtail(FAR struct iob_s *iob, unsigned int trimlen)
|
|||
* stop the trim.
|
||||
*/
|
||||
|
||||
head->io_pktlen -= last->io_len;
|
||||
last->io_len -= len;
|
||||
len = 0;
|
||||
iob->io_pktlen -= len;
|
||||
last->io_len -= len;
|
||||
len = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue