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

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

?? netbuf.c

?? 一個tcp/ip協議棧,帶有PPP、IP、TCP、UDP等協議
?? C
?? 第 1 頁 / 共 3 頁
字號:
/*****************************************************************************
* netbuf.c - Network Buffers program file.
*
* Copyright (c) 1998 by Global Election Systems Inc.  All rights reserved.
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice and the following disclaimer are included verbatim in any 
* distributions. No written agreement, license, or royalty fee is required
* for any of the authorized uses.
*
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *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 CONTRIBUTORS 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.
*
******************************************************************************
* REVISION HISTORY
*
* 98-01-30 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
*   Original based on BSD codes.
* 2001-05-18 Mads Christiansen <mads@mogi.dk>, Partner Voxtream 
*       Small bugfix in nSplit.
* 2001-04-05 Robert Dickenson <odin@pnc.com.au>, Cognizant Pty Ltd.
*       Updated in various ways.
******************************************************************************
* PROGRAMMER NOTES
*
* FREE BUFFER MARK
*   Free buffers have nextChain pointing back to themselves.
*
* CRITICAL SECTIONS
*   Only queue operations are protected from corruption from other tasks and
* interrupts.  It is assumed that only one task at a time operates on a buffer
* chain but multiple tasks will share queues.
*
* BUFFER QUEUES
*   The buffer queue structure's primary purpose is to minimize the overhead
* of adding a new chain to the queue.  A side benefit is that if packets
* span more than one nBuf, then the overhead to seek to a particular offset
* in the queue is reduced.  A queue is required to maintain boundaries of 
* incoming UDP datagrams if UDP support were added.
*****************************************************************************/

#include "netconf.h"
#include "netbuf.h"

#include <string.h>
#include <stdio.h>
#include "netdebug.h"

#pragma warning (push)
#pragma warning (disable: 4018) // signed/unsigned mismatch


/*************************/
/*** LOCAL DEFINITIONS ***/
/*************************/
#define MAXNBUFS 32                 /* The number of nBufs allocated. */

                                                                    
/******************************/
/*** PUBLIC DATA STRUCTURES ***/
/******************************/
NBuf *topNBuf;
#if STATS_SUPPORT > 0
NBufStats nBufStats;
u_int curFreeBufs;  // added by robert to make build
#else
u_int curFreeBufs;
#endif


/*****************************/
/*** LOCAL DATA STRUCTURES ***/
/*****************************/
/* The free list of buffers. */
static NBuf nBufs[MAXNBUFS];


/***********************************/
/*** PUBLIC FUNCTION DEFINITIONS ***/
/***********************************/
/* Initialize the memory buffer subsytem. */
void nBufInit(void)
{
    int i;
    
    topNBuf = &nBufs[0];
    for (i = 0; i < MAXNBUFS; i++) {
        nBufs[i].nextBuf = &nBufs[i + 1];
        nBufs[i].nextChain = &nBufs[i];
    }
    nBufs[MAXNBUFS - 1].nextBuf = NULL;
    
#if STATS_SUPPORT > 0
    memset(&nBufStats, 0, sizeof(nBufStats));
    nBufStats.headLine.fmtStr    = "\t\tNETWORK BUFFERS\r\n";
    nBufStats.curFreeBufs.fmtStr = "\tCURRENT FREE: %5lu\r\n";
    nBufStats.curFreeBufs.val = MAXNBUFS;
    nBufStats.minFreeBufs.fmtStr = "\tMINIMUM FREE: %5lu\r\n";
    nBufStats.minFreeBufs.val = MAXNBUFS;
    nBufStats.maxFreeBufs.fmtStr = "\tMAXIMUM FREE: %5lu\r\n";
    nBufStats.maxFreeBufs.val = MAXNBUFS;
    nBufStats.maxChainLen.fmtStr = "\tMAX CHAIN SZ: %5lu\r\n";
#else
    curFreeBufs = MAXNBUFS;
#endif
}

/*
 * nFree - Free a single nBuf and associated external storage.
 * Return the next nBuf in the chain, if any.
 */
NBuf* nFree(NBuf* n)
{
    NBuf* n0 = NULL;
    
    nFREE(n, n0);
    return n0;
}


/*
 * nFreeChain - Free all nBufs in a chain.  
 * Return the next chain in the queue, if any.
 */
