From 1b798ed6d362aa2a306df66b70cc5f289b90ef31 Mon Sep 17 00:00:00 2001 From: likewise Date: Mon, 18 Nov 2002 09:51:48 +0000 Subject: [PATCH] Added PBUF_REF (payload external, copied on queueing). --- src/core/pbuf.c | 53 +++++++++++++++++++++++++++++++++++++++++ src/include/lwip/pbuf.h | 5 ++++ 2 files changed, 58 insertions(+) diff --git a/src/core/pbuf.c b/src/core/pbuf.c index 531e3173..e679eaae 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -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; +} \ No newline at end of file diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h index d8b98eec..ac7949df 100644 --- a/src/include/lwip/pbuf.h +++ b/src/include/lwip/pbuf.h @@ -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__ */