VirtualBox

Ignore:
Timestamp:
Aug 8, 2010 12:51:20 PM (14 years ago)
Author:
vboxsync
Message:

Runtime/socket: Make use of the new method to convert the S/G buffer to another type (only non blocking version for now to not risk breaking something else)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/socket.cpp

    r31212 r31450  
    873873        return rc;
    874874
    875     /*
    876      * Construct message descriptor (translate pSgBuf) and send it.
    877      */
     875    unsigned cSegsToSend = 0;
    878876    rc = VERR_NO_TMP_MEMORY;
    879877#ifdef RT_OS_WINDOWS
    880     AssertCompileSize(WSABUF, sizeof(RTSGSEG));
    881     AssertCompileMemberSize(WSABUF, buf, RT_SIZEOFMEMB(RTSGSEG, pvSeg));
    882 
    883     LPWSABUF paMsg = (LPWSABUF)RTMemTmpAllocZ(pSgBuf->cSegs * sizeof(WSABUF));
     878    LPWSABUF paMsg = NULL;
     879
     880    RTSgBufMapToNative(paMsg, pSgBuf, WSABUF, buf, char *, len, u_long, cSegsToSend);
    884881    if (paMsg)
    885882    {
    886         for (unsigned i = 0; i < pSgBuf->cSegs; i++)
    887         {
    888             paMsg[i].buf = (char *)pSgBuf->paSegs[i].pvSeg;
    889             paMsg[i].len = (u_long)pSgBuf->paSegs[i].cbSeg;
    890         }
    891 
    892883        DWORD dwSent = 0;
    893         int hrc = WSASend(pThis->hNative, paMsg, pSgBuf->cSegs, &dwSent,
     884        int hrc = WSASend(pThis->hNative, paMsg, cSegsToSend, &dwSent,
    894885                          MSG_NOSIGNAL, NULL, NULL);
    895886        if (!hrc)
    896887            rc = VINF_SUCCESS;
    897 /** @todo check for incomplete writes */
    898888        else
    899889            rc = rtSocketError();
     
    905895
    906896#else  /* !RT_OS_WINDOWS */
    907     AssertCompileSize(struct iovec, sizeof(RTSGSEG));
    908     AssertCompileMemberSize(struct iovec, iov_base, RT_SIZEOFMEMB(RTSGSEG, pvSeg));
    909     AssertCompileMemberSize(struct iovec, iov_len,  RT_SIZEOFMEMB(RTSGSEG, cbSeg));
    910 
    911     struct iovec *paMsg = (struct iovec *)RTMemTmpAllocZ(pSgBuf->cSegs * sizeof(struct iovec));
     897    struct iovec *paMsg = NULL;
     898
     899    RTSgBufMapToNative(paMsg, pSgBuf, struct iovec, iov_base, void *, iov_len, size_t, cSegsToSend);
    912900    if (paMsg)
    913901    {
    914         for (unsigned i = 0; i < pSgBuf->cSegs; i++)
    915         {
    916             paMsg[i].iov_base = pSgBuf->paSegs[i].pvSeg;
    917             paMsg[i].iov_len  = pSgBuf->paSegs[i].cbSeg;
    918         }
    919 
    920902        struct msghdr msgHdr;
    921903        RT_ZERO(msgHdr);
    922904        msgHdr.msg_iov    = paMsg;
    923         msgHdr.msg_iovlen = pSgBuf->cSegs;
     905        msgHdr.msg_iovlen = cSegsToSend;
    924906        ssize_t cbWritten = sendmsg(pThis->hNative, &msgHdr, MSG_NOSIGNAL);
    925907        if (RT_LIKELY(cbWritten >= 0))
     908        {
    926909            rc = VINF_SUCCESS;
    927 /** @todo check for incomplete writes */
     910            *pcbWritten = cbWritten;
     911        }
    928912        else
    929913            rc = rtSocketError();
    930 
    931         *pcbWritten = cbWritten;
    932914
    933915        RTMemTmpFree(paMsg);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette