mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-01-12 21:41:28 +00:00
Added PBUF_REF (payload external, copied on queueing).
This commit is contained in:
parent
dbac2ff0b3
commit
1b798ed6d3
@ -609,3 +609,56 @@ pbuf_dechain(struct pbuf *p)
|
||||
return q;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
struct pbuf *
|
||||
pbuf_unref(struct pbuf *f)
|
||||
{
|
||||
struct pbuf *p, *q;
|
||||
DEBUGF(PBUF_DEBUG, ("pbuf_unref: %p \n", f));
|
||||
/* first pbuf is of type PBUF_REF? */
|
||||
if (f->flags == PBUF_FLAG_REF)
|
||||
{
|
||||
/* allocate a pbuf (w/ payload) fully in RAM */
|
||||
p = pbuf_alloc(PBUF_RAW, f->len, PBUF_RAM);
|
||||
if (p != 0)
|
||||
{
|
||||
int i;
|
||||
unsigned char *src, *dst;
|
||||
/* copy pbuf struct */
|
||||
p->next = f->next;
|
||||
src = f->payload;
|
||||
dst = p->payload;
|
||||
i = 0;
|
||||
/* copy payload to RAM pbuf */
|
||||
while(i < p->len)
|
||||
{
|
||||
*dst = *src;
|
||||
dst++;
|
||||
src++;
|
||||
}
|
||||
f->next = NULL;
|
||||
/* de-allocate PBUF_REF */
|
||||
pbuf_free(f);
|
||||
f = p;
|
||||
DEBUGF(PBUF_DEBUG, ("pbuf_unref: succesful %p \n", f));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* deallocate chain */
|
||||
pbuf_free(f);
|
||||
f = NULL;
|
||||
DEBUGF(PBUF_DEBUG, ("pbuf_unref: failed\n", f));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
/* p = previous pbuf == first pbuf */
|
||||
p = f;
|
||||
/* q = current pbuf */
|
||||
q = f->next;
|
||||
while (q != NULL)
|
||||
{
|
||||
q = q->next;
|
||||
}
|
||||
return f;
|
||||
}
|
@ -50,6 +50,7 @@ typedef enum {
|
||||
typedef enum {
|
||||
PBUF_RAM,
|
||||
PBUF_ROM,
|
||||
PBUF_REF,
|
||||
PBUF_POOL
|
||||
} pbuf_flag;
|
||||
|
||||
@ -59,6 +60,7 @@ typedef enum {
|
||||
#define PBUF_FLAG_ROM 0x01 /* Flags that pbuf data is stored in ROM. */
|
||||
#define PBUF_FLAG_POOL 0x02 /* Flags that the pbuf comes from the
|
||||
pbuf pool. */
|
||||
#define PBUF_FLAG_REF 0x03
|
||||
|
||||
struct pbuf {
|
||||
struct pbuf *next;
|
||||
@ -149,4 +151,7 @@ void pbuf_chain(struct pbuf *h, struct pbuf *t);
|
||||
the pbuf chain or NULL if the pbuf p was not chained. */
|
||||
struct pbuf *pbuf_dechain(struct pbuf *p);
|
||||
|
||||
struct pbuf *pbuf_unref(struct pbuf *f);
|
||||
|
||||
|
||||
#endif /* __LWIP_PBUF_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user