Changeset 31448 in vbox for trunk/include/iprt/sg.h
- Timestamp:
- Aug 8, 2010 12:47:52 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/sg.h
r30470 r31448 204 204 RTDECL(size_t) RTSgBufSegArrayCreate(PRTSGBUF pSgBuf, PRTSGSEG paSeg, unsigned *pcSeg, size_t cbData); 205 205 206 /** 207 * Maps the given S/G buffer to a segment array of another type 208 * (for example to iovec on Posix or WSABUF on Windows). 209 * 210 * @param paMapped Where to store the pointer to the start of the native array or NULL. 211 * The memory needs to be freed with RTMemTmpFree(). 212 * @param pSgBuf The S/G buffer to map. 213 * @param Struct Struct used as the destination. 214 * @param pvBuf Name of the field holding the pointer to a buffer. 215 * @param TypeBufPtr Type of the buffer pointer. 216 * @param cbBuf Name of the field holding the size of the buffer. 217 * @param TypeBufSize Type of the field for the buffer size. 218 * @param cSegsMapped Where to store the number of segments the native array has. 219 * 220 * @note This operation maps the whole S/G buffer starting at the current internal position. 221 * The internal buffer position is unchanged by this operation. 222 * 223 * @remark Usage is a bit ugly but saves a few lines of duplicated code somewhere else and makes it possible to 224 * keep the S/G buffer members private without going through RTSgBufSegArrayCreate() first. 225 */ 226 #define RTSgBufMapToNative(paMapped, pSgBuf, Struct, pvBuf, TypeBufPtr, cbBuf, TypeBufSize, cSegsMapped) \ 227 do \ 228 { \ 229 AssertCompileMemberSize(Struct, pvBuf, RT_SIZEOFMEMB(RTSGSEG, pvSeg)); \ 230 AssertCompileMemberSize(Struct, cbBuf, RT_SIZEOFMEMB(RTSGSEG, cbSeg)); \ 231 cSegsMapped = pSgBuf->cSegs - pSgBuf->idxSeg; \ 232 \ 233 paMapped = NULL; \ 234 \ 235 /* We need room for at least one segment. */ \ 236 if (pSgBuf->cSegs == pSgBuf->idxSeg) \ 237 cSegsMapped++; \ 238 \ 239 paMapped = (Struct *)RTMemTmpAllocZ(cSegsMapped * sizeof(Struct)); \ 240 if (paMapped) \ 241 { \ 242 /* The first buffer is special because we could be in the middle of a segment. */ \ 243 paMapped[0].pvBuf = (TypeBufPtr)pSgBuf->pvSegCur; \ 244 paMapped[0].cbBuf = (TypeBufSize)pSgBuf->cbSegLeft; \ 245 \ 246 for (unsigned i = 1; i < cSegsMapped; i++) \ 247 { \ 248 paMsg[i].pvBuf = (TypeBufPtr)pSgBuf->paSegs[pSgBuf->idxSeg + i].pvSeg; \ 249 paMsg[i].cbBuf = (TypeBufSize)pSgBuf->paSegs[pSgBuf->idxSeg + i].cbSeg; \ 250 } \ 251 } \ 252 } \ 253 while (0) 254 206 255 RT_C_DECLS_END 207 256
Note:
See TracChangeset
for help on using the changeset viewer.