You might want to read the comments at the beginning of pbuf.c. They
describe a distinction between a chain and a queue. A chain is a
single packet spanning multiple pbufs. It is widely supported and used
in lwip. A queue is a thread of pbufs containing multiple packets. A
queue may be composed of single buffer packets or packets in pbuf
chains.
I'm using an older rev of lwip that only uses queues in ARP. It is
possible that they are more widely used in newer versions of lwip.
The pbuf_chain function that you are calling is appropriate if you are
trying to assemble a single packet from multiple pbufs. It is not
appropriate if you are trying to create a multi-packet queue. The
pbuf_queue function does that. Same goes for pbuf_dechain and
pbuf_dequeue.
The reference count situation that you describes seems consistent with
the source code for the functions involved, and they seem to provide
self-consistent results. Wiser people then me could probably tell you
why it's done that way, but regardless, it seems to work.
Tim Newsham wrote:
Hi, I'm receiving pbufs from the tcp receive callback and I need
to queue several buffers up so I figure, hey, I'll use the pbufs.
The code isn't working as I hoped, and I guess I misunderstand
the pbuf api.
When I get the first pbuf, I set my queue variable to be equal
to it. On subsequent pbufs I use pbuf_chain(queue, p) to add
the pbuf to the chain.
Now when I want to take data off the pbuf I use pbuf_header
to pop off a certain number of bytes if I only take a partial
buffer worth, or pbuf_dechain if I take a whole buffers worth.
However, pbuf_dechain is doing:
tail_gone = pbuf_free(q)
and returning NULL for next when tail_gone returns true.
I'm looking at the references. Each pbuf I receive has a
reference of 1 when I get it. At the point I want to
start dechaining, I have a total of 4 pbufs in the chain
with refcounts of: 1,1,2,1!
Why does one of the pbufs have a higher reference count?
Am I supposed to bump up the reference count while chaining
these things together? What am I doing wrong here?
Tim N.
_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users
--
E-mail signature
Jim Gibbons
|
address@hidden
|
Gibbons and Associates, Inc.
|
TEL: (408) 984-1441
|
900 Lafayette, Suite 704, Santa Clara, CA
|
FAX: (408) 247-6395
|
|