|
From: | address@hidden |
Subject: | Re: [lwip-users] PBUF_RAM etc |
Date: | Thu, 16 Feb 2012 21:28:45 +0100 |
User-agent: | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 |
Mason wrote:
Can you explain why the pbuf struct and the payload buffer need to be contiguous? What problems are solved by having the struct and the buffer stored contiguously?
When passing the packet through the stack, the payload pointer in the pbuf is moved back and forth (e.g. to point at the current protocol header or at the application payload). This is what pbuf_header() does.
Hiding a header (moving payload 'higher' in memory address) always works because you can do that as long as p->len > 0. However, restoring a header or making room for one (which is mainly needed when sending a packet out) does not work with the current members of struct pbuf, as it doesn't have a 'max_len' field.
To understand this you have to know that when allocating a pbuf for TCP or UDP data, pbuf_alloc() always leaves room for all the headers (which are filled in later) so that all the data is in one piece (with some exceptions for TCP), which makes it easier and faster for DMA engines to send packets.
So for non-contiguous pbuf/payload combinations, we always eitehr need a separate pbuf for headers or we'd need a 'max_len' pointer to know how big the externally allocated memory is.
No, since the payload is not a 'total_payload' but a 'current_payload_pointer', like I described above.There is a pointer to a buffer in the struct, it is redundant if the payload is at a known offset, right?
Simon
[Prev in Thread] | Current Thread | [Next in Thread] |