⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netbuflib.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 5 页
字号:
* RETURNS: CL_BLK_ID or NULL.*/CL_BLK_ID netClBlkJoin    (    CL_BLK_ID		pClBlk,		/* pointer to a cluster Blk */    char *		pClBuf,		/* pointer to a cluster buffer */    int			size,		/* size of the cluster buffer */    FUNCPTR		pFreeRtn,	/* pointer to the free routine */    int			arg1,		/* argument 1 of the free routine */    int			arg2,		/* argument 2 of the free routine */    int			arg3		/* argument 3 of the free routine */    )    {    if (pClBlk == NULL || pClBuf == NULL)        return (NULL);    pClBlk->clNode.pClBuf 	= pClBuf;    pClBlk->clSize 		= size;    pClBlk->pClFreeRtn 		= pFreeRtn;    pClBlk->clFreeArg1 		= arg1;    pClBlk->clFreeArg2 		= arg2;    pClBlk->clFreeArg3 		= arg3;    pClBlk->clRefCnt		= 1;    return (pClBlk);    }/********************************************************************************* netMblkClJoin - join an `mBlk' to a `clBlk'-cluster construct** This routine joins the previously reserved `mBlk' referenced in <pMblk> to* the `clBlk'-cluster construct referenced in <pClBlk>. * Internally, this routine sets the M_EXT flag in 'mBlk.mBlkHdr.mFlags'.  It * also and sets the 'mBlk.mBlkHdr.mData' to point to the start of the data * in the cluster.** .SH "RETURNS"* M_BLK_ID or NULL. **/M_BLK_ID netMblkClJoin    (    M_BLK_ID 		pMblk,		/* pointer to an mBlk */    CL_BLK_ID		pClBlk		/* pointer to a cluster Blk */    )    {    if (pMblk == NULL || pClBlk == NULL)        return (NULL);    pMblk->mBlkHdr.mData 	= pClBlk->clNode.pClBuf;    pMblk->mBlkHdr.mFlags 	|= M_EXT;    pMblk->pClBlk		= pClBlk;    return (pMblk);    }/********************************************************************************* netClPoolIdGet - return a CL_POOL_ID for a specified buffer size * This routine returns a CL_POOL_ID for a cluster pool containing clusters * that match the specified <bufSize>.  If bestFit is TRUE, this routine returns * a CL_POOL_ID for a pool that contains clusters greater than or equal * to <bufSize>.  If <bestFit> is FALSE, this routine returns a CL_POOL_ID for a * cluster from whatever cluster pool is available.  If the memory pool * specified by <pNetPool> contains only one cluster pool, <bestFit> should * always be FALSE.*** RETURNS: CL_POOL_ID or NULL.*/CL_POOL_ID netClPoolIdGet    (    NET_POOL_ID		pNetPool,	/* pointer to the net pool */    int 		bufSize,	/* size of the buffer */    BOOL		bestFit		/* TRUE/FALSE */    )    {    if (pNetPool == NULL || pNetPool->pFuncTbl == NULL ||        pNetPool->pFuncTbl->pClPoolIdGetRtn == NULL)        return (NULL);    return ((*pNetPool->pFuncTbl->pClPoolIdGetRtn) (pNetPool, bufSize,                                                    bestFit));    }/********************************************************************************* netMblkToBufCopy - copy data from an `mBlk' to a buffer** This routine copies data from the `mBlk' chain referenced in <pMblk> to * the buffer referenced in <pBuf>.  It is assumed that <pBuf> points to * enough memory to contain all the data in the entire `mBlk' chain.* The argument <pCopyRtn> expects either a NULL or a function pointer to a * copy routine.  The arguments passed to the copy routine are source * pointer, destination pointer and the length of data to copy.  If <pCopyRtn> * is NULL, netMblkToBufCopy() uses a default routine to extract the data from * the chain.* * .SH "RETURNS"* The length of data copied or zero.*/int netMblkToBufCopy    (    M_BLK_ID 		pMblk,		/* pointer to an mBlk */    char *		pBuf,		/* pointer to the buffer to copy */    FUNCPTR		pCopyRtn	/* function pointer for copy routine */    )    {    char *		pChar;    if (pCopyRtn == NULL)        pCopyRtn = (FUNCPTR) bcopy;	/* default copy routine */    pChar = pBuf;    while (pMblk != NULL)        {        (*pCopyRtn) ((char *)pMblk->mBlkHdr.mData, pBuf, pMblk->mBlkHdr.mLen);        pBuf 	+= pMblk->mBlkHdr.mLen;        pMblk 	= pMblk->mBlkHdr.mNext;        }    return ((int) pBuf - (int) pChar);		/* return length copied */    }/********************************************************************************* netMblkDup - duplicate an `mBlk'** This routine copies the references from a source `mBlk' in * an `mBlk'-`clBlk'-cluster construct to a stand-alone `mBlk'.* This lets the two `mBlk' structures share the same `clBlk'-cluster* construct.  This routine also increments the reference count in the * shared `clBlk'.  The <pSrcMblk> expects a pointer to the source `mBlk'.  * The <pDescMblk> parameter expects a pointer to the destination `mBlk'. ** .SH "RETURNS"* A pointer to the destination `mBlk' or NULL if the source `mBlk' * referenced in <pSrcMblk> is not part of a * valid `mBlk'-`clBlk'-cluster construct.**/M_BLK_ID netMblkDup    (    M_BLK_ID	pSrcMblk,		/* pointer to source mBlk */    M_BLK_ID	pDestMblk		/* pointer to the destination mBlk */    )    {    int		level;			/* level of interrupt */    if (pSrcMblk == NULL || pDestMblk == NULL)        return (NULL);    if (M_HASCL (pSrcMblk))		/* only if associated with a cluster */        {        if (pSrcMblk->mBlkHdr.mFlags & M_PKTHDR)            pDestMblk->mBlkPktHdr = pSrcMblk->mBlkPktHdr;        pDestMblk->mBlkHdr.mData 	= pSrcMblk->mBlkHdr.mData;        pDestMblk->mBlkHdr.mLen 	= pSrcMblk->mBlkHdr.mLen;        pDestMblk->mBlkHdr.mType 	= pSrcMblk->mBlkHdr.mType;        pDestMblk->mBlkHdr.mFlags 	= pSrcMblk->mBlkHdr.mFlags;        pDestMblk->pClBlk 		= pSrcMblk->pClBlk;        level = intLock ();        ++(pDestMblk->pClBlk->clRefCnt);	/* increment the ref count */        intUnlock (level);        }    else        pDestMblk = NULL;    return (pDestMblk);    }/********************************************************************************* netMblkChainDup - duplicate an `mBlk' chain** This routine makes a copy of an `mBlk' chain starting at <offset> bytes from* the beginning of the chain and continuing for <len> bytes.  If <len> * is M_COPYALL, then this routine will copy the entire `mBlk' chain from * the <offset>.* * This routine copies the references from a source <pMblk> chain to* a newly allocated `mBlk' chain. * This lets the two `mBlk' chains share the same `clBlk'-cluster* constructs.  This routine also increments the reference count in the * shared `clBlk'.  The <pMblk> expects a pointer to the source `mBlk'* chain.  * The <pNetPool> parameter expects a pointer to the netPool from which* the new `mBlk' chain is allocated.** The <canWait> parameter expects* either M_WAIT or M_DONTWAIT.  If <canWait> is M_WAIT, this* routine blocks until `mBlk' is available.  * If <canWait> is M_DONTWAIT and no `mBlk' is immediately available,* this routine returns immediately (no blocking) * with a NULL value.** SEE ALSO: netMblkDup()** .SH "RETURNS"* A pointer to the newly allocated `mBlk' chain or NULL.** ERRNO:*  S_netBufLib_INVALID_ARGUMENT*  S_netBufLib_NO_POOL_MEMORY*/M_BLK_ID netMblkChainDup    (    NET_POOL_ID	pNetPool,		/* pointer to the pool */    M_BLK_ID	pMblk,			/* pointer to source mBlk chain*/    int 	offset,			/* offset to duplicate from */	    int 	len,			/* length to copy */    int		canWait			/* M_DONTWAIT/M_WAIT */    )    {    M_BLK_ID 	pNewMblk = NULL;    M_BLK_ID *	ppMblk   = NULL;    M_BLK_ID 	top      = NULL;    BOOL	copyhdr  = FALSE;    int 	off      = offset;    int		level;    if (off < 0 || len < 0)        {        errno = S_netBufLib_INVALID_ARGUMENT;        goto netMblkChainDupError;        }    if (off == 0 && pMblk->mBlkHdr.mFlags & M_PKTHDR)	copyhdr = TRUE;    while (off > 0)	{	if (pMblk == 0)            {            errno = S_netBufLib_INVALID_ARGUMENT;            goto netMblkChainDupError;            }	if (off < pMblk->mBlkHdr.mLen)	    break;	off   -= pMblk->mBlkHdr.mLen;	pMblk = pMblk->mBlkHdr.mNext;	}    ppMblk = &top;    while (len > 0)	{	if (pMblk == 0)	    {	    if (len != M_COPYALL)                {                errno = S_netBufLib_INVALID_ARGUMENT;                goto netMblkChainDupError;                }	    break;	    }	pNewMblk = mBlkGet(pNetPool, canWait, pMblk->mBlkHdr.mType);	if ((*ppMblk = pNewMblk) == NULL)            {            errno = S_netBufLib_NO_POOL_MEMORY;            goto netMblkChainDupError;            }	if (copyhdr)	    {            pNewMblk->mBlkPktHdr = pMblk->mBlkPktHdr;	    if (len == M_COPYALL)		pNewMblk->mBlkPktHdr.len -= offset;	    else		pNewMblk->mBlkPktHdr.len = len;	    copyhdr = FALSE;	    }	pNewMblk->mBlkHdr.mFlags = pMblk->mBlkHdr.mFlags; 	pNewMblk->mBlkHdr.mLen = min(len, pMblk->mBlkHdr.mLen - off);	pNewMblk->mBlkHdr.mData = pMblk->mBlkHdr.mData + off;	pNewMblk->pClBlk = pMblk->pClBlk;        level = intLock ();        ++(pNewMblk->pClBlk->clRefCnt);	/* increment the ref count */        intUnlock (level);	if (len != M_COPYALL)	    len -= pNewMblk->mBlkHdr.mLen;	off = 0;	pMblk = pMblk->mBlkHdr.mNext;	ppMblk = &pNewMblk->mBlkHdr.mNext;	}    return (top);    netMblkChainDupError:    	{        if (top != NULL)            netMblkClChainFree (top);        return (NULL);        }    }/********************************************************************************* netMblkOffsetToBufCopy - copy data from an `mBlk' from an offset to a buffer** This routine copies data from the `mBlk' chain referenced in <pMblk> to * the buffer referenced in <pBuf>.  It is assumed that <pBuf> points to * enough memory to contain all the data in the entire `mBlk' chain.* The argument <pCopyRtn> expects either a NULL or a function pointer to a * copy routine.  The arguments passed to the copy routine are source * pointer, destination pointer and the length of data to copy.  If <pCopyRtn> * is NULL, netMblkToBufCopy() uses a default routine to extract the data from * the chain.  The argument <offset> is a an offset from the first byte of data* in the mBlk chain.  The argument <len> is the total of length of data to be* copied from the mBlk Chain.  If value of <len> is M_COPYALL then the entire* mBlkChain is copied from the offset.  M_COPYALL is defined to be 1000000000** NOMANUAL** .SH "RETURNS"* The length of data copied or zero.** ERRNO:*  S_netBufLib_INVALID_ARGUMENT*/int netMblkOffsetToBufCopy    (    M_BLK_ID 	pMblk,		/* pointer to an mBlk */    int		offset,		/* offset to copy from */    char *	pBuf,		/* pointer to the buffer to copy */    int 	len,		/* length to copy */    FUNCPTR	pCopyRtn	/* function pointer for copy routine */    )    {    ULONG 	count;    char *	pChar;    pChar = pBuf;    if (pCopyRtn == NULL)        pCopyRtn = (FUNCPTR) bcopy;	/* default copy routine */    if (offset < 0 || len < 0 || pMblk == NULL)         goto netMblkOffsetToBufCopyError;        while (offset > 0 && pMblk != NULL)	{	if (offset < pMblk->mBlkHdr.mLen)	    break;	offset -= pMblk->mBlkHdr.mLen;	pMblk  = pMblk->mBlkHdr.mNext;	}    while (len > 0 && pMblk != NULL)	{        if (len != M_COPYALL)            {            count = min(pMblk->mBlkHdr.mLen - offset, len);            len   -= count;            }        else            count = pMblk->mBlkHdr.mLen - offset;                    (*pCopyRtn) ((char *)pMblk->mBlkHdr.mData + offset, pBuf, count);	pBuf   += count;	offset = 0;	pMblk  = pMblk->mBlkHdr.mNext;	}    return ((int) pBuf - (int) pChar);		/* return length copied */        netMblkOffsetToBufCopyError:    	{        errno = S_netBufLib_INVALID_ARGUMENT;        return (0);        }    }#if 0 /* XXX support may be required later *//********************************************************************************* netMblkFromBufCopy - copy data to an mBlk chain** This routine copies data from a given buffer to an mBlk chain.* The argument <pCopyRtn> is a function pointer to a copy routine which* if not specified a default copy routine would be used.  The arguments passed* to the copy routine are source pointer, destination pointer and the length* of data to copy.  The data is copied from an offset indicated the argument* <offset>.** NOMANUAL** RETURNS unsigned char pointer to the buffer or NULL.*/UCHAR * netMblkFromBufCopy    (    M_BLK_ID 	pMblk,		/* pointer to an mBlk chain */    char *	pBuffer,	/* pointer to the data buffer */    int 	offset,		/* offset from the beginning of the data */    int 	len,		/* total length to copy */    FUNCPTR	pCopyRtn	/* function pointer for copy routine */    )    {    return (NULL);    }#endif /* XXX future support */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -