mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2025-12-10 08:46:40 +08:00
Add pbuf_cat and use it where pbuf_chain followed by pbuf_free was used before
This commit is contained in:
parent
1047fee2bd
commit
fde27c5f52
@ -617,7 +617,6 @@ pbuf_clen(struct pbuf *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Increment the reference count of the pbuf.
|
* Increment the reference count of the pbuf.
|
||||||
*
|
*
|
||||||
* @param p pbuf to increase reference counter of
|
* @param p pbuf to increase reference counter of
|
||||||
@ -636,20 +635,16 @@ pbuf_ref(struct pbuf *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Concatenate two pbufs (each may be a pbuf chain) and take over
|
||||||
|
* the reference of the tail pbuf.
|
||||||
*
|
*
|
||||||
* Chain two pbufs (or pbuf chains) together. They must belong to the same packet.
|
* @note The caller MAY NOT reference the tail pbuf afterwards.
|
||||||
*
|
|
||||||
* @param h head pbuf (chain)
|
|
||||||
* @param t tail pbuf (chain)
|
|
||||||
* @note May not be called on a packet queue.
|
|
||||||
*
|
|
||||||
* The ->tot_len fields of all pbufs of the head chain are adjusted.
|
|
||||||
* The ->next field of the last pbuf of the head chain is adjusted.
|
|
||||||
* The ->ref field of the first pbuf of the tail chain is adjusted.
|
|
||||||
*
|
*
|
||||||
|
* @see pbuf_chain()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
pbuf_chain(struct pbuf *h, struct pbuf *t)
|
pbuf_cat(struct pbuf *h, struct pbuf *t)
|
||||||
{
|
{
|
||||||
struct pbuf *p;
|
struct pbuf *p;
|
||||||
|
|
||||||
@ -670,9 +665,29 @@ pbuf_chain(struct pbuf *h, struct pbuf *t)
|
|||||||
p->tot_len += t->tot_len;
|
p->tot_len += t->tot_len;
|
||||||
/* chain last pbuf of head (p) with first of tail (t) */
|
/* chain last pbuf of head (p) with first of tail (t) */
|
||||||
p->next = t;
|
p->next = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chain two pbufs (or pbuf chains) together. They must belong to the same packet.
|
||||||
|
* It's the same as pbuf_cat with the addition that it increases the reference count
|
||||||
|
* of the tail.
|
||||||
|
*
|
||||||
|
* @param h head pbuf (chain)
|
||||||
|
* @param t tail pbuf (chain)
|
||||||
|
* @note May not be called on a packet queue.
|
||||||
|
*
|
||||||
|
* The ->tot_len fields of all pbufs of the head chain are adjusted.
|
||||||
|
* The ->next field of the last pbuf of the head chain is adjusted.
|
||||||
|
* The ->ref field of the first pbuf of the tail chain is adjusted.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
pbuf_chain(struct pbuf *h, struct pbuf *t)
|
||||||
|
{
|
||||||
|
pbuf_cat(h, t);
|
||||||
/* t is now referenced to one more time */
|
/* t is now referenced to one more time */
|
||||||
pbuf_ref(t);
|
pbuf_ref(t);
|
||||||
LWIP_DEBUGF(PBUF_DEBUG | DBG_FRESH | 2, ("pbuf_chain: %p references %p\n", (void *)p, (void *)t));
|
LWIP_DEBUGF(PBUF_DEBUG | DBG_FRESH | 2, ("pbuf_chain: %p references %p\n", (void *)h, (void *)t));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For packet queueing. Note that queued packets must be dequeued first
|
/* For packet queueing. Note that queued packets must be dequeued first
|
||||||
|
|||||||
@ -1013,8 +1013,7 @@ tcp_receive(struct tcp_pcb *pcb)
|
|||||||
/* Chain this pbuf onto the pbuf that we will pass to
|
/* Chain this pbuf onto the pbuf that we will pass to
|
||||||
the application. */
|
the application. */
|
||||||
if (recv_data) {
|
if (recv_data) {
|
||||||
pbuf_chain(recv_data, cseg->p);
|
pbuf_cat(recv_data, cseg->p);
|
||||||
pbuf_free(cseg->p);
|
|
||||||
} else {
|
} else {
|
||||||
recv_data = cseg->p;
|
recv_data = cseg->p;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -210,9 +210,8 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
|
|||||||
}
|
}
|
||||||
++queuelen;
|
++queuelen;
|
||||||
|
|
||||||
/* Chain the headers and data pbufs together. */
|
/* Concatenate the headers and data pbufs together. */
|
||||||
pbuf_chain(seg->p, p);
|
pbuf_cat(seg->p, p);
|
||||||
pbuf_free(p);
|
|
||||||
p = NULL;
|
p = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,11 +285,7 @@ tcp_enqueue(struct tcp_pcb *pcb, void *arg, u16_t len,
|
|||||||
useg->len + queue->len <= pcb->mss) {
|
useg->len + queue->len <= pcb->mss) {
|
||||||
/* Remove TCP header from first segment. */
|
/* Remove TCP header from first segment. */
|
||||||
pbuf_header(queue->p, -TCP_HLEN);
|
pbuf_header(queue->p, -TCP_HLEN);
|
||||||
pbuf_chain(useg->p, queue->p);
|
pbuf_cat(useg->p, queue->p);
|
||||||
/* Free buffer which was merged. Note that the previous pbuf_chain call
|
|
||||||
* will have incremented the ref count, so here the ref count will still
|
|
||||||
* be 1 for the 1 pointer still being used on this buffer. */
|
|
||||||
pbuf_free(queue->p);
|
|
||||||
useg->len += queue->len;
|
useg->len += queue->len;
|
||||||
useg->next = queue->next;
|
useg->next = queue->next;
|
||||||
|
|
||||||
|
|||||||
@ -108,6 +108,7 @@ void pbuf_ref(struct pbuf *p);
|
|||||||
void pbuf_ref_chain(struct pbuf *p);
|
void pbuf_ref_chain(struct pbuf *p);
|
||||||
u8_t pbuf_free(struct pbuf *p);
|
u8_t pbuf_free(struct pbuf *p);
|
||||||
u8_t pbuf_clen(struct pbuf *p);
|
u8_t pbuf_clen(struct pbuf *p);
|
||||||
|
void pbuf_cat(struct pbuf *h, struct pbuf *t);
|
||||||
void pbuf_chain(struct pbuf *h, struct pbuf *t);
|
void pbuf_chain(struct pbuf *h, struct pbuf *t);
|
||||||
struct pbuf *pbuf_take(struct pbuf *f);
|
struct pbuf *pbuf_take(struct pbuf *f);
|
||||||
struct pbuf *pbuf_dechain(struct pbuf *p);
|
struct pbuf *pbuf_dechain(struct pbuf *p);
|
||||||
|
|||||||
@ -1480,14 +1480,12 @@ static void pppInProc(int pd, u_char *s, int l)
|
|||||||
|
|
||||||
pc->inTail->tot_len = pc->inTail->len;
|
pc->inTail->tot_len = pc->inTail->len;
|
||||||
if (pc->inTail != pc->inHead) {
|
if (pc->inTail != pc->inHead) {
|
||||||
pbuf_chain(pc->inHead, pc->inTail);
|
pbuf_cat(pc->inHead, pc->inTail);
|
||||||
pbuf_free(pc->inTail);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pc->inTail->tot_len = pc->inTail->len;
|
pc->inTail->tot_len = pc->inTail->len;
|
||||||
if (pc->inTail != pc->inHead) {
|
if (pc->inTail != pc->inHead) {
|
||||||
pbuf_chain(pc->inHead, pc->inTail);
|
pbuf_cat(pc->inHead, pc->inTail);
|
||||||
pbuf_free(pc->inTail);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pbuf_realloc(pc->inHead, pc->inHead->tot_len - 2);
|
pbuf_realloc(pc->inHead, pc->inHead->tot_len - 2);
|
||||||
@ -1583,8 +1581,7 @@ static void pppInProc(int pd, u_char *s, int l)
|
|||||||
if(pc->inTail) {
|
if(pc->inTail) {
|
||||||
pc->inTail->tot_len = pc->inTail->len;
|
pc->inTail->tot_len = pc->inTail->len;
|
||||||
if (pc->inTail != pc->inHead) {
|
if (pc->inTail != pc->inHead) {
|
||||||
pbuf_chain(pc->inHead, pc->inTail);
|
pbuf_cat(pc->inHead, pc->inTail);
|
||||||
pbuf_free(pc->inTail);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* If we haven't started a packet, we need a packet header. */
|
/* If we haven't started a packet, we need a packet header. */
|
||||||
|
|||||||
@ -611,8 +611,7 @@ int vj_uncompress_tcp(
|
|||||||
*nb = NULL;
|
*nb = NULL;
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
pbuf_chain(np, n0);
|
pbuf_cat(np, n0);
|
||||||
pbuf_free(n0);
|
|
||||||
n0 = np;
|
n0 = np;
|
||||||
}
|
}
|
||||||
LWIP_ASSERT("n0->len >= cs->cs_hlen", n0->len >= cs->cs_hlen);
|
LWIP_ASSERT("n0->len >= cs->cs_hlen", n0->len >= cs->cs_hlen);
|
||||||
|
|||||||
@ -145,8 +145,7 @@ slipif_input( struct netif * netif )
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (q != NULL) {
|
if (q != NULL) {
|
||||||
pbuf_chain(q, p);
|
pbuf_cat(q, p);
|
||||||
pbuf_free(p);
|
|
||||||
} else {
|
} else {
|
||||||
q = p;
|
q = p;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user