Changeset 30468 in vbox
- Timestamp:
- Jun 28, 2010 1:58:04 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/sg.h
r28800 r30468 56 56 { 57 57 /** Pointer to the scatter/gather array. */ 58 PCRTSGSEG p caSeg;58 PCRTSGSEG paSegs; 59 59 /** Number of segments. */ 60 unsigned cSeg ;60 unsigned cSegs; 61 61 /** Current segment we are in. */ 62 62 unsigned idxSeg; 63 63 /** Pointer to the current segment start. */ 64 void *pvSegCur r;64 void *pvSegCur; 65 65 /** Number of bytes left in the current buffer. */ 66 66 size_t cbSegLeft; … … 78 78 * @returns nothing. 79 79 * @param pSgBuf Pointer to the S/G buffer to initialize. 80 * @param p caSegPointer to the start of the segment array.81 * @param cSeg 82 */ 83 RTDECL(void) RTSgBufInit(PRTSGBUF pSgBuf, PCRTSGSEG p caSeg, unsigned cSeg);80 * @param paSegs Pointer to the start of the segment array. 81 * @param cSegs Number of segments in the array. 82 */ 83 RTDECL(void) RTSgBufInit(PRTSGBUF pSgBuf, PCRTSGSEG paSegs, unsigned cSegs); 84 84 85 85 /** -
trunk/include/iprt/socket.h
r30270 r30468 188 188 RTDECL(int) RTSocketSgWrite(RTSOCKET hSocket, PCRTSGBUF pSgBuf); 189 189 190 /** 191 * Send data from multiple buffers to a socket. 192 * 193 * This is convenience wrapper around the RTSocketSgWrite and RTSgBufInit calls 194 * for lazy coders. The "L" in the function name is short for "list" just like 195 * in the execl libc API. 196 * 197 * @returns IPRT status code. 198 * @retval VERR_INTERRUPTED if interrupted before anything was written. 199 * 200 * @param hSocket The socket handle. 201 * @param cSegs The number of data segments in the following 202 * ellipsis. 203 * @param ... Pairs of buffer pointers (void const *) and buffer 204 * sizes (size_t). Make 101% sure the pointer is 205 * really size_t. 206 */ 207 RTDECL(int) RTSocketSgWriteL(RTSOCKET hSocket, size_t cSegs, ...); 208 209 /** 210 * Send data from multiple buffers to a socket. 211 * 212 * This is convenience wrapper around the RTSocketSgWrite and RTSgBufInit calls 213 * for lazy coders. The "L" in the function name is short for "list" just like 214 * in the execl libc API. 215 * 216 * @returns IPRT status code. 217 * @retval VERR_INTERRUPTED if interrupted before anything was written. 218 * 219 * @param hSocket The socket handle. 220 * @param cSegs The number of data segments in the following 221 * argument list. 222 * @param va Pairs of buffer pointers (void const *) and buffer 223 * sizes (size_t). Make 101% sure the pointer is 224 * really size_t. 225 */ 226 RTDECL(int) RTSocketSgWriteLV(RTSOCKET hSocket, size_t cSegs, va_list va); 227 190 228 /** @} */ 191 229 RT_C_DECLS_END -
trunk/include/iprt/tcp.h
r30270 r30468 292 292 RTR3DECL(int) RTTcpSgWrite(RTSOCKET Sock, PCRTSGBUF pSgBuf); 293 293 294 295 /** 296 * Send data from multiple buffers to a socket. 297 * 298 * This is convenience wrapper around the RTSocketSgWrite and RTSgBufInit calls 299 * for lazy coders. The "L" in the function name is short for "list" just like 300 * in the execl libc API. 301 * 302 * @returns IPRT status code. 303 * @retval VERR_INTERRUPTED if interrupted before anything was written. 304 * 305 * @param hSocket The socket handle. 306 * @param cSegs The number of data segments in the following 307 * ellipsis. 308 * @param ... Pairs of buffer pointers (void const *) and buffer 309 * sizes (size_t). Make 101% sure the pointer is 310 * really size_t. 311 */ 312 RTR3DECL(int) RTTcpSgWriteL(RTSOCKET hSocket, size_t cSegs, ...); 313 314 /** 315 * Send data from multiple buffers to a socket. 316 * 317 * This is convenience wrapper around the RTSocketSgWrite and RTSgBufInit calls 318 * for lazy coders. The "L" in the function name is short for "list" just like 319 * in the execl libc API. 320 * 321 * @returns IPRT status code. 322 * @retval VERR_INTERRUPTED if interrupted before anything was written. 323 * 324 * @param hSocket The socket handle. 325 * @param cSegs The number of data segments in the following 326 * argument list. 327 * @param va Pairs of buffer pointers (void const *) and buffer 328 * sizes (size_t). Make 101% sure the pointer is 329 * really size_t. 330 */ 331 RTR3DECL(int) RTTcpSgWriteLV(RTSOCKET hSocket, size_t cSegs, va_list va); 332 294 333 /** @} */ 295 334 RT_C_DECLS_END -
trunk/src/VBox/Devices/Storage/DrvVD.cpp
r30309 r30468 740 740 /* This is an extremely crude emulation, however it's good enough 741 741 * for our iSCSI code. INIP has no sendmsg(). */ 742 for (unsigned i = 0; i < pSgBuf->cSeg ; i++)743 { 744 rc = drvvdINIPWrite(Sock, pSgBuf->p caSeg[i].pvSeg,745 pSgBuf->p caSeg[i].cbSeg);742 for (unsigned i = 0; i < pSgBuf->cSegs; i++) 743 { 744 rc = drvvdINIPWrite(Sock, pSgBuf->paSegs[i].pvSeg, 745 pSgBuf->paSegs[i].cbSeg); 746 746 if (RT_FAILURE(rc)) 747 747 break; -
trunk/src/VBox/Runtime/common/misc/sg.cpp
r28800 r30468 37 37 { 38 38 size_t cbData = RT_MIN(*pcbData, pSgBuf->cbSegLeft); 39 void *pvBuf = pSgBuf->pvSegCur r;39 void *pvBuf = pSgBuf->pvSegCur; 40 40 41 41 pSgBuf->cbSegLeft -= cbData; … … 46 46 pSgBuf->idxSeg++; 47 47 48 if (RT_UNLIKELY(pSgBuf->idxSeg == pSgBuf->cSeg ))48 if (RT_UNLIKELY(pSgBuf->idxSeg == pSgBuf->cSegs)) 49 49 { 50 50 pSgBuf->cbSegLeft = 0; 51 pSgBuf->pvSegCur r= NULL;51 pSgBuf->pvSegCur = NULL; 52 52 } 53 53 else 54 54 { 55 pSgBuf->pvSegCur r = pSgBuf->pcaSeg[pSgBuf->idxSeg].pvSeg;56 pSgBuf->cbSegLeft = pSgBuf->p caSeg[pSgBuf->idxSeg].cbSeg;55 pSgBuf->pvSegCur = pSgBuf->paSegs[pSgBuf->idxSeg].pvSeg; 56 pSgBuf->cbSegLeft = pSgBuf->paSegs[pSgBuf->idxSeg].cbSeg; 57 57 } 58 58 … … 60 60 } 61 61 else 62 pSgBuf->pvSegCur r = (void *)((uintptr_t)pSgBuf->pvSegCurr + cbData);62 pSgBuf->pvSegCur = (uint8_t *)pSgBuf->pvSegCur + cbData; 63 63 64 64 return pvBuf; … … 66 66 67 67 68 RTDECL(void) RTSgBufInit(PRTSGBUF pSgBuf, PCRTSGSEG pcaSeg, unsigned cSeg) 68 RTDECL(void) RTSgBufInit(PRTSGBUF pSgBuf, PCRTSGSEG paSegs, unsigned cSegs) 69 { 70 AssertPtr(pSgBuf); 71 AssertPtr(paSegs); 72 Assert(cSegs > 0); 73 74 pSgBuf->paSegs = paSegs; 75 pSgBuf->cSegs = cSegs; 76 pSgBuf->idxSeg = 0; 77 pSgBuf->pvSegCur = paSegs[0].pvSeg; 78 pSgBuf->cbSegLeft = paSegs[0].cbSeg; 79 } 80 81 82 RTDECL(void) RTSgBufReset(PRTSGBUF pSgBuf) 69 83 { 70 84 AssertPtrReturnVoid(pSgBuf); 71 AssertPtrReturnVoid(pcaSeg); 72 AssertReturnVoid(cSeg > 0); 73 74 pSgBuf->pcaSeg = pcaSeg; 75 pSgBuf->cSeg = cSeg; 85 76 86 pSgBuf->idxSeg = 0; 77 pSgBuf->pvSegCurr = pcaSeg[0].pvSeg; 78 pSgBuf->cbSegLeft = pcaSeg[0].cbSeg; 79 } 80 81 82 RTDECL(void) RTSgBufReset(PRTSGBUF pSgBuf) 83 { 84 AssertPtrReturnVoid(pSgBuf); 85 86 pSgBuf->idxSeg = 0; 87 pSgBuf->pvSegCurr = pSgBuf->pcaSeg[0].pvSeg; 88 pSgBuf->cbSegLeft = pSgBuf->pcaSeg[0].cbSeg; 87 pSgBuf->pvSegCur = pSgBuf->paSegs[0].pvSeg; 88 pSgBuf->cbSegLeft = pSgBuf->paSegs[0].cbSeg; 89 89 } 90 90 … … 92 92 RTDECL(void) RTSgBufClone(PRTSGBUF pSgBufTo, PCRTSGBUF pSgBufFrom) 93 93 { 94 AssertPtr ReturnVoid(pSgBufTo);95 AssertPtr ReturnVoid(pSgBufFrom);96 97 pSgBufTo->p caSeg = pSgBufFrom->pcaSeg;98 pSgBufTo->cSeg = pSgBufFrom->cSeg;94 AssertPtr(pSgBufTo); 95 AssertPtr(pSgBufFrom); 96 97 pSgBufTo->paSegs = pSgBufFrom->paSegs; 98 pSgBufTo->cSegs = pSgBufFrom->cSegs; 99 99 pSgBufTo->idxSeg = pSgBufFrom->idxSeg; 100 pSgBufTo->pvSegCur r = pSgBufFrom->pvSegCurr;100 pSgBufTo->pvSegCur = pSgBufFrom->pvSegCur; 101 101 pSgBufTo->cbSegLeft = pSgBufFrom->cbSegLeft; 102 102 } -
trunk/src/VBox/Runtime/r3/socket.cpp
r30307 r30468 52 52 #include <iprt/socket.h> 53 53 54 #include <iprt/alloca.h> 54 55 #include <iprt/asm.h> 55 56 #include <iprt/assert.h> … … 586 587 AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE); 587 588 AssertPtrReturn(pSgBuf, VERR_INVALID_PARAMETER); 588 AssertReturn(pSgBuf->cSeg > 0, VERR_INVALID_PARAMETER);589 AssertReturn(pSgBuf->cSegs > 0, VERR_INVALID_PARAMETER); 589 590 AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS); 590 591 … … 592 593 * Construct message descriptor (translate pSgBuf) and send it. 593 594 */ 594 int rc = VINF_SUCCESS; 595 do 596 { 597 #ifdef RT_OS_WINDOWS 598 AssertCompileSize(WSABUF, sizeof(RTSGSEG)); 599 AssertCompileMemberSize(WSABUF, buf, RT_SIZEOFMEMB(RTSGSEG, pvSeg)); 600 601 LPWSABUF paMsg = (LPWSABUF)RTMemTmpAllocZ(pSgBuf->cSeg * sizeof(WSABUF)); 602 AssertPtrBreakStmt(paMsg, rc = VERR_NO_MEMORY); 603 for (unsigned i = 0; i < pSgBuf->cSeg; i++) 595 int rc = VERR_NO_TMP_MEMORY; 596 #ifdef RT_OS_WINDOWS 597 AssertCompileSize(WSABUF, sizeof(RTSGSEG)); 598 AssertCompileMemberSize(WSABUF, buf, RT_SIZEOFMEMB(RTSGSEG, pvSeg)); 599 600 LPWSABUF paMsg = (LPWSABUF)RTMemTmpAllocZ(pSgBuf->cSegs * sizeof(WSABUF)); 601 if (paMsg) 602 { 603 for (unsigned i = 0; i < pSgBuf->cSegs; i++) 604 604 { 605 paMsg[i].buf = (char *)pSgBuf->p caSeg[i].pvSeg;606 paMsg[i].len = (u_long)pSgBuf->p caSeg[i].cbSeg;605 paMsg[i].buf = (char *)pSgBuf->paSegs[i].pvSeg; 606 paMsg[i].len = (u_long)pSgBuf->paSegs[i].cbSeg; 607 607 } 608 608 609 609 DWORD dwSent; 610 int hrc = WSASend(pThis->hNative, paMsg, pSgBuf->cSeg , &dwSent,610 int hrc = WSASend(pThis->hNative, paMsg, pSgBuf->cSegs, &dwSent, 611 611 MSG_NOSIGNAL, NULL, NULL); 612 ssize_t cbWritten;613 612 if (!hrc) 613 rc = VINF_SUCCESS; 614 /** @todo check for incomplete writes */ 615 else 616 rc = rtSocketError(); 617 618 RTMemTmpFree(paMsg); 619 } 620 621 #else /* !RT_OS_WINDOWS */ 622 AssertCompileSize(struct iovec, sizeof(RTSGSEG)); 623 AssertCompileMemberSize(struct iovec, iov_base, RT_SIZEOFMEMB(RTSGSEG, pvSeg)); 624 AssertCompileMemberSize(struct iovec, iov_len, RT_SIZEOFMEMB(RTSGSEG, cbSeg)); 625 626 struct iovec *paMsg = (struct iovec *)RTMemTmpAllocZ(pSgBuf->cSegs * sizeof(struct iovec)); 627 if (paMsg) 628 { 629 for (unsigned i = 0; i < pSgBuf->cSegs; i++) 614 630 { 615 /* avoid overflowing ssize_t, the exact value isn't important */616 cbWritten = RT_MIN(dwSent, INT_MAX);631 paMsg[i].iov_base = pSgBuf->paSegs[i].pvSeg; 632 paMsg[i].iov_len = pSgBuf->paSegs[i].cbSeg; 617 633 } 618 else619 cbWritten = -1;620 #else621 AssertCompileSize(struct iovec, sizeof(RTSGSEG));622 AssertCompileMemberSize(struct iovec, iov_base, RT_SIZEOFMEMB(RTSGSEG, pvSeg));623 AssertCompileMemberSize(struct iovec, iov_len, RT_SIZEOFMEMB(RTSGSEG, cbSeg));624 625 struct iovec *paMsg = (struct iovec *)RTMemTmpAllocZ(pSgBuf->cSeg * sizeof(struct iovec));626 AssertPtrBreakStmt(paMsg, rc = VERR_NO_MEMORY);627 for (unsigned i = 0; i < pSgBuf->cSeg; i++)628 {629 paMsg[i].iov_base = pSgBuf->pcaSeg[i].pvSeg;630 paMsg[i].iov_len = pSgBuf->pcaSeg[i].cbSeg;631 }632 634 633 635 struct msghdr msgHdr; 634 memset(&msgHdr, '\0', sizeof(msgHdr));635 msgHdr.msg_iov = paMsg;636 msgHdr.msg_iovlen = pSgBuf->cSeg ;636 RT_ZERO(msgHdr); 637 msgHdr.msg_iov = paMsg; 638 msgHdr.msg_iovlen = pSgBuf->cSegs; 637 639 ssize_t cbWritten = sendmsg(pThis->hNative, &msgHdr, MSG_NOSIGNAL); 638 #endif639 640 RTMemTmpFree(paMsg);641 640 if (RT_LIKELY(cbWritten >= 0)) 642 641 rc = VINF_SUCCESS; 642 /** @todo check for incomplete writes */ 643 643 else 644 644 rc = rtSocketError(); 645 } while (0); 645 646 RTMemTmpFree(paMsg); 647 } 648 #endif /* !RT_OS_WINDOWS */ 646 649 647 650 rtSocketUnlock(pThis); 648 651 return rc; 652 } 653 654 655 RTDECL(int) RTSocketSgWriteL(RTSOCKET hSocket, size_t cSegs, ...) 656 { 657 va_list va; 658 va_start(va, cSegs); 659 int rc = RTSocketSgWriteLV(hSocket, cSegs, va); 660 va_end(va); 661 return rc; 662 } 663 664 665 RTDECL(int) RTSocketSgWriteLV(RTSOCKET hSocket, size_t cSegs, va_list va) 666 { 667 /* 668 * Set up a S/G segment array + buffer on the stack and pass it 669 * on to RTSocketSgWrite. 670 */ 671 Assert(cSegs <= 16); 672 PRTSGSEG paSegs = (PRTSGSEG)alloca(cSegs * sizeof(RTSGSEG)); 673 AssertReturn(paSegs, VERR_NO_TMP_MEMORY); 674 for (size_t i = 0; i < cSegs; i++) 675 { 676 paSegs[i].pvSeg = va_arg(va, void *); 677 paSegs[i].cbSeg = va_arg(va, size_t); 678 } 679 680 RTSGBUF SgBuf; 681 RTSgBufInit(&SgBuf, paSegs, cSegs); 682 return RTSocketSgWrite(hSocket, &SgBuf); 649 683 } 650 684 -
trunk/src/VBox/Runtime/r3/tcp.cpp
r30270 r30468 1020 1020 } 1021 1021 1022 1023 RTR3DECL(int) RTTcpSgWriteL(RTSOCKET hSocket, size_t cSegs, ...) 1024 { 1025 va_list va; 1026 va_start(va, cSegs); 1027 int rc = RTSocketSgWriteLV(hSocket, cSegs, va); 1028 va_end(va); 1029 return rc; 1030 } 1031 1032 1033 RTR3DECL(int) RTTcpSgWriteLV(RTSOCKET hSocket, size_t cSegs, va_list va) 1034 { 1035 return RTSocketSgWriteLV(hSocket, cSegs, va); 1036 } 1037
Note:
See TracChangeset
for help on using the changeset viewer.