636 |
|
|
637 |
/** |
/** |
638 |
* Concatenate two pbufs (each may be a pbuf chain) and take over |
* Concatenate two pbufs (each may be a pbuf chain) and take over |
639 |
* the reference of the tail pbuf. |
* the caller's reference of the tail pbuf. |
640 |
* |
* |
641 |
* @note The caller MAY NOT reference the tail pbuf afterwards. |
* @note The caller MAY NOT reference the tail pbuf afterwards. |
642 |
|
* Use pbuf_chain() for that purpose. |
643 |
* |
* |
644 |
* @see pbuf_chain() |
* @see pbuf_chain() |
645 |
*/ |
*/ |
646 |
|
|
647 |
void |
void |
651 |
|
|
652 |
LWIP_ASSERT("h != NULL", h != NULL); |
LWIP_ASSERT("h != NULL", h != NULL); |
653 |
LWIP_ASSERT("t != NULL", t != NULL); |
LWIP_ASSERT("t != NULL", t != NULL); |
654 |
|
if ((h = NULL) || (t == NULL)) return; |
|
if (t == NULL) |
|
|
return; |
|
655 |
|
|
656 |
/* proceed to last pbuf of chain */ |
/* proceed to last pbuf of chain */ |
657 |
for (p = h; p->next != NULL; p = p->next) { |
for (p = h; p->next != NULL; p = p->next) { |
658 |
/* add total length of second chain to all totals of first chain */ |
/* add total length of second chain to all totals of first chain */ |
659 |
p->tot_len += t->tot_len; |
p->tot_len += t->tot_len; |
660 |
} |
} |
661 |
/* p is last pbuf of first h chain */ |
/* { p is last pbuf of first h chain, p->next == NULL } */ |
662 |
LWIP_ASSERT("p->tot_len == p->len (of last pbuf in chain)", p->tot_len == p->len); |
LWIP_ASSERT("p->tot_len == p->len (of last pbuf in chain)", p->tot_len == p->len); |
663 |
/* add total length of second chain to last pbuf total of first chain */ |
/* add total length of second chain to last pbuf total of first chain */ |
664 |
p->tot_len += t->tot_len; |
p->tot_len += t->tot_len; |
667 |
} |
} |
668 |
|
|
669 |
/** |
/** |
670 |
* Chain two pbufs (or pbuf chains) together. They must belong to the same packet. |
* Chain two pbufs (or pbuf chains) together. |
671 |
* It's the same as pbuf_cat with the addition that it increases the reference count |
* |
672 |
* of the tail. |
* The caller MUST call pbuf_free(t) once it has stopped |
673 |
|
* using it. Use pbuf_cat() instead if you no longer use t. |
674 |
* |
* |
675 |
* @param h head pbuf (chain) |
* @param h head pbuf (chain) |
676 |
* @param t tail pbuf (chain) |
* @param t tail pbuf (chain) |
677 |
* @note May not be called on a packet queue. |
* @note The pbufs MUST belong to the same packet. |
678 |
|
* @note MAY NOT be called on a packet queue. |
679 |
* |
* |
680 |
* The ->tot_len fields of all pbufs of the head chain are adjusted. |
* The ->tot_len fields of all pbufs of the head chain are adjusted. |
681 |
* The ->next field of the last pbuf of the head chain is adjusted. |
* The ->next field of the last pbuf of the head chain is adjusted. |
686 |
pbuf_chain(struct pbuf *h, struct pbuf *t) |
pbuf_chain(struct pbuf *h, struct pbuf *t) |
687 |
{ |
{ |
688 |
pbuf_cat(h, t); |
pbuf_cat(h, t); |
689 |
/* t is now referenced to one more time */ |
/* t is now referenced by h */ |
690 |
pbuf_ref(t); |
pbuf_ref(t); |
691 |
LWIP_DEBUGF(PBUF_DEBUG | DBG_FRESH | 2, ("pbuf_chain: %p references %p\n", (void *)h, (void *)t)); |
LWIP_DEBUGF(PBUF_DEBUG | DBG_FRESH | 2, ("pbuf_chain: %p references %p\n", (void *)h, (void *)t)); |
692 |
} |
} |