515 |
(u8_t *)p->payload, |
(u8_t *)p->payload, |
516 |
(u8_t *)p + sizeof(struct pbuf)) );\ |
(u8_t *)p + sizeof(struct pbuf)) );\ |
517 |
/* restore old payload pointer */ |
/* restore old payload pointer */ |
518 |
p->payload = payload;/ |
p->payload = payload; |
519 |
/* bail out unsuccesfully */ |
/* bail out unsuccesfully */ |
520 |
return 1; |
return 1; |
521 |
} |
} |
681 |
|
|
682 |
/** |
/** |
683 |
* |
* |
684 |
* Link two pbuf (chains) together. |
* Link two pbufs (or chains) together. |
685 |
|
* |
686 |
|
* @param h head pbuf (chain) |
687 |
|
* @param t tail pbuf (chain) |
688 |
* |
* |
689 |
* The ->tot_len field of the first pbuf (h) is adjusted. |
* The ->tot_len field of the first pbuf (h) is adjusted. |
690 |
*/ |
*/ |
698 |
|
|
699 |
/* proceed to last pbuf of chain */ |
/* proceed to last pbuf of chain */ |
700 |
for (p = h; p->next != NULL; p = p->next) { |
for (p = h; p->next != NULL; p = p->next) { |
701 |
/* add total length of second chain to each total of first chain */ |
/* add total length of second chain to all totals of first chain */ |
702 |
p->tot_len += t->tot_len; |
p->tot_len += t->tot_len; |
703 |
} |
} |
704 |
/* chain last pbuf of h chain (p) with first of tail (t) */ |
/* chain last pbuf of h chain (p) with first of tail (t) */ |
719 |
pbuf_dechain(struct pbuf *p) |
pbuf_dechain(struct pbuf *p) |
720 |
{ |
{ |
721 |
struct pbuf *q; |
struct pbuf *q; |
722 |
u8_t deallocated; |
u8_t tail_gone = 1; |
723 |
/* tail */ |
/* tail */ |
724 |
q = p->next; |
q = p->next; |
725 |
/* pbuf has successor in chain? */ |
/* pbuf has successor in chain? */ |
726 |
if (q != NULL) { |
if (q != NULL) { |
727 |
/* tot_len invariant: (p->tot_len == p->len + p->next->tot_len) */ |
/* assert tot_len invariant: (p->tot_len == p->len + (p->next? p->next->tot_len: 0) */ |
728 |
LWIP_ASSERT("p->tot_len = p->len + q->tot_len", p->tot_len = p->len + q->tot_len); |
LWIP_ASSERT("p->tot_len == p->len + q->tot_len", q->tot_len == p->tot_len - p->len); |
729 |
/* enforce invariant if assertion is disabled */ |
/* enforce invariant if assertion is disabled */ |
730 |
q->tot_len = p->tot_len - p->len; |
q->tot_len = p->tot_len - p->len; |
731 |
} |
/* decouple pbuf from remainder */ |
732 |
/* decouple pbuf from remainder */ |
p->next = NULL; |
733 |
p->tot_len = p->len; |
/* total length of pbuf p is its own length only */ |
734 |
p->next = NULL; |
p->tot_len = p->len; |
735 |
/* q is no longer referenced by p, free */ |
/* q is no longer referenced by p, free it */ |
736 |
deallocated = pbuf_free(q); |
DEBUGF(PBUF_DEBUG | DBG_FRESH | 2, ("pbuf_dechain: unreferencing %p\n", (void *) q)); |
737 |
DEBUGF(PBUF_DEBUG | DBG_FRESH | 2, ("pbuf_dechain: unreferencing %p\n", (void *) q)); |
tail_gone = pbuf_free(q); |
738 |
/* return remaining tail or NULL if deallocated */ |
/* return remaining tail or NULL if deallocated */ |
739 |
return (deallocated > 0? NULL: q); |
} |
740 |
|
/* assert tot_len invariant: (p->tot_len == p->len + (p->next? p->next->tot_len: 0) */ |
741 |
|
LWIP_ASSERT("p->tot_len == p->len", p->tot_len == p->len); |
742 |
|
return (tail_gone > 0? NULL: q); |
743 |
} |
} |
744 |
|
|
745 |
/** |
/** |