64 |
struct pbuf { |
struct pbuf { |
65 |
struct pbuf *next; |
struct pbuf *next; |
66 |
|
|
67 |
/* Pointer to the actual data in the buffer. */ |
/** pointer to the actual data in the buffer. */ |
68 |
void *payload; |
void *payload; |
69 |
|
|
70 |
/* total length of this buffer and additionally chained buffers */ |
/** |
71 |
/* (p->tot_len = p->len + p->next->tot_len) */ |
* total length of this buffer and all chained buffers. |
72 |
|
* invariant: (p->tot_len == p->len + (p->next? p->next->tot_len: 0) |
73 |
|
*/ |
74 |
u16_t tot_len; |
u16_t tot_len; |
75 |
|
|
76 |
/* Length of this buffer. */ |
/* length of this buffer */ |
77 |
u16_t len; |
u16_t len; |
78 |
|
|
79 |
/* flags */ |
/* flags */ |
80 |
u16_t flags; |
u16_t flags; |
81 |
|
|
82 |
/** the reference count always equals the number of pointers |
/** |
83 |
|
* the reference count always equals the number of pointers |
84 |
* that refer to this pbuf. This can be pointers from an application, |
* that refer to this pbuf. This can be pointers from an application, |
85 |
* the stack itself, or pbuf->next pointers from a chain. |
* the stack itself, or pbuf->next pointers from a chain. |
86 |
*/ |
*/ |
95 |
parameter specifies the size of the data allocated to those. */ |
parameter specifies the size of the data allocated to those. */ |
96 |
void pbuf_init(void); |
void pbuf_init(void); |
97 |
|
|
|
/* pbuf_alloc(): |
|
|
|
|
|
Allocates a pbuf at protocol layer l. The actual memory allocated |
|
|
for the pbuf is determined by the layer at which the pbuf is |
|
|
allocated and the requested size (from the size parameter). The |
|
|
flag parameter decides how and where the pbuf should be allocated |
|
|
as follows: |
|
|
|
|
|
* PBUF_RAM: buffer memory for pbuf is allocated as one large |
|
|
chunk. This includesprotocol headers as well. |
|
|
|
|
|
* RBUF_ROM: no buffer memory is allocated for the pbuf, even for |
|
|
protocol headers. Additional headers must be |
|
|
prepended by allocating another pbuf and chain in to |
|
|
the front of the ROM pbuf. |
|
|
|
|
|
* PBUF_POOL: the pbuf is allocated as a pbuf chain, with pbufs from |
|
|
the pbuf pool that is allocated during pbuf_init(). */ |
|
98 |
struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag); |
struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag); |
|
|
|
|
/* pbuf_realloc(): |
|
|
|
|
|
Shrinks the pbuf to the size given by the size parameter. |
|
|
*/ |
|
99 |
void pbuf_realloc(struct pbuf *p, u16_t size); |
void pbuf_realloc(struct pbuf *p, u16_t size); |
|
|
|
|
/* pbuf_header(): |
|
|
|
|
|
Tries to move the p->payload pointer header_size number of bytes |
|
|
upward within the pbuf. The return value is non-zero if it |
|
|
fails. If so, an additional pbuf should be allocated for the header |
|
|
and it should be chained to the front. */ |
|
100 |
u8_t pbuf_header(struct pbuf *p, s16_t header_size); |
u8_t pbuf_header(struct pbuf *p, s16_t header_size); |
|
|
|
|
/* pbuf_ref(): |
|
|
|
|
|
Increments the reference count of the pbuf p. |
|
|
*/ |
|
101 |
void pbuf_ref(struct pbuf *p); |
void pbuf_ref(struct pbuf *p); |
102 |
void pbuf_ref_chain(struct pbuf *p); |
void pbuf_ref_chain(struct pbuf *p); |
|
/* pbuf_free(): |
|
|
|
|
|
Decrements the reference count and deallocates the pbuf if the |
|
|
reference count is zero. If the pbuf is a chain all pbufs in the |
|
|
chain are deallocated. */ |
|
103 |
u8_t pbuf_free(struct pbuf *p); |
u8_t pbuf_free(struct pbuf *p); |
|
|
|
|
/* pbuf_clen(): |
|
|
|
|
|
Returns the length of the pbuf chain. */ |
|
104 |
u8_t pbuf_clen(struct pbuf *p); |
u8_t pbuf_clen(struct pbuf *p); |
|
|
|
|
/* pbuf_chain(): |
|
|
|
|
|
Chains pbuf t on the end of pbuf h. Pbuf h will have it's tot_len |
|
|
field adjusted accordingly. Pbuf t should no be used any more after |
|
|
a call to this function, since pbuf t is now a part of pbuf h. */ |
|
105 |
void pbuf_chain(struct pbuf *h, struct pbuf *t); |
void pbuf_chain(struct pbuf *h, struct pbuf *t); |
|
|
|
|
/* pbuf_dechain(): |
|
|
|
|
|
Picks off the first pbuf from the pbuf chain p. Returns the tail of |
|
|
the pbuf chain or NULL if the pbuf p was not chained. */ |
|
106 |
struct pbuf *pbuf_dechain(struct pbuf *p); |
struct pbuf *pbuf_dechain(struct pbuf *p); |
|
|
|
107 |
struct pbuf *pbuf_take(struct pbuf *f); |
struct pbuf *pbuf_take(struct pbuf *f); |
108 |
|
|
109 |
|
|