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

📄 netbuf.h

📁 一个uCOS-II下的tcpip协议栈实现源码
💻 H
📖 第 1 页 / 共 2 页
字号:
 *
 * nPrepend - Same as above except return the new nBuf chain on success, NULL
 * on failure.
 */
#if STATS_SUPPORT > 0
#define	nPREPEND(n, s, plen) { \
	if (nLEADINGSPACE(n) >= (plen)) { \
		if ((n)->len) (n)->data -= (plen); \
		else (n)->data = (n)->body + NBUFSZ - (plen); \
		(n)->len += (plen); \
		if (((n)->chainLen += (plen)) > nBufStats.maxChainLen.val) \
			nBufStats.maxChainLen.val = (n)->chainLen; \
		if (s) memcpy((n)->data, (const char *)(s), (plen)); \
	} else \
		(n) = nPrepend((n), (const char *)(s), (plen)); \
}
#else
#define	nPREPEND(n, s, plen) { \
	if (nLEADINGSPACE(n) >= (plen)) { \
		if ((n)->len) (n)->data -= (plen); \
		else (n)->data = (n)->body + NBUFSZ - (plen); \
		(n)->len += (plen); \
		(n)->chainLen += (plen); \
		if (s) memcpy((n)->data, (const char *)(s), (plen)); \
	} else \
		(n) = nPrepend((n), (const char *)(s), (plen)); \
}
#endif
NBuf *nPrepend(
	NBuf	*n,					/* Destination nBuf chain. */
	const char *s,				/* The data to prepend. */
	u_int	plen				/* The length of the data to prepend. */
);


/*
 * nAPPEND - Append slen bytes to the nBuf chain n and load from s if non-null.
 * cLen is set to the number of bytes copied.  Note that the chain length is
 * updated but the chain is assumed to not be in a queue.
 *
 * nAPPENDCHAR - Append a single character to the nBuf chain.  cLen is set
 * to 1 on success, 0 on failure.  Note that c must be a legal lvalue so
 * that it's address may be passed to a function.
 *
 * nAppend - As above expect return the number of bytes copied.
 *
 * nAppendBuf - Append data from a source buffer chain starting from the offset
 * onto the end of the destination chain.  Return the number of characters
 * appended.
 *
 * nAppendFromQ - Append data from a source queue starting from the offset
 * onto the end of the destination chain.  Return the number of characters
 * appended.
 */
#if STATS_SUPPORT > 0
#define nAPPEND(n, s, sLen, cLen) { \
	if ((n)->nextBuf == NULL && nTRAILINGSPACE(n) >= (sLen)) { \
		(n)->len += (sLen); \
		if (((n)->chainLen += (sLen)) > nBufStats.maxChainLen.val) \
			nBufStats.maxChainLen.val = (n)->chainLen; \
		if (s) memcpy((n)->data, (s), (sLen)); \
		(cLen) = (sLen); \
	} else \
		(cLen) = nAppend((n), (s), (sLen)); \
}
#define nAPPENDCHAR(n, c, cLen) { \
	if ((n)->nextBuf == NULL && nTRAILINGSPACE(n) > 0) { \
		(n)->data[(n)->len++] = c; \
		if (++(n)->chainLen > nBufStats.maxChainLen.val) \
			nBufStats.maxChainLen.val = (n)->chainLen; \
		(cLen) = 1; \
	} else \
		(cLen) = nAppend((n), &(c), 1); \
}
#else
#define nAPPEND(n, s, sLen, cLen) { \
	if ((n)->nextBuf == NULL && nTRAILINGSPACE(n) >= (sLen)) { \
		(n)->len += (sLen); \
		(n)->chainLen += (sLen); \
		if (s) memcpy((n)->data, (s), (sLen)); \
		(cLen) = (sLen); \
	} else \
		(cLen) = nAppend((n), (s), (sLen)); \
}
#define nAPPENDCHAR(n, c, cLen) { \
	if ((n)->nextBuf == NULL && nTRAILINGSPACE(n) > 0) { \
		(n)->data[(n)->len++] = c; \
		(n)->chainLen++; \
		(cLen) = 1; \
	} else \
		(cLen) = nAppend((n), &(c), 1); \
}
#endif
u_int nAppend(NBuf *n, const char *s, u_int sLen);
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 nAppendFromQ(
	NBuf *nDst,					/* The destination chain. */
	NBufQHdr *nSrcQ,			/* The source queue. */
	u_int off0, 				/* The starting offset into the source. */
	u_int len					/* The maximum bytes to copy. */
);

/* nBufCopy - Return a new nBuf chain containing a copy of up to len bytes of
 * an nBuf chain starting "off0" bytes from the beginning.
 * Return the new chain on success, otherwise NULL. 
 */
NBuf *nBufCopy(
	NBuf *n,					/* Top of nBuf chain to be copied. */
	u_int off0, 				/* Offset into the nBuf chain's data. */
	u_int len					/* Maximum bytes to copy. */
);

/*
 * nPullup - Rearange an nBuf chain so that len bytes are contiguous and in
 * the data area of the buffer thereby allowing direct access to a structure
 * of size len. 
 * Return the resulting nBuf chain on success.  On failure, the original
 * nBuf is freed and NULL is returned.
 */
NBuf *nPullup(NBuf *n, u_int len);

/*
 * nCopyOut - Copy len bytes from an nBuf chain starting from an offset in
 * that chain.
 * Return the number of bytes copied.
 */
u_int nCopyOut(
	char *d, 					/* Destination string. */
	NBuf *n0, 					/* Source nBuf chain. */
	u_int off0, 				/* Offset into the nBuf chain's data. */
	u_int len					/* Max bytes to copy. */
);

/*
 * nSplit - Partition an nBuf chain in two pieces leaving len bytes in the
 * original chain.  A len of zero leaves an empty nBuf for n.  A len longer
 * than the amount of data in the chain returns NULL.
 * Return the new chain produced by the tail on success.  Otherwise, return
 * NULL and attempt to restore the chain to its original state.
 */
NBuf *nSplit(
	NBuf *n, 					/* The chain to be split. */
	u_int len					/* The bytes to leave in the original chain. */
);

/* 
 * nTrim - Trim up to len bytes from the chain, copying the data into
 * dst if dst is not NULL.  len > 0 trims off the front,
 * len < 0 trims off the end.  *nb is set to the new chain, NULL if
 * |len| >= the amount of data in the chain.
 * Note that this depends on the chain length field being accurate.
 * Return the actual number of bytes trimmed (always positive).
 *
 * nTrimQ - Trim bytes from the front of a buffer queue.
 * Note: The queue needs to be protected from collisions for the duration
 * of this call.
 * Return the number of bytes trimmed.
 */
int nTrim(char *dst, NBuf **nb, int len);
int nTrimQ(char *dst, NBufQHdr *qh, u_int len);


/*
 * nCat - Concatenate nBuf chain n2 to n1.  The chain length of n2 is added
 * to n1.
 * Return the new chain.
 */
NBuf *nCat(NBuf *n1, NBuf *n2);

/*
 * nChainLen - Determine the chain length of the mBuf chain and update the
 * chain length of the chain header.
 * Return the chain length.
 */
u_int nChainLen(NBuf *n);

/*
 * nENQUEUE - Add nBuf chain n to the end of the queue q.  q must be a
 * pointer to an nBufQHdr.  If any of them are NULL, nothing happens.
 *
 * nEnqSort - Insert a new chain into the queue in sorted order.
 * The sort function is designed to handle wrapping 32 bit values.
 * Return the number of chains in the queue on success, an error code
 * on error.
 */
#define nENQUEUE(q, n) \
	if ((n) && (q)) { \
		OS_ENTER_CRITICAL(); \
		if (!(q)->qTail) \
			(q)->qHead = (q)->qTail = (n); \
		else \
			(q)->qTail = ((q)->qTail->nextChain = n); \
		(q)->qLen++; \
		OS_EXIT_CRITICAL(); \
	}
int nEnqSort(NBufQHdr *qh, NBuf *nb, u_long sort);
		
    
/*
 * nDEQUEUE - Remove the first buffer chain, if any, from the queue q.
 * q must be a pointer to an nBufQHdr.  If q is NULL or empty, n is set to 
 * NULL.
 */
#define nDEQUEUE(q, n) { \
	OS_ENTER_CRITICAL(); \
	if (!(q) || !(q)->qHead) { \
		OS_EXIT_CRITICAL(); \
		(n) = NULL; \
	} else { \
		if (((q)->qHead = ((n) = (q)->qHead)->nextChain) == NULL) \
			(q)->qTail = NULL; \
		(q)->qLen--; \
		OS_EXIT_CRITICAL(); \
		(n)->nextChain = NULL; \
	} \
}

/*
 * nQHEAD - Returns a pointer to the first buffer chain in the queue.
 *
 * nQHEADSORT - Returns the sort value of the first buffer chain in the queue.
 */
#define nQHEAD(q) ((q) ? (q)->qHead : NULL)
#define nQHEADSORT(q) (((q) && (q)->qHead) ? (q)->qHead->sortOrder : 0)

/*
 * nQLENGTH - Returns the number of chains in the queue.
 */
#define nQLENGTH(q) ((q) ? (q)->qLen : 0)


#if DEBUG_SUPPORT > 0
/*
 * nDumpChain - Dump the details of the given buffer chain to the trace log.
 */
void nDumpChain(NBuf *n);
#endif

#endif

⌨️ 快捷键说明

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