mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-11-05 17:28:02 +00:00
pbuf: added new function pbuf_free_header() to gradually hide bytes and free pbufs from the front of a pbuf chain
This commit is contained in:
parent
c295717ce7
commit
49414826af
@ -683,6 +683,36 @@ pbuf_header_force(struct pbuf *p, s16_t header_size_increment)
|
||||
return pbuf_header_impl(p, header_size_increment, 1);
|
||||
}
|
||||
|
||||
/** Similar to pbuf_header(-size) but de-refs header pbufs for (size >= p->len)
|
||||
*
|
||||
* @param q pbufs to operate on
|
||||
* @param size The number of bytes to remove from the beginning of the pbuf list.
|
||||
* While size >= p->len, pbufs are freed.
|
||||
* ATTENTION: this is the opposite direction as @ref pbuf_header, but
|
||||
* takes an u16_t not s16_t!
|
||||
* @return the new head pbuf
|
||||
*/
|
||||
struct pbuf*
|
||||
pbuf_free_header(struct pbuf *q, u16_t size)
|
||||
{
|
||||
struct pbuf *p = q;
|
||||
u16_t free_left = size;
|
||||
while (free_left && p) {
|
||||
s16_t free_len = (free_left > INT16_MAX ? INT16_MAX : (s16_t)free_left);
|
||||
if (free_len >= p->len) {
|
||||
struct pbuf *f = p;
|
||||
free_left -= p->len;
|
||||
p = p->next;
|
||||
f->next = 0;
|
||||
pbuf_free(f);
|
||||
} else {
|
||||
pbuf_header(p, -free_len);
|
||||
free_left -= free_len;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup pbuf
|
||||
* Dereference a pbuf chain or queue and deallocate any no-longer-used
|
||||
|
@ -248,6 +248,7 @@ struct pbuf *pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type,
|
||||
void pbuf_realloc(struct pbuf *p, u16_t size);
|
||||
u8_t pbuf_header(struct pbuf *p, s16_t header_size);
|
||||
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size);
|
||||
struct pbuf *pbuf_free_header(struct pbuf *q, u16_t size);
|
||||
void pbuf_ref(struct pbuf *p);
|
||||
u8_t pbuf_free(struct pbuf *p);
|
||||
u16_t pbuf_clen(const struct pbuf *p);
|
||||
|
Loading…
Reference in New Issue
Block a user