/[lwip]/lwip/src/core/pbuf.c
ViewVC logotype

Diff of /lwip/src/core/pbuf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.39 by davidhaas, Tue Apr 1 15:54:25 2003 UTC revision 1.40 by likewise, Thu Apr 3 08:50:57 2003 UTC
# Line 788  pbuf_dechain(struct pbuf *p) Line 788  pbuf_dechain(struct pbuf *p)
788   * Used to queue packets on behalf of the lwIP stack, such as   * Used to queue packets on behalf of the lwIP stack, such as
789   * ARP based queueing.   * ARP based queueing.
790   *   *
791   * @param f Head of pbuf chain to process   * @param p Head of pbuf chain to process
792   *   *
793   * @return Pointer to new head of pbuf chain   * @return Pointer to new head of pbuf chain
794   */   */
795  struct pbuf *  struct pbuf *
796  pbuf_take(struct pbuf *f)  pbuf_take(struct pbuf *p)
797  {  {
798    struct pbuf *p, *prev, *top;    struct pbuf *q , *prev, *head;
799    LWIP_ASSERT("pbuf_take: f != NULL\n", f != NULL);    LWIP_ASSERT("pbuf_take: p != NULL\n", p != NULL);
800    DEBUGF(PBUF_DEBUG | DBG_TRACE | 3, ("pbuf_take(%p)\n", (void*)f));    DEBUGF(PBUF_DEBUG | DBG_TRACE | 3, ("pbuf_take(%p)\n", (void*)p));
801    
802    prev = NULL;    prev = NULL;
803    p = f;    head = p;
   top = f;  
804    /* iterate through pbuf chain */    /* iterate through pbuf chain */
805    do    do
806    {    {
807      /* pbuf is of type PBUF_REF? */      /* pbuf is of type PBUF_REF? */
808      if (p->flags == PBUF_FLAG_REF)      if (p->flags == PBUF_FLAG_REF) {
     {  
       /* the replacement pbuf */  
       struct pbuf *q;  
809        DEBUGF(PBUF_DEBUG | DBG_TRACE, ("pbuf_take: encountered PBUF_REF %p\n", (void *)p));        DEBUGF(PBUF_DEBUG | DBG_TRACE, ("pbuf_take: encountered PBUF_REF %p\n", (void *)p));
810        /* allocate a pbuf (w/ payload) fully in RAM */        /* allocate a pbuf (w/ payload) fully in RAM */
811        /* PBUF_POOL buffers are faster if we can use them */        /* PBUF_POOL buffers are faster if we can use them */
# Line 837  pbuf_take(struct pbuf *f) Line 833  pbuf_take(struct pbuf *f)
833          /* remove linkage to original pbuf */          /* remove linkage to original pbuf */
834          if (prev != NULL) {          if (prev != NULL) {
835            /* prev->next == p at this point */            /* prev->next == p at this point */
836              LWIP_ASSERT("prev->next == p", prev->next == p);
837            /* break chain and insert new pbuf instead */            /* break chain and insert new pbuf instead */
838            prev->next = q;            prev->next = q;
839          /* prev == NULL, so we replaced the top pbuf of the chain */          /* prev == NULL, so we replaced the head pbuf of the chain */
840          } else {          } else {
841            top = q;            head = q;
842          }          }
843          /* copy pbuf payload */          /* copy pbuf payload */
844          memcpy(q->payload, p->payload, p->len);          memcpy(q->payload, p->payload, p->len);
# Line 860  pbuf_take(struct pbuf *f) Line 857  pbuf_take(struct pbuf *f)
857          p = q;          p = q;
858        } else {        } else {
859          /* deallocate chain */          /* deallocate chain */
860          pbuf_free(top);          pbuf_free(head);
861          DEBUGF(PBUF_DEBUG | 2, ("pbuf_take: failed to allocate replacement pbuf for %p\n", (void *)p));          DEBUGF(PBUF_DEBUG | 2, ("pbuf_take: failed to allocate replacement pbuf for %p\n", (void *)p));
862          return NULL;          return NULL;
863        }        }
# Line 875  pbuf_take(struct pbuf *f) Line 872  pbuf_take(struct pbuf *f)
872    } while (p);    } while (p);
873    DEBUGF(PBUF_DEBUG | DBG_TRACE | 1, ("pbuf_take: end of chain reached.\n"));    DEBUGF(PBUF_DEBUG | DBG_TRACE | 1, ("pbuf_take: end of chain reached.\n"));
874        
875    return top;    return head;
876  }  }
877    

Legend:
Removed from v.1.39  
changed lines
  Added in v.1.40

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26