📄 netbuflib.c
字号:
}/********************************************************************************* netPoolDelete - delete a memory pool** This routine deletes the specified netBufLib-managed memory pool.** RETURNS: OK or ERROR.** ERRNO:* S_netBufLib_NETPOOL_INVALID*/STATUS netPoolDelete ( NET_POOL_ID pNetPool /* pointer to a net pool */ ) { int ix; /* index variable */ int iy; /* index variable */ CL_POOL_ID pClPool; /* pointer to the pool */ if (pNetPool->pPoolStat == NULL) { errno = S_netBufLib_NETPOOL_INVALID; return (ERROR); /* pool already deleted */ } free (pNetPool->pPoolStat); for (ix = 0; ix < CL_TBL_SIZE; ix++) { pClPool = pNetPool->clTbl [ix]; if (pClPool != NULL) { for (iy = ix + 1; iy < CL_TBL_SIZE; iy++) { if (pClPool == pNetPool->clTbl [iy]) pNetPool->clTbl [iy] = NULL; } free (pClPool); } } bzero ((char *)pNetPool, sizeof(NET_POOL)); /* zero the structure */ return (OK); }/********************************************************************************* netMblkFree - free an `mBlk' back to its memory pool** This routine frees the specified `mBlk' back to the specified memory pool.** RETURNS: N/A*/void netMblkFree ( NET_POOL_ID pNetPool, /* pointer to the net pool */ M_BLK_ID pMblk /* mBlk to free */ ) { if (pNetPool == NULL || pNetPool->pFuncTbl == NULL || pNetPool->pFuncTbl->pMblkFreeRtn == NULL) return; (*pNetPool->pFuncTbl->pMblkFreeRtn) (pNetPool, pMblk); }/********************************************************************************* netClBlkFree - free a `clBlk'-cluster construct back to the memory pool** This routine decrements the reference counter in the specified `clBlk'. * If the reference count falls to zero, this routine frees both the `clBlk'* and its associated cluster back to the specified memory pool.** RETURNS: N/A*/void netClBlkFree ( NET_POOL_ID pNetPool, /* pointer to the net pool */ CL_BLK_ID pClBlk /* pointer to the clBlk to free */ ) { pNetPool = pClBlk->pNetPool; if (pNetPool == NULL || pNetPool->pFuncTbl == NULL || pNetPool->pFuncTbl->pClBlkFreeRtn == NULL) return; (*pNetPool->pFuncTbl->pClBlkFreeRtn) (pClBlk); }/********************************************************************************* netClFree - free a cluster back to the memory pool** This routine returns the specified cluster buffer back to the specified* memory pool. * * RETURNS: N/A*/void netClFree ( NET_POOL_ID pNetPool, /* pointer to the net pool */ UCHAR * pClBuf /* pointer to the cluster buffer */ ) { if (pNetPool == NULL || pNetPool->pFuncTbl == NULL || pNetPool->pFuncTbl->pClFreeRtn == NULL) return; (*pNetPool->pFuncTbl->pClFreeRtn) (pNetPool, pClBuf); }/********************************************************************************* netMblkClFree - free an `mBlk'-`clBlk'-cluster construct** For the specified `mBlk'-`clBlk'-cluster construct, this routine* frees the `mBlk' back to the specified memory pool. It also decrements * the reference count in the `clBlk' structure. If the reference count * falls to zero, no other `mBlk' structure reference this `clBlk'. In that * case, this routine also frees the `clBlk' structure and its associated * cluster back to the specified memory pool. ** RETURNS* If the specified `mBlk' was part of an `mBlk' chain, this routine returns * a pointer to the next `mBlk'. Otherwise, it returns a NULL.** ERRNO:* S_netBufLib_MBLK_INVALID*/M_BLK_ID netMblkClFree ( M_BLK_ID pMblk /* pointer to the mBlk */ ) { NET_POOL_ID pNetPool; if (pMblk == NULL) return (NULL); pNetPool = MBLK_TO_NET_POOL(pMblk); return ((*pNetPool->pFuncTbl->pMblkClFreeRtn) (pNetPool, pMblk)); }/********************************************************************************* netMblkClChainFree - free a chain of `mBlk'-`clBlk'-cluster constructs** For the specified chain of `mBlk'-`clBlk'-cluster constructs, this * routine frees all the `mBlk' structures back to the specified memory pool. * It also decrements the reference count in all the `clBlk' structures. If * the reference count in a `clBlk' falls to zero, this routine also frees * that `clBlk' and its associated cluster back to the specified memory pool. ** RETURNS: N/A** ERRNO:* S_netBufLib_MBLK_INVALID*/void netMblkClChainFree ( M_BLK_ID pMblk /* pointer to the mBlk */ ) { NET_POOL_ID pNetPool; while (pMblk != NULL) { pNetPool = MBLK_TO_NET_POOL(pMblk); pMblk = (*pNetPool->pFuncTbl->pMblkClFreeRtn) (pNetPool, pMblk); } }/********************************************************************************* netMblkGet - get an `mBlk'** This routine gets a `mBlk' from the specified memory pool.** .IP <pNetPool> 9* Expects a pointer to the pool from which you want an `mBlk'.* .IP <canWait>* Expects either M_WAIT or M_DONTWAIT. If <canWait> is M_WAIT, this * routine blocks until an `mBlk' is available. If <canWait> is M_DONTWAIT* and no `mBlk' is immediately available, this routine returns immediately* (no blocking) with a NULL value. * .IP <type>* Expects the type value that you want to associate with the returned `mBlk'.* .LP** RETURNS* M_BLK_ID, or a NULL if no `mBlk' was available.** ERRNO:* S_netBufLib_MBLK_INVALID*/M_BLK_ID netMblkGet ( NET_POOL_ID pNetPool, /* pointer to the net pool */ int canWait, /* M_WAIT/M_DONTWAIT */ UCHAR type /* mBlk type */ ) { if (pNetPool == NULL || pNetPool->pFuncTbl == NULL || pNetPool->pFuncTbl->pMblkGetRtn == NULL) return (NULL); return ((*pNetPool->pFuncTbl->pMblkGetRtn) (pNetPool, canWait, type)); }/********************************************************************************* netClBlkGet - get a `clBlk'** This routine gets a `clBlk' from the specified memory pool.* .IP <pNetPool> 9* Expects a pointer to the pool from which you want a `clBlk'.* .IP <canWait>* Expects either M_WAIT or M_DONTWAIT. If <canWait> is M_WAIT, this * routine blocks until an `clBlk' is available. If <canWait> is M_DONTWAIT* and no `clBlk' is immediately available, this routine returns immediately* (no blocking) with a NULL value. ** RETURNS: CL_BLK_ID or a NULL if no `clBlk' was available.*/CL_BLK_ID netClBlkGet ( NET_POOL_ID pNetPool, /* pointer to the net pool */ int canWait /* M_WAIT/M_DONTWAIT */ ) { if (pNetPool == NULL || pNetPool->pFuncTbl == NULL || pNetPool->pFuncTbl->pClBlkGetRtn == NULL) return (NULL); return ((*pNetPool->pFuncTbl->pClBlkGetRtn) (pNetPool, canWait)); }/********************************************************************************* netClusterGet - get a cluster from the specified cluster pool** This routine gets a cluster from the specified cluster pool <pClPool> * within the specified memory pool <pNetPool>. ** 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 construct from the specified * memory pool and joins it to the specified `mBlk' structure. This creates* an `mBlk'-`clBlk'-cluster construct that you can use to pass data* across the 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 construct. * .IP <pMbkl>* Expects a pointer to the `mBlk' structure (previously allocated) to which * you want to join the retrieved `clBlk'-cluster construct. * .IP <bufSize>* Expects the size, in bytes, of the cluster in the `clBlk'-cluster* construct. * .IP <canWait>* Expects either M_WAIT or M_DONTWAIT. If <canWait> is M_WAIT, this* routine blocks until a `clBlk'-cluster construct is available. * If <canWait> is M_DONTWAIT and no `clBlk'-cluster construct is * immediately available, this routine returns immediately (no blocking) * with an ERROR value.* .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.** .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 a `mBlk'-`clBlk'-cluster construct from the* specified memory pool. Use this construct to pass data across the * layers of the network stack.** .IP <pNetPool> 9* Expects a pointer to the memory pool from which you want to get a * free `mBlk'-`clBlk'-cluster construct. * .IP <bufSize>* Expects the size, in bytes, of the cluster in the `clBlk'-cluster* construct. * .IP <canWait>* Expects either M_WAIT or M_DONTWAIT. If <canWait> is M_WAIT, this* routine blocks until an `mBlk'-`clBlk'-cluster construct is available.* If <canWait> is M_DONTWAIT and no `mBlk'-`clBlk'-cluster construct is* immediately available, this routine returns immediately (no blocking) * with a NULL value.* .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.** 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.*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -