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

📄 netbuflib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
* within the specified memory pool <pNetPool>. ** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * Likewise, the returned ID is valid in the kernel protection domain only.* This restriction does not apply under non-AE versions of VxWorks.  ** RETURNS* This routine returns a character pointer to a cluster buffer or NULL* if none was available.**/char * netClusterGet    (    NET_POOL_ID		pNetPool,	/* pointer to the net pool */    CL_POOL_ID 		pClPool 	/* ptr to the cluster pool */    )    {    if (pNetPool == NULL || pNetPool->pFuncTbl == NULL ||        pNetPool->pFuncTbl->pClGetRtn == NULL)        return (NULL);    return ((*pNetPool->pFuncTbl->pClGetRtn) (pNetPool, pClPool));    }/********************************************************************************* netMblkClGet - get a `clBlk'-cluster and join it to the specified `mBlk'** This routine gets a `clBlk'-cluster pair from the specified memory pool* and joins it to the specified `mBlk' structure.  The `mBlk'-`clBlk'-cluster* triplet it produces is the basic structure for handling data at all layers* of the network stack.** .IP <pNetPool> 9* Expects a pointer to the memory pool from which you want to get a * free `clBlk'-cluster pair.* .IP <pMbkl>* Expects a pointer to the `mBlk' structure (previously allocated) to which * you want to join the retrieved `clBlk'-cluster pair.  * .IP <bufSize>* Expects the size, in bytes, of the cluster in the `clBlk'-cluster pair.  * .IP <canWait>* Expects either M_WAIT or M_DONTWAIT.  If either item is not immediately* available, the M_WAIT value allows this routine to repeat the allocation* attempt after performing garbage collection. It omits those steps when the* M_DONTWAIT value is used.* .IP <bestFit>* Expects either TRUE or FALSE.  If <bestFit> is TRUE and a cluster of the * exact size is unavailable, this routine gets a larger cluster (if* available).  If <bestFit> is FALSE and an exact size cluster is unavailable, * this routine gets either a smaller or a larger cluster (depending * on what is available).  Otherwise, it returns immediately with an ERROR value.* For memory pools containing only one cluster size, <bestFit> should always* be set to FALSE.** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * This restriction does not apply under non-AE versions of VxWorks.  ** .SH "RETURNS"* OK or ERROR.** ERRNO:*  S_netBufLib_CLSIZE_INVALID*/STATUS netMblkClGet    (    NET_POOL_ID		pNetPool,	/* pointer to the net pool */    M_BLK_ID	 	pMblk, 		/* mBlk to embed the cluster in */    int			bufSize,	/* size of the buffer to get */    int			canWait,	/* wait or dontwait */    BOOL		bestFit		/* TRUE/FALSE */    )    {    if (pNetPool == NULL || pNetPool->pFuncTbl == NULL ||        pNetPool->pFuncTbl->pMblkClGetRtn == NULL)        return (ERROR);    return ((*pNetPool->pFuncTbl->pMblkClGetRtn) (pNetPool, pMblk, bufSize,                                                  canWait, bestFit));    }/********************************************************************************* netTupleGet - get an `mBlk'-`clBlk'-cluster** This routine gets an `mBlk'-`clBlk'-cluster triplet from the specified* memory pool.  The resulting structure is the basic method for accessing* data at all layers of the network stack.** .IP <pNetPool> 9* Expects a pointer to the memory pool with which you want to build a* `mBlk'-`clBlk'-cluster triplet.* .IP <bufSize>* Expects the size, in bytes, of the cluster in the `clBlk'-cluster* pair.* .IP <canWait>* Expects either M_WAIT or M_DONTWAIT.  If any item in the triplet is not* immediately available, the M_WAIT value allows this routine to repeat the* allocation attempt after performing garbage collection. The M_DONTWAIT value* prevents those extra steps.* .IP <type>* Expects the type of data, for example MT_DATA, MT_HEADER. The various* values for this type are defined in netBufLib.h.* .IP <bestFit>* Expects either TRUE or FALSE.  If <bestFit> is TRUE and a cluster of the * exact size is unavailable, this routine gets a larger cluster (if* available).  If <bestFit> is FALSE and an exact size cluster is unavailable, * this routine gets either a smaller or a larger cluster (depending * on what is available).  Otherwise, it returns immediately with an ERROR value.* For memory pools containing only one cluster size, <bestFit> should always* be set to FALSE.** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * Likewise, the returned ID is valid in the kernel protection domain only.* This restriction does not apply under non-AE versions of VxWorks.  ** RETURNS* M_BLK_ID or NULL.** ERRNO:*  S_netBufLib_MBLK_INVALID*  S_netBufLib_CLSIZE_INVALID*  S_netBufLib_NETPOOL_INVALID*/M_BLK_ID netTupleGet    (    NET_POOL_ID		pNetPool,	/* pointer to the net pool */    int			bufSize,	/* size of the buffer to get */    int			canWait,	/* wait or dontwait */    UCHAR		type,		/* type of data */    BOOL		bestFit		/* TRUE/FALSE */    )    {    M_BLK_ID		pMblk = NULL; 		/* pointer to mBlk */    if (pNetPool != NULL && pNetPool->pFuncTbl != NULL)        {        pMblk = mBlkGet (pNetPool, canWait, type); 	/* get an mBlk */        /* allocate a cluster and point the mBlk to it */        if (pMblk && (mClGet (pNetPool, pMblk, bufSize, canWait, bestFit)                      != OK))            {            netMblkFree (pNetPool, pMblk);             pMblk = NULL;             }        }    else        errno = S_netBufLib_NETPOOL_INVALID;     return (pMblk);     }/********************************************************************************* netClBlkJoin - join a cluster to a `clBlk' structure ** This routine joins the previously reserved cluster specified by <pClBuf> * to the previously reserved `clBlk' structure specified by <pClBlk>. * The <size> parameter passes in the size of the cluster referenced * in <pClBuf>.  The arguments <pFreeRtn>, <arg1>, <arg2>, <arg3> set the  * values of the 'pCLFreeRtn', 'clFreeArg1', 'clFreeArg2', and 'clFreeArg1', * members of the specified `clBlk' structure.** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * Likewise, the returned ID is valid in the kernel protection domain only.* This restriction does not apply under non-AE versions of VxWorks.  ** 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.** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * Likewise, the returned ID is valid in the kernel protection domain only.* This restriction does not apply under non-AE versions of VxWorks.  ** .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.** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * Likewise, the returned ID is valid in the kernel protection domain only.* This restriction does not apply under non-AE versions of VxWorks.  ** 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'. ** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call this function from within the kernel * protection domain only.  In addition, all arguments to this function can  * reference only that data which is valid in the kernel protection domain. * Likewise, the returned ID is valid in the kernel protection domain only.* This restriction does not apply under non-AE versions of VxWorks.  ** .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 determines the behavior if any required 'mBlk'* is not immediately available. A valu

⌨️ 快捷键说明

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