/[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.24 by likewise, Wed Mar 26 13:30:38 2003 UTC revision 1.25 by likewise, Wed Mar 26 13:50:03 2003 UTC
# Line 404  pbuf_refresh(void) Line 404  pbuf_refresh(void)
404   *   *
405   * @param p pbuf to shrink.   * @param p pbuf to shrink.
406   * @param size new size   * @param size new size
407   * If the pbuf is in ROM, only the ->tot_len and ->len fields are adjusted.   *
408     * Depending on the desired size, the first few pbufs in a chain might
409     * be skipped.
410     * @note If the pbuf is ROM/REF, only the ->tot_len and ->len fields are adjusted.
411   * If the chain   * If the chain
412   * a pbuf chain, as it might be with both pbufs in dynamically   * a pbuf chain, as it might be with both pbufs in dynamically
413   * allocated RAM and for pbufs from the pbuf pool, we have to step   * allocated RAM and for pbufs from the pbuf pool, we have to step
414   * through the chain until we find the new endpoint in the pbuf chain.   * through the chain until we find the new endpoint in the pbuf chain.
415   * Then the pbuf that is right on the endpoint is resized and any   * Then the pbuf that is right on the endpoint is resized and any
416   * further pbufs on the chain are deallocated.   * further pbufs on the chain are deallocated.
417   * @bug #1903   * @bug #1903 should be fixed
418     * @bug Does not grow pbuf chains
419   */   */
420  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
421  #if NEW_PBUF_REALLOC  #if NEW_PBUF_REALLOC
# Line 420  pbuf_realloc(struct pbuf *p, u16_t new_l Line 424  pbuf_realloc(struct pbuf *p, u16_t new_l
424  {  {
425    struct pbuf *q, *r;    struct pbuf *q, *r;
426    u16_t rem_len; /* remaining length */    u16_t rem_len; /* remaining length */
427      s16_t grow;
428    
429    LWIP_ASSERT("pbuf_realloc: sane p->flags", p->flags == PBUF_FLAG_POOL ||    LWIP_ASSERT("pbuf_realloc: sane p->flags", p->flags == PBUF_FLAG_POOL ||
430                p->flags == PBUF_FLAG_ROM ||                p->flags == PBUF_FLAG_ROM ||
# Line 430  pbuf_realloc(struct pbuf *p, u16_t new_l Line 435  pbuf_realloc(struct pbuf *p, u16_t new_l
435      /** enlarging not yet supported */      /** enlarging not yet supported */
436      return;      return;
437    }    }
438      
439      /* { the pbuf chains grows by (new_len - p->tot_len) bytes } */
440      grow = new_len - p->tot_len;
441      
442    /* first, step over any pbufs that should remain in the chain */    /* first, step over any pbufs that should remain in the chain */
443    rem_len = new_len;    rem_len = new_len;
444    q = p;      q = p;  
445    /* this pbuf should be kept? */    /* this pbuf should be kept? */
446    while (rem_len > q->len) {    while (rem_len > q->len) {
447      /* decrease remaining length by pbuf length */      /* decrease remaining length by pbuf length */
448      rem_len -= q->len;            rem_len -= q->len;
449        q->tot_len += grow;
450      q = q->next;      q = q->next;
451    }    }
452    /* { we have now reached the new last pbuf } */    /* { we have now reached the new last pbuf } */
# Line 445  pbuf_realloc(struct pbuf *p, u16_t new_l Line 454  pbuf_realloc(struct pbuf *p, u16_t new_l
454    
455    /* shrink allocated memory for PBUF_RAM */    /* shrink allocated memory for PBUF_RAM */
456    /* (other types merely adjust their length fields */    /* (other types merely adjust their length fields */
457    if (q->flags == PBUF_FLAG_RAM) {    if ((q->flags == PBUF_FLAG_RAM) && (rem_len != q->len )) {
458      /* reallocate and adjust the length of the pbuf that will be split */      /* reallocate and adjust the length of the pbuf that will be split */
459      mem_realloc(q, (u8_t *)q->payload - (u8_t *)q + rem_len);      mem_realloc(q, (u8_t *)q->payload - (u8_t *)q + rem_len);
460    }    }
461        /* adjust length fields */
462    q->len = rem_len;    q->len = rem_len;
463    q->tot_len = q->len;    q->tot_len = q->len;
464    
# Line 465  pbuf_realloc(struct pbuf *p, u16_t new_l Line 474  pbuf_realloc(struct pbuf *p, u16_t new_l
474      /* remember next pbuf in chain */      /* remember next pbuf in chain */
475      r = q->next;      r = q->next;
476      /* deallocate pbuf */      /* deallocate pbuf */
477      if (q->flags == PBUF_FLAG_RAM) {      if (q->flags == PBUF_FLAG_POOL) {
       pbuf_free(q);  
     } else if ((q->flags == PBUF_FLAG_ROM) || (q->flags == PBUF_FLAG_REF)) {  
       PBUF_POOL_FREE(q);  
     } else if (q->flags == PBUF_FLAG_POOL) {  
478        PBUF_POOL_FREE(q);        PBUF_POOL_FREE(q);
479        } else {
480          pbuf_free(q);
481      }      }
482      q = r;      q = r;
483    }    }

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25

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