NBuf* nFreeChain(NBuf* n)
{
    NBuf* n0;
    NBuf* n1 = NULL;
    
    if (n) {
        if (n->nextChain == n)
            panic("nFreeChain");
        else {
            n0 = n;
            n = n->nextChain;
            while (n0) {
                nFREE(n0, n1);
                n0 = n1;
            }
        }
    }
    return n;
}


/*
 * nPrepend - Prepend plen bytes to nBuf n and load from s if non-null.
 * A new nBuf is always allocated but if allocation fails, the
 * original nBuf chain is freed.  The chain size is updated.  This assumes
 * that the chain is not in a queue.
 * Return the new nBuf chain on success, NULL on failure.
 */
NBuf *nPrepend(
    NBuf    *n,                 /* Destination nBuf chain. */
    const char *s,              /* The data to prepend. */
    u_int   plen                /* The length of the data to prepend. */
)
{
    NBuf *n0;
    
    if (n) {
        nGET(n0);
        while (n0) {
            n0->nextBuf = n;
            if (plen > NBUFSZ) {
                n0->len = NBUFSZ;
#if STATS_SUPPORT > 0
                if ((n0->chainLen = n->chainLen + NBUFSZ) > nBufStats.maxChainLen.val)
                    nBufStats.maxChainLen.val = n0->chainLen;
#else
                n0->chainLen = n->chainLen + NBUFSZ;
#endif
                if (s) {
                    memcpy(n0->data, s + plen - NBUFSZ, NBUFSZ);
                }
                plen -= NBUFSZ;
                n = n0;
                nGET(n0);
            } else {
                n0->len = plen;
#if STATS_SUPPORT > 0
                if ((n0->chainLen = n->chainLen + plen) > nBufStats.maxChainLen.val)
                    nBufStats.maxChainLen.val = n0->chainLen;
#else
                n0->chainLen = n->chainLen + plen;
#endif
                n0->data = n0->body + NBUFSZ - plen;
                if (s) {
                    memcpy(n0->data, s, plen);
                }
                plen = 0;
                n = n0;
                /*** We're done, skip the test.
                n0 = NULL;
                ***/
                break;
            }
        }
        if (plen) {
            NBUFDEBUG((LOG_ERR, "nPrepend: No free buffers"));
            (void)nFreeChain(n);
            n = NULL;
        }
    }
    return n;
}


/*
 * nAppend - Append slen bytes to the nBuf chain n and load from s if non-null.
 * Note that the chain length is updated but the chain is assumed to not be in
 * a queue.
 * Return the number of bytes appended.
 */
u_int nAppend(NBuf *n, const char *s, u_int sLen)
{
    u_int copied = 0, i;
    NBuf *n0 = n;   

    if (n0 && sLen) {
        /* Find the last nBuf on the chain. */
        for (; n0->nextBuf; n0 = n0->nextBuf);
        /* If there's space, append what we can. */
        if ((i = (u_int)nTRAILINGSPACE(n0)) > 0) {
            if (i > sLen)
                i = sLen;
            /* n0->len += i; // this line moved to below */
#if STATS_SUPPORT > 0
            if ((n->chainLen += i) > nBufStats.maxChainLen.val)
                nBufStats.maxChainLen.val = n->chainLen;
#else
            n->chainLen += i;
#endif
            if (s) {
                // BUGFIX, replaced n0->data with n0->data + n0->len  and moved a line   /mogi
                memcpy( n0->data + n0->len , s, i);
                s += i;
            }
            // Moved this line here /mogi
            n0->len += i;
            copied = i;
            sLen -= i;
        }
        if (sLen) {
            nGET(n0->nextBuf);
            n0 = n0->nextBuf;
        }
    }
    /* Append new buffers until s is consumed or we fail to allocate. */
    while (n0 && sLen) {
        if (sLen > NBUFSZ) {
            n0->len = NBUFSZ;
#if STATS_SUPPORT > 0
            if ((n->chainLen += NBUFSZ) > nBufStats.maxChainLen.val)
                nBufStats.maxChainLen.val = n->chainLen;
#else
            n->chainLen += NBUFSZ;
#endif
            if (s) {
                memcpy(n0->data, s, NBUFSZ);
                s += NBUFSZ;
            }
            sLen -= NBUFSZ;
            copied += NBUFSZ;
        } else {
            n0->len = sLen;
#if STATS_SUPPORT > 0
            if ((n->chainLen += sLen) > nBufStats.maxChainLen.val)
                nBufStats.maxChainLen.val = n->chainLen;
#else
            n->chainLen += sLen;
#endif
            if (s) {
                memcpy(n0->data, s, sLen);
            }
            copied += sLen;
            break;  /* We're done, skip the test. */
        }
        nGET(n0->nextBuf);
        n0 = n0->nextBuf;
    }
    return copied;
}


/*
 * nAppendBuf - Append data from buffer chain n1 starting from the offset
 * onto the end of the chain n0.  
 * Return the number of characters appended.
 */
u_int nAppendBuf(
    NBuf *nDst,                 /* The destination chain. */
    NBuf *nSrc,                 /* The source chain. */
    u_int off0,                 /* The starting offset into the source. */
    u_int len                   /* The maximum bytes to copy. */
)
{
    u_int st = 0, copySz;
    NBuf *nTop = nDst, *nTmp;
    
    if (!nDst)
        return 0;
        
    /* Find the end of the destination chain. */
    nTop = nDst;
    for (; nDst->nextBuf; nDst = nDst->nextBuf)
        ;
        
    /* Find the starting position in the source chain. */
    for (; nSrc && off0 > nSrc->len; nSrc = nSrc->nextBuf)
        off0 -= nSrc->len;
    
    if (nSrc) {
      while (nSrc && nDst && len) {
//      while (nDst && len) {
            /* Compute how much to copy from the current source buffer. */
            copySz = min(len, nSrc->len - off0);

            /* Do we need to append another destination buffer? */
            /* 
             * Note that we don't attempt to fill small spaces at the
             * end of the current destination buffer since on average,
             * we don't expect that it would reduce the number of
             * buffers used and it would complicate and slow the 
             * operation.
             */
            if (nTRAILINGSPACE(nDst) < copySz) {
                nGET(nTmp);
                if (!nTmp) {
                    NBUFDEBUG((LOG_ERR, "nBufCopy: No free buffers"));
                    nDst = NULL;
                    break;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲综合男人的天堂| 欧美日韩一区二区三区四区五区| 成人免费三级在线| 欧美色综合久久| 国产精品福利一区二区三区| 麻豆成人综合网| 欧美亚洲图片小说| 亚洲另类一区二区| 国产成人免费视频一区| 欧美一区二区视频观看视频| 一区二区三区欧美激情| 成人免费看视频| 久久在线免费观看| 久久疯狂做爰流白浆xx| 欧美日韩和欧美的一区二区| 最好看的中文字幕久久| 国产成人精品在线看| 久久亚洲精品国产精品紫薇| 免费在线看成人av| 欧美日韩国产免费一区二区| 亚洲国产乱码最新视频 | 国产主播一区二区| 日韩一区二区在线播放| 亚洲1区2区3区视频| 在线视频中文字幕一区二区| 亚洲人成电影网站色mp4| 97久久久精品综合88久久| 国产精品嫩草99a| 大美女一区二区三区| 日本一区二区三区在线观看| 国产成人午夜精品影院观看视频 | 97精品久久久午夜一区二区三区 | av亚洲精华国产精华| 国产三级精品三级| 国产成人在线观看| 中国av一区二区三区| 成人免费视频免费观看| 亚洲天堂2014| 日本精品视频一区二区三区| 亚洲精品国产一区二区精华液 | 久久久久国产精品厨房| 国产精品一区免费在线观看| 国产午夜精品一区二区| 99精品国产99久久久久久白柏| 国产精品女同互慰在线看 | 国产成人综合亚洲网站| 国产精品沙发午睡系列990531| 成人激情综合网站| 亚洲欧美日韩国产综合| 欧美日韩国产电影| 另类小说色综合网站| 国产日韩欧美精品一区| 国产精品主播直播| 一区二区三区在线视频观看58| 欧美区在线观看| 国产丶欧美丶日本不卡视频| 日韩美女精品在线| 制服丝袜激情欧洲亚洲| 国产一区二区伦理| 一区二区三区高清在线| 91精品国产综合久久精品麻豆 | 日韩av电影一区| 国产日产亚洲精品系列| 欧美亚洲禁片免费| 激情综合五月婷婷| 一区二区在线电影| 久久亚洲二区三区| 91极品视觉盛宴| 黄网站免费久久| 夜夜精品浪潮av一区二区三区| 日韩丝袜情趣美女图片| 91网页版在线| 九色综合国产一区二区三区| 一区二区三区日韩欧美| 国产亚洲一区二区三区四区| 欧美日韩成人在线| 丁香天五香天堂综合| 日韩一区精品视频| 1024亚洲合集| 久久久久久黄色| 337p亚洲精品色噜噜狠狠| 91一区二区在线| 国产福利一区二区三区视频| 日日欢夜夜爽一区| 亚洲三级在线看| 久久久久久久电影| 精品国产免费人成在线观看| 精品视频123区在线观看| 波多野结衣亚洲一区| 精品在线视频一区| 午夜欧美电影在线观看| 亚洲品质自拍视频| 中文av字幕一区| 国产视频一区二区三区在线观看| 欧美一级欧美三级在线观看| 欧美性xxxxx极品少妇| 成人激情免费视频| 国产91综合网| 国产精品一区二区三区乱码| 久88久久88久久久| 免费成人在线播放| 日日摸夜夜添夜夜添亚洲女人| 亚洲一区二区三区中文字幕在线| 国产精品成人免费| 亚洲欧美在线视频| 国产精品免费观看视频| 国产精品久久久久一区 | 日韩欧美一区二区视频| 欧美日韩中文字幕精品| 91成人免费在线视频| 色狠狠色噜噜噜综合网| 91国产精品成人| 在线亚洲精品福利网址导航| 99精品久久99久久久久| 不卡电影免费在线播放一区| 成人国产精品免费网站| 99久久777色| 91麻豆文化传媒在线观看| 91首页免费视频| 在线观看欧美日本| 欧美精品丝袜中出| 日韩欧美国产一二三区| 久久在线免费观看| 亚洲欧美综合网| 亚洲激情图片一区| 日韩福利电影在线观看| 美腿丝袜在线亚洲一区 | 蜜臀av一区二区在线观看| 卡一卡二国产精品| 高清国产一区二区| 99久久精品国产网站| 欧洲精品在线观看| 欧美xxxxx牲另类人与| 国产调教视频一区| 亚洲一卡二卡三卡四卡无卡久久 | 精品一区二区三区日韩| 国产成人啪午夜精品网站男同| a亚洲天堂av| 欧美日韩精品系列| 国产婷婷色一区二区三区在线| 亚洲少妇30p| 午夜精品福利一区二区三区蜜桃| 日韩成人午夜精品| 福利一区在线观看| 欧美日韩视频一区二区| 精品国产91乱码一区二区三区 | 久久久国产一区二区三区四区小说 | 国产三级久久久| 一区二区三区在线免费观看| 美女脱光内衣内裤视频久久影院| 丰满少妇久久久久久久| 欧美丰满美乳xxx高潮www| 国产欧美精品国产国产专区| 亚洲福利一区二区| 成人精品免费视频| 欧美一区二区成人| 亚洲欧美视频在线观看视频| 捆绑紧缚一区二区三区视频| 91麻豆蜜桃一区二区三区| 精品少妇一区二区三区视频免付费 | 日韩欧美高清一区| 一区二区三区中文字幕电影 | 欧美欧美欧美欧美首页| 国产三级欧美三级| 日本欧美韩国一区三区| 99久久伊人精品| 久久精品视频网| 蜜桃久久久久久| 欧美午夜精品免费| 国产精品美女久久福利网站| 日本不卡视频在线观看| 欧美这里有精品| 国产精品久久三区| 国产最新精品免费| 日韩一区二区三区高清免费看看| 亚洲欧美成人一区二区三区| 国产精品一卡二卡| 精品人伦一区二区色婷婷| 亚洲自拍欧美精品| 在线一区二区三区四区五区| 欧美激情一区在线观看| 国产又黄又大久久| 日韩欧美一区二区视频| 亚洲成人7777| 欧美日韩极品在线观看一区| 伊人婷婷欧美激情| av午夜一区麻豆| 国产精品福利电影一区二区三区四区| 精品一二三四区| 日韩欧美第一区| 麻豆精品精品国产自在97香蕉 | 国产清纯在线一区二区www| 亚洲chinese男男1069| 色婷婷激情久久| 中文字幕综合网| 色综合一区二区| 亚洲卡通动漫在线| 91国偷自产一区二区使用方法| 亚洲精品乱码久久久久久| 日本丶国产丶欧美色综合|