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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? pbuf.c

?? 一個輕量tcpip協議在移植在ucOS2系統上運行
?? C
?? 第 1 頁 / 共 3 頁
字號:
/**
 * @file
 * Packet buffer management
 *
 * Packets are represented by 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.
 *
 * Pbufs can be chained as a singly linked list, called a pbuf chain, so
 * that a packet may span over several pbufs.
 *
 */

/*
 * Copyright (c) 2001-2003 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"
//added by dy
#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;
static struct pbuf *pbuf_pool_alloc_cache = NULL;
static struct pbuf *pbuf_pool_free_cache = 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", (long)pbuf_pool % MEM_ALIGNMENT == 0);
   
#ifdef 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)));
    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 void
pbuf_pool_free(struct pbuf *p)
{
  struct pbuf *q;
//丁一修改
#if SYS_LIGHTWEIGHT_PROT
  SYS_ARCH_DECL_PROTECT(old_level);
  SYS_ARCH_PROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */  
  sys_sem_wait(pbuf_pool_free_sem);
#endif /* SYS_LIGHTWEIGHT_PROT */  
//原本
//  SYS_ARCH_DECL_PROTECT(old_level);
// SYS_ARCH_PROTECT(old_level); 

#ifdef PBUF_STATS
    for(q = p; q != NULL; q = q->next) {
      --lwip_stats.pbuf.used;
    }
#endif /* PBUF_STATS */

  if(pbuf_pool_alloc_cache == NULL) {
    pbuf_pool_alloc_cache = p;
  } else {  
    for(q = pbuf_pool_alloc_cache; q->next != NULL; q = q->next);
    q->next = p;    
  }

//丁一修改  
#if SYS_LIGHTWEIGHT_PROT
  SYS_ARCH_UNPROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */
  sys_sem_signal(pbuf_pool_free_sem);
#endif /* SYS_LIGHTWEIGHT_PROT */  
//原本  
//  SYS_ARCH_UNPROTECT(old_level);  
}

/**
 * @internal only called from pbuf_alloc()
 */

static struct pbuf *
pbuf_pool_alloc(void)
{
  struct pbuf *p = NULL;

//丁一修改
#if SYS_LIGHTWEIGHT_PROT
  SYS_ARCH_DECL_PROTECT(old_level);
  SYS_ARCH_PROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */  
  sys_sem_wait(pbuf_pool_free_sem);
#endif /* SYS_LIGHTWEIGHT_PROT */  
//原本
//  SYS_ARCH_DECL_PROTECT(old_level);
//  SYS_ARCH_PROTECT(old_level); 

  /* First, see if there are pbufs in the cache. */
  
  if(pbuf_pool_alloc_cache) {
    p = pbuf_pool_alloc_cache;
    if(p) {
      pbuf_pool_alloc_cache = p->next; 
    }
  } else {
#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) {
#ifdef 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      
#ifdef PBUF_STATS
    } else {
      ++lwip_stats.pbuf.alloc_locked;
#endif /* PBUF_STATS */
    }
    pbuf_pool_alloc_lock = 0;
#endif /* SYS_LIGHTWEIGHT_PROT */    
  }
  
#ifdef 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 */

  //丁一修改  
#if SYS_LIGHTWEIGHT_PROT
  SYS_ARCH_UNPROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */
  sys_sem_signal(pbuf_pool_free_sem);
#endif /* SYS_LIGHTWEIGHT_PROT */  
//原本  
//  SYS_ARCH_UNPROTECT(old_level);  

  return p;   
}


/**
 * Allocates a pbuf.
 *
 * 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 */

  /* 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();
    if (p == NULL) {
#ifdef 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",
	    ((u32_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 pbuf type */
    p->flags = PBUF_FLAG_POOL;
    
    /* 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) {
       DEBUGF(PBUF_DEBUG | 2, ("pbuf_alloc: Out of pbufs in pool.\n"));

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品国产综合久久婷婷香蕉| 日本亚洲三级在线| 亚洲欧美国产毛片在线| 欧美高清一级片在线观看| 亚洲一区中文日韩| 国产成人鲁色资源国产91色综| 99久久精品国产一区二区三区| 欧美裸体bbwbbwbbw| 亚洲色图丝袜美腿| 国产一区啦啦啦在线观看| 欧美日韩中字一区| 一区精品在线播放| 国产麻豆精品久久一二三| 91精品国产aⅴ一区二区| 亚洲日本在线a| 成人成人成人在线视频| 久久―日本道色综合久久| 美国三级日本三级久久99| 欧美精品精品一区| 亚洲成人午夜电影| 欧美日韩精品一区二区三区四区| 成人网男人的天堂| 石原莉奈在线亚洲三区| 91视视频在线观看入口直接观看www | 日韩视频一区二区在线观看| 亚洲亚洲精品在线观看| 色婷婷激情综合| 一区二区视频免费在线观看| 91在线视频网址| 中文字幕一区二区三区不卡| 丁香婷婷综合网| 中文字幕制服丝袜一区二区三区| 高清国产一区二区| 国产精品午夜在线| 91在线国产福利| 亚洲视频香蕉人妖| 99这里只有久久精品视频| 国产精品美女久久久久久久| 不卡一区在线观看| 亚洲精品免费在线观看| 色av成人天堂桃色av| 亚洲一区二区免费视频| 5566中文字幕一区二区电影| 免费欧美日韩国产三级电影| 精品蜜桃在线看| 成人网在线播放| 亚洲丝袜精品丝袜在线| 欧美亚洲高清一区二区三区不卡| 亚洲成精国产精品女| 欧美一区二区大片| 国产福利一区二区三区视频| 18欧美亚洲精品| 欧美美女一区二区在线观看| 青青草一区二区三区| 久久久久国产精品麻豆| 不卡区在线中文字幕| 亚洲午夜久久久久久久久久久| 7777女厕盗摄久久久| 国产精品99久久久久久久女警| 国产精品久久久久久久久果冻传媒| 91蜜桃免费观看视频| 日韩精品一区第一页| 久久网这里都是精品| 99精品偷自拍| 久久国产欧美日韩精品| 日韩在线卡一卡二| 精品理论电影在线| 99久久精品国产毛片| 日本网站在线观看一区二区三区| 中文字幕不卡三区| 欧美日韩精品欧美日韩精品一| 国产一区二区免费在线| 一区二区免费视频| 国产午夜久久久久| 欧美日韩在线免费视频| 丰满少妇在线播放bd日韩电影| 丝袜a∨在线一区二区三区不卡| 欧美国产一区二区在线观看| 欧美久久久久免费| 99麻豆久久久国产精品免费 | 亚洲人成在线观看一区二区| 欧美一区二区视频在线观看2020| va亚洲va日韩不卡在线观看| 视频一区二区三区中文字幕| 中文字幕一区二区三区四区| 欧美午夜电影一区| 成人高清视频在线观看| 日本亚洲视频在线| 一个色在线综合| 国产精品超碰97尤物18| 亚洲精品一区二区精华| 欧美日韩久久不卡| 91黄色激情网站| 成人国产精品视频| 老司机精品视频导航| 亚洲国产日日夜夜| 国产精品超碰97尤物18| 欧美国产成人在线| 欧美变态tickle挠乳网站| 欧美系列亚洲系列| 色噜噜狠狠色综合中国| 97久久精品人人澡人人爽| 成人小视频免费在线观看| 国产精品99久久久| 狠狠久久亚洲欧美| 精品亚洲porn| 久久97超碰国产精品超碰| 免费xxxx性欧美18vr| 免费人成精品欧美精品| 麻豆91在线播放| 青青草伊人久久| 麻豆91在线播放免费| 麻豆成人久久精品二区三区红 | 色综合久久久久综合99| 成人午夜视频福利| 高潮精品一区videoshd| 成人理论电影网| 99久久伊人网影院| 成人av集中营| 91在线免费视频观看| 99re在线视频这里只有精品| 91在线观看免费视频| 99re6这里只有精品视频在线观看| 丰满少妇久久久久久久| 懂色av一区二区夜夜嗨| av一区二区三区黑人| 色综合网色综合| 欧美日韩国产精品自在自线| 91精品国产91久久综合桃花| 精品少妇一区二区三区在线播放| 久久一区二区三区四区| 国产欧美一区二区三区在线老狼| 欧美激情一区在线观看| 亚洲婷婷综合色高清在线| 亚洲一区二区三区四区在线观看| 日韩高清不卡在线| 精品一区二区三区的国产在线播放 | 国产伦精品一区二区三区视频青涩| 韩国av一区二区三区在线观看| 国产老女人精品毛片久久| 97久久精品人人澡人人爽| 国产精品高潮呻吟| 最新国产精品久久精品| 一区二区在线免费| 精品一区二区国语对白| 成人午夜精品在线| 在线视频欧美区| 精品久久久久久久久久久久久久久| 久久这里只有精品首页| 亚洲精品美腿丝袜| 狠狠色2019综合网| 欧美亚洲国产怡红院影院| 精品国产乱码久久久久久浪潮| 中文字幕日韩一区| 婷婷久久综合九色综合伊人色| 国产成人精品免费网站| 欧美日韩国产精品成人| 亚洲国产精品传媒在线观看| 日韩激情一区二区| 国产v综合v亚洲欧| 欧美美女喷水视频| 中文字幕日本不卡| 韩国在线一区二区| 欧美日韩国产高清一区二区 | 亚洲一本大道在线| 豆国产96在线|亚洲| 日韩欧美成人激情| 夜夜精品视频一区二区| 国产精品123| 日韩一区二区三区三四区视频在线观看| 中文字幕日本乱码精品影院| 精品系列免费在线观看| 欧美日韩国产一区二区三区地区| 国产日韩欧美激情| 久久99精品视频| 欧美一区二区三区在线看| 亚洲国产精品尤物yw在线观看| 99久久久久久| 国产日产欧美一区二区三区| 日本不卡高清视频| 欧美猛男男办公室激情| 一区二区三区成人| 97精品视频在线观看自产线路二| 国产亚洲精品久| 国产一区二区毛片| 欧美电影免费观看高清完整版在线观看| 亚洲资源在线观看| 在线精品视频免费播放| 亚洲女同ⅹxx女同tv| 白白色 亚洲乱淫| 国产精品高清亚洲| 99riav久久精品riav| 国产精品成人在线观看 | 国产高清久久久久| 欧美精品一区二区三区在线播放 | 另类小说色综合网站| 欧美一区二区国产| 韩日av一区二区| 久久精品一级爱片| 成人福利在线看|