亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? pbuf.c

?? FreeRtos Source code Version 4.04
?? C
?? 第 1 頁(yè) / 共 3 頁(yè)
字號(hào):
/**
 * @file
 * Packet buffer management
 *
 * Packets are built from the pbuf data structure. It supports dynamic
 * memory allocation for packet contents or can reference externally
 * managed packet contents both in RAM and ROM. Quick allocation for
 * incoming packets is provided through pools with fixed sized pbufs.
 *
 * A packet may span over multiple pbufs, chained as a singly linked
 * list. This is called a "pbuf chain".
 *
 * Multiple packets may be queued, also using this singly linked list.
 * This is called a "packet queue".
 * 
 * So, a packet queue consists of one or more pbuf chains, each of
 * which consist of one or more pbufs. Currently, queues are only
 * supported in a limited section of lwIP, this is the etharp queueing
 * code. Outside of this section no packet queues are supported yet.
 * 
 * The differences between a pbuf chain and a packet queue are very
 * precise but subtle. 
 *
 * The last pbuf of a packet has a ->tot_len field that equals the
 * ->len field. It can be found by traversing the list. If the last
 * pbuf of a packet has a ->next field other than NULL, more packets
 * are on the queue.
 *
 * Therefore, looping through a pbuf of a single packet, has an
 * loop end condition (tot_len == p->len), NOT (next == NULL).
 */

/*
 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGE.
 *
 * This file is part of the lwIP TCP/IP stack.
 *
 * Author: Adam Dunkels <adam@sics.se>
 *
 */

#include "lwip/opt.h"

#include "lwip/stats.h"

#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/pbuf.h"

#include "lwip/sys.h"

#include "arch/perf.h"

#include <string.h>

static u8_t pbuf_pool_memory[(PBUF_POOL_SIZE * MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE + sizeof(struct pbuf)))];

#if !SYS_LIGHTWEIGHT_PROT
static volatile u8_t pbuf_pool_free_lock, pbuf_pool_alloc_lock;
static sys_sem_t pbuf_pool_free_sem;
#endif

static struct pbuf *pbuf_pool = NULL;

/**
 * Initializes the pbuf module.
 *
 * A large part of memory is allocated for holding the pool of pbufs.
 * The size of the individual pbufs in the pool is given by the size
 * parameter, and the number of pbufs in the pool by the num parameter.
 *
 * After the memory has been allocated, the pbufs are set up. The
 * ->next pointer in each pbuf is set up to point to the next pbuf in
 * the pool.
 *
 */
void
pbuf_init(void)
{
  struct pbuf *p, *q = NULL;
  u16_t i;

  pbuf_pool = (struct pbuf *)&pbuf_pool_memory[0];
  LWIP_ASSERT("pbuf_init: pool aligned", (mem_ptr_t)pbuf_pool % MEM_ALIGNMENT == 0);

#if PBUF_STATS
  lwip_stats.pbuf.avail = PBUF_POOL_SIZE;
#endif /* PBUF_STATS */

  /* Set up ->next pointers to link the pbufs of the pool together */
  p = pbuf_pool;

  for(i = 0; i < PBUF_POOL_SIZE; ++i) {
    p->next = (struct pbuf *)((u8_t *)p + PBUF_POOL_BUFSIZE + sizeof(struct pbuf));
    p->len = p->tot_len = PBUF_POOL_BUFSIZE;
    p->payload = MEM_ALIGN((void *)((u8_t *)p + sizeof(struct pbuf)));
    p->flags = PBUF_FLAG_POOL;
    q = p;
    p = p->next;
  }

  /* The ->next pointer of last pbuf is NULL to indicate that there
     are no more pbufs in the pool */
  q->next = NULL;

#if !SYS_LIGHTWEIGHT_PROT
  pbuf_pool_alloc_lock = 0;
  pbuf_pool_free_lock = 0;
  pbuf_pool_free_sem = sys_sem_new(1);
#endif
}

/**
 * @internal only called from pbuf_alloc()
 */
static struct pbuf *
pbuf_pool_alloc(void)
{
  struct pbuf *p = NULL;

  SYS_ARCH_DECL_PROTECT(old_level);
  SYS_ARCH_PROTECT(old_level);

#if !SYS_LIGHTWEIGHT_PROT
  /* Next, check the actual pbuf pool, but if the pool is locked, we
     pretend to be out of buffers and return NULL. */
  if (pbuf_pool_free_lock) {
#if PBUF_STATS
    ++lwip_stats.pbuf.alloc_locked;
#endif /* PBUF_STATS */
    return NULL;
  }
  pbuf_pool_alloc_lock = 1;
  if (!pbuf_pool_free_lock) {
#endif /* SYS_LIGHTWEIGHT_PROT */
    p = pbuf_pool;
    if (p) {
      pbuf_pool = p->next;
    }
#if !SYS_LIGHTWEIGHT_PROT
#if PBUF_STATS
  } else {
    ++lwip_stats.pbuf.alloc_locked;
#endif /* PBUF_STATS */
  }
  pbuf_pool_alloc_lock = 0;
#endif /* SYS_LIGHTWEIGHT_PROT */

#if PBUF_STATS
  if (p != NULL) {
    ++lwip_stats.pbuf.used;
    if (lwip_stats.pbuf.used > lwip_stats.pbuf.max) {
      lwip_stats.pbuf.max = lwip_stats.pbuf.used;
    }
  }
#endif /* PBUF_STATS */

  SYS_ARCH_UNPROTECT(old_level);
  return p;
}


/**
 * Allocates a pbuf of the given type (possibly a chain for PBUF_POOL type).
 *
 * The actual memory allocated for the pbuf is determined by the
 * layer at which the pbuf is allocated and the requested size
 * (from the size parameter).
 *
 * @param flag this parameter decides how and where the pbuf
 * should be allocated as follows:
 *
 * - PBUF_RAM: buffer memory for pbuf is allocated as one large
 *             chunk. This includes protocol headers as well.
 * - PBUF_ROM: no buffer memory is allocated for the pbuf, even for
 *             protocol headers. Additional headers must be prepended
 *             by allocating another pbuf and chain in to the front of
 *             the ROM pbuf. It is assumed that the memory used is really
 *             similar to ROM in that it is immutable and will not be
 *             changed. Memory which is dynamic should generally not
 *             be attached to PBUF_ROM pbufs. Use PBUF_REF instead.
 * - PBUF_REF: no buffer memory is allocated for the pbuf, even for
 *             protocol headers. It is assumed that the pbuf is only
 *             being used in a single thread. If the pbuf gets queued,
 *             then pbuf_take should be called to copy the buffer.
 * - PBUF_POOL: the pbuf is allocated as a pbuf chain, with pbufs from
 *              the pbuf pool that is allocated during pbuf_init().
 *
 * @return the allocated pbuf. If multiple pbufs where allocated, this
 * is the first pbuf of a pbuf chain.
 */
struct pbuf *
pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
{
  struct pbuf *p, *q, *r;
  u16_t offset;
  s32_t rem_len; /* remaining length */
  LWIP_DEBUGF(PBUF_DEBUG | DBG_TRACE | 3, ("pbuf_alloc(length=%u)\n", length));

  /* determine header offset */
  offset = 0;
  switch (l) {
  case PBUF_TRANSPORT:
    /* add room for transport (often TCP) layer header */
    offset += PBUF_TRANSPORT_HLEN;
    /* FALLTHROUGH */
  case PBUF_IP:
    /* add room for IP layer header */
    offset += PBUF_IP_HLEN;
    /* FALLTHROUGH */
  case PBUF_LINK:
    /* add room for link layer header */
    offset += PBUF_LINK_HLEN;
    break;
  case PBUF_RAW:
    break;
  default:
    LWIP_ASSERT("pbuf_alloc: bad pbuf layer", 0);
    return NULL;
  }

  switch (flag) {
  case PBUF_POOL:
    /* allocate head of pbuf chain into p */
    p = pbuf_pool_alloc();
    LWIP_DEBUGF(PBUF_DEBUG | DBG_TRACE | 3, ("pbuf_alloc: allocated pbuf %p\n", (void *)p));
    if (p == NULL) {
#if PBUF_STATS
      ++lwip_stats.pbuf.err;
#endif /* PBUF_STATS */
      return NULL;
    }
    p->next = NULL;

    /* make the payload pointer point 'offset' bytes into pbuf data memory */
    p->payload = MEM_ALIGN((void *)((u8_t *)p + (sizeof(struct pbuf) + offset)));
    LWIP_ASSERT("pbuf_alloc: pbuf p->payload properly aligned",
            ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0);
    /* the total length of the pbuf chain is the requested size */
    p->tot_len = length;
    /* set the length of the first pbuf in the chain */
    p->len = length > PBUF_POOL_BUFSIZE - offset? PBUF_POOL_BUFSIZE - offset: length;
    /* set reference count (needed here in case we fail) */
    p->ref = 1;

    /* now allocate the tail of the pbuf chain */

    /* remember first pbuf for linkage in next iteration */
    r = p;
    /* remaining length to be allocated */
    rem_len = length - p->len;
    /* any remaining pbufs to be allocated? */
    while (rem_len > 0) {
      q = pbuf_pool_alloc();
      if (q == NULL) {
       LWIP_DEBUGF(PBUF_DEBUG | 2, ("pbuf_alloc: Out of pbufs in pool.\n"));
#if PBUF_STATS
        ++lwip_stats.pbuf.err;
#endif /* PBUF_STATS */
        /* free chain so far allocated */
        pbuf_free(p);
        /* bail out unsuccesfully */
        return NULL;
      }
      q->next = NULL;
      /* make previous pbuf point to this pbuf */
      r->next = q;
      /* set total length of this pbuf and next in chain */
      q->tot_len = rem_len;
      /* this pbuf length is pool size, unless smaller sized tail */
      q->len = rem_len > PBUF_POOL_BUFSIZE? PBUF_POOL_BUFSIZE: rem_len;
      q->payload = (void *)((u8_t *)q + sizeof(struct pbuf));
      LWIP_ASSERT("pbuf_alloc: pbuf q->payload properly aligned",
              ((mem_ptr_t)q->payload % MEM_ALIGNMENT) == 0);
      q->ref = 1;
      /* calculate remaining length to be allocated */
      rem_len -= q->len;
      /* remember this pbuf for linkage in next iteration */
      r = q;
    }
    /* end of chain */
    /*r->next = NULL;*/

    break;
  case PBUF_RAM:
    /* If pbuf is to be allocated in RAM, allocate memory for it. */
    p = mem_malloc(MEM_ALIGN_SIZE(sizeof(struct pbuf) + offset) + MEM_ALIGN_SIZE(length));
    if (p == NULL) {
      return NULL;
    }
    /* Set up internal structure of the pbuf. */
    p->payload = MEM_ALIGN((void *)((u8_t *)p + sizeof(struct pbuf) + offset));
    p->len = p->tot_len = length;
    p->next = NULL;
    p->flags = PBUF_FLAG_RAM;

    LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned",

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品国产黑色紧身裤美女| 欧美精品一二三| 日一区二区三区| 欧美国产一区二区| 欧美日韩久久不卡| 不卡的av网站| 精品在线免费观看| 亚洲第一狼人社区| ●精品国产综合乱码久久久久| 日韩一区二区三区免费看| 91香蕉视频黄| 国产二区国产一区在线观看| 午夜欧美大尺度福利影院在线看 | 欧美在线免费观看视频| 国产美女精品在线| 日本成人在线不卡视频| 一区二区三区在线视频免费观看| 久久精品网站免费观看| 欧美一区欧美二区| 欧美日韩国产天堂| 91黄色免费网站| 91色综合久久久久婷婷| 成人综合激情网| 国产很黄免费观看久久| 久久精品99国产精品日本| 天天操天天干天天综合网| 一区二区三区电影在线播| 中文字幕亚洲成人| 国产精品免费aⅴ片在线观看| 久久综合九色综合97婷婷| 欧美一级二级在线观看| 欧美日本一区二区三区四区 | 国产成人综合亚洲91猫咪| 日本伊人午夜精品| 天堂一区二区在线| 图片区小说区区亚洲影院| 亚洲综合激情小说| 亚洲影视在线播放| 亚洲国产成人高清精品| 亚洲第一成年网| 视频一区二区欧美| 日韩和欧美一区二区三区| 日韩国产欧美一区二区三区| 视频在线在亚洲| 美女久久久精品| 精品一区二区三区免费| 国产一区二区中文字幕| 高清不卡一二三区| 成人h精品动漫一区二区三区| 不卡视频在线观看| 一本大道久久a久久精二百| 在线观看日韩电影| 欧美色图片你懂的| 欧美一区二区三区爱爱| 欧美大度的电影原声| 2020国产精品自拍| 中文字幕av一区 二区| 亚洲欧美在线另类| 一区二区三区中文字幕| 午夜精品福利视频网站| 美女mm1313爽爽久久久蜜臀| 国产一区二区三区不卡在线观看| 国产精品一区免费在线观看| jizzjizzjizz欧美| 欧美日韩在线精品一区二区三区激情| 在线不卡中文字幕| 26uuu精品一区二区三区四区在线 26uuu精品一区二区在线观看 | 亚洲成人资源在线| 久久99精品一区二区三区 | 久久av中文字幕片| 国产精品亚洲人在线观看| 91丨九色丨尤物| 7878成人国产在线观看| 久久久99免费| 一区二区高清视频在线观看| 麻豆免费看一区二区三区| 国产精品18久久久久| 色老综合老女人久久久| 日韩欧美在线1卡| 国产精品美日韩| 亚洲18色成人| 福利一区福利二区| 欧美日韩在线三级| 欧美国产精品久久| 图片区日韩欧美亚洲| 成人免费毛片a| 欧美一区二区久久| 国产精品卡一卡二卡三| 日韩av不卡在线观看| 不卡影院免费观看| 日韩精品一区二区三区中文不卡| 欧美国产1区2区| 青青草国产精品亚洲专区无| jizzjizzjizz欧美| www国产亚洲精品久久麻豆| 一区二区三区在线高清| 韩国v欧美v亚洲v日本v| 在线观看91视频| 国产精品久久久99| 久久成人久久爱| 欧美精品久久天天躁| 日韩毛片精品高清免费| 久久97超碰色| 欧美日韩国产精品自在自线| 国产精品国产三级国产| 国产综合色视频| 欧美久久久久久蜜桃| 亚洲欧美一区二区三区极速播放 | 国产高清亚洲一区| 欧美丰满少妇xxxxx高潮对白 | 视频在线观看一区二区三区| 99国产麻豆精品| 久久精品免视看| 麻豆国产精品一区二区三区| 在线观看三级视频欧美| 国产精品久久久久久妇女6080| 久久国产综合精品| 91麻豆精品国产91久久久久久久久 | 成人免费一区二区三区视频| 国产一区二区三区黄视频| 欧美一区二区在线不卡| 亚洲午夜久久久久久久久电影院| 欧美精品1区2区| 亚洲一区二区三区视频在线| 99久久精品国产导航| 国产精品久久久久精k8| 成人视屏免费看| 国产精品免费免费| 国产成人综合在线观看| 国产清纯白嫩初高生在线观看91 | a级精品国产片在线观看| 国产欧美日韩精品一区| 国产精品亚洲成人| 久久精品亚洲精品国产欧美kt∨| 久久99久久久欧美国产| 欧美电视剧免费全集观看 | 91香蕉视频在线| 一区二区在线免费观看| 色菇凉天天综合网| 亚洲综合在线观看视频| 欧美三级视频在线观看| 亚洲午夜激情网站| 欧美日韩三级视频| 秋霞国产午夜精品免费视频| 欧美一激情一区二区三区| 久久精品国产99久久6| 精品成人私密视频| 国产91精品免费| 亚洲欧洲国产日本综合| 色综合网站在线| 亚洲mv大片欧洲mv大片精品| 欧美一区二区三区免费| 国产综合成人久久大片91| 国产三级三级三级精品8ⅰ区| 成人午夜视频在线观看| 亚洲精选一二三| 在线观看91av| 国产高清无密码一区二区三区| 国产精品美女www爽爽爽| 色爱区综合激月婷婷| 首页国产欧美久久| 久久―日本道色综合久久| 不卡电影一区二区三区| 亚洲一区二区四区蜜桃| 日韩欧美www| 成人永久aaa| 午夜国产精品一区| 亚洲精品一区二区三区蜜桃下载| 国产成人激情av| 亚洲一区影音先锋| 欧美www视频| 91色乱码一区二区三区| 日本美女一区二区三区视频| 久久久蜜桃精品| 91国偷自产一区二区三区成为亚洲经典| 亚洲一区二区在线观看视频| 精品少妇一区二区三区视频免付费 | 在线日韩国产精品| 麻豆专区一区二区三区四区五区| 国产亲近乱来精品视频 | 日本一区二区三区免费乱视频| 色综合天天综合网天天狠天天| 日韩影院精彩在线| 国产欧美一区二区三区网站 | 久久99国内精品| 亚洲精品亚洲人成人网在线播放| 欧美一区二区免费| 97久久超碰精品国产| 日本在线不卡视频一二三区| 亚洲欧洲精品天堂一级| 日韩精品一区二| 在线观看成人免费视频| 国产精品乡下勾搭老头1| 亚洲成人资源网| 中文子幕无线码一区tr| 精品日韩一区二区三区| 欧美日韩在线播| 99久久精品国产麻豆演员表| 久久99精品久久久久婷婷| 亚洲精品成人精品456|