* @ingroup pbuf * Concatenate two pbufs (each may be a pbuf chain) and take over * the caller's reference of the tail pbuf. * * @note The caller MAY NOT reference the tail pbuf afterwards. * Use pbuf_chain() for that purpose. * * This function explicitly does not check for tot_len overflow to prevent * failing to queue too long pbufs. This can produce invalid pbufs, so * handle with care!
| 850 | * @see pbuf_chain() |
| 851 | */ |
| 852 | void |
| 853 | pbuf_cat(struct pbuf *h, struct pbuf *t) |
| 854 | { |
| 855 | struct pbuf *p; |
| 856 | |
| 857 | LWIP_ERROR("(h != NULL) && (t != NULL) (programmer violates API)", |
| 858 | ((h != NULL) && (t != NULL)), return;); |
| 859 | |
| 860 | /* proceed to last pbuf of chain */ |
| 861 | for (p = h; p->next != NULL; p = p->next) { |
| 862 | /* add total length of second chain to all totals of first chain */ |
| 863 | p->tot_len = (u16_t)(p->tot_len + t->tot_len); |
| 864 | } |
| 865 | /* { p is last pbuf of first h chain, p->next == NULL } */ |
| 866 | LWIP_ASSERT("p->tot_len == p->len (of last pbuf in chain)", p->tot_len == p->len); |
| 867 | LWIP_ASSERT("p->next == NULL", p->next == NULL); |
| 868 | /* add total length of second chain to last pbuf total of first chain */ |
| 869 | p->tot_len = (u16_t)(p->tot_len + t->tot_len); |
| 870 | /* chain last pbuf of head (p) with first of tail (t) */ |
| 871 | p->next = t; |
| 872 | /* p->next now references t, but the caller will drop its reference to t, |
| 873 | * so netto there is no change to the reference count of t. |
| 874 | */ |
| 875 | } |
| 876 | |
| 877 | /** |
| 878 | * @ingroup pbuf |
no outgoing calls