Retry with PBUF_RAM if PBUF_POOL allocation failed.

This commit is contained in:
likewise 2003-03-24 13:27:12 +00:00
parent ce4dbcec6a
commit e062b70da8

View File

@ -713,10 +713,10 @@ pbuf_dechain(struct pbuf *p)
struct pbuf * struct pbuf *
pbuf_unref(struct pbuf *f) pbuf_unref(struct pbuf *f)
{ {
struct pbuf *p, *prev, *q, *top; struct pbuf *p, *prev, *top;
DEBUGF(PBUF_DEBUG | DBG_TRACE | 3, ("pbuf_unref: %p\n", (void*)f)); DEBUGF(PBUF_DEBUG | DBG_TRACE, ("pbuf_unref: %p\n", (void*)f));
prev = 0; prev = NULL;
p = f; p = f;
top = f; top = f;
do do
@ -724,23 +724,30 @@ pbuf_unref(struct pbuf *f)
/* pbuf is of type PBUF_REF? */ /* pbuf is of type PBUF_REF? */
if (p->flags == PBUF_FLAG_REF) if (p->flags == PBUF_FLAG_REF)
{ {
struct pbuf *q;
q = NULL;
/* allocate a pbuf (w/ payload) fully in RAM */ /* allocate a pbuf (w/ payload) fully in RAM */
/* PBUF_POOL buffers are faster if we can use them */ /* PBUF_POOL buffers are faster if we can use them */
if (p->len <= PBUF_POOL_BUFSIZE) if (p->len <= PBUF_POOL_BUFSIZE) {
q = pbuf_alloc(PBUF_RAW, p->len, PBUF_POOL); q = pbuf_alloc(PBUF_RAW, p->len, PBUF_POOL);
else if (q == NULL) DEBUGF(PBUF_DEBUG | DBG_TRACE, ("pbuf_unref: Could not allocate PBUF_RAW\n"));
}
/* no (large enough) PBUF_POOL was available? retry with PBUF_RAM */
if (q == NULL) {
q = pbuf_alloc(PBUF_RAW, p->len, PBUF_RAM); q = pbuf_alloc(PBUF_RAW, p->len, PBUF_RAM);
if (q != 0) if (q == NULL) DEBUGF(PBUF_DEBUG | DBG_TRACE, ("pbuf_unref: Could not allocate PBUF_POOL\n"));
}
if (q != NULL)
{ {
/* copy pbuf struct */ /* copy pbuf struct */
q->next = p->next; q->next = p->next;
if (prev) if (prev != NULL)
/* Break chain and insert new pbuf instead */ /* Break chain and insert new pbuf instead */
prev->next = q; prev->next = q;
else else
top = q; top = q;
p->next = NULL; p->next = NULL;
/* copy pbuf payload */
memcpy(q->payload, p->payload, p->len); memcpy(q->payload, p->payload, p->len);
q->tot_len = p->tot_len; q->tot_len = p->tot_len;
q->len = p->len; q->len = p->len;