Added PBUF_REF (payload external, copied on queueing).

This commit is contained in:
likewise 2002-11-18 09:51:48 +00:00
parent dbac2ff0b3
commit 1b798ed6d3
2 changed files with 58 additions and 0 deletions

View File

@ -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;
}

View File

@ -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__ */