VirtualBox

Changeset 30306 in vbox for trunk/src


Ignore:
Timestamp:
Jun 18, 2010 11:35:06 AM (15 years ago)
Author:
vboxsync
Message:

Runtime/socket: Windows does have a good enough sendmsg() equivalent with an unexpected name

File:
1 edited

Legend:

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

    r30275 r30306  
    596596    {
    597597#ifdef RT_OS_WINDOWS
    598 # if 0 /* WSASendMsg is Vista+, so not an option */
    599598        AssertCompileSize(WSABUF, sizeof(RTSGSEG));
    600599        AssertCompileMemberSize(WSABUF, buf, RT_SIZEOFMEMB(RTSGSEG, pvSeg));
    601600        AssertCompileMemberSize(WSABUF, len, RT_SIZEOFMEMB(RTSGSEG, cbSeg));
    602601
    603         LPWSABUF *paMsg = (LPWSABUF)RTMemTmpAllocZ(pSgBuf->cSeg * sizeof(WSABUF));
     602        LPWSABUF paMsg = (LPWSABUF)RTMemTmpAllocZ(pSgBuf->cSeg * sizeof(WSABUF));
    604603        AssertPtrBreakStmt(paMsg, rc = VERR_NO_MEMORY);
    605604        for (unsigned i = 0; i < pSgBuf->cSeg; i++)
    606605        {
    607             paMsg[i].buf = pSgBuf->pcaSeg[i].pvSeg;
     606            paMsg[i].buf = (char *)pSgBuf->pcaSeg[i].pvSeg;
    608607            paMsg[i].len = pSgBuf->pcaSeg[i].cbSeg;
    609608        }
    610609
    611         WSAMSG msgHdr;
    612610        DWORD dwSent;
    613         memset(&msgHdr, '\0', sizeof(msgHdr));
    614         msgHdr.lpBuffers = paMsg;
    615         msgHdr.dwBufferCount = pSgBuf->cSeg;
    616         int hrc = WSASendMsg(pThis->hNative, &msgHdr, MSG_NOSIGNAL, &dwSent,
    617                              NULL, NULL);
     611        int hrc = WSASend(pThis->hNative, paMsg, pSgBuf->cSeg, &dwSent,
     612                          MSG_NOSIGNAL, NULL, NULL);
    618613        ssize_t cbWritten;
    619614        if (!hrc)
     
    624619        else
    625620            cbWritten = -1;
    626         RTMemTmpFree(paMsg);
    627 # else /* 1 */
    628         /* Portable but inefficient: copy everything to a single buffer and
    629          * use send(). Annoying that WSASendMsg() is so "new". */
    630         int cbBuf = 0;
    631         for (unsigned i = 0; i < pSgBuf->cSeg; i++)
    632         {
    633             cbBuf += (int)pSgBuf->pcaSeg[i].cbSeg;
    634             AssertBreakStmt(cbBuf, rc = VERR_BUFFER_OVERFLOW);
    635         }
    636 
    637         void *pBuf = RTMemTmpAlloc(cbBuf);
    638         AssertPtrBreakStmt(pBuf, rc = VERR_NO_MEMORY);
    639         char *p = (char *)pBuf;
    640         for (unsigned i = 0; i < pSgBuf->cSeg; i++)
    641         {
    642             memcpy(p, pSgBuf->pcaSeg[i].pvSeg, pSgBuf->pcaSeg[i].cbSeg);
    643             p += (int)pSgBuf->pcaSeg[i].cbSeg;
    644         }
    645 
    646         ssize_t cbWritten = send(pThis->hNative, (const char *)pBuf, cbBuf, MSG_NOSIGNAL);
    647         RTMemTmpFree(pBuf);
    648 # endif /* 1 */
    649621#else
    650622        AssertCompileSize(struct iovec, sizeof(RTSGSEG));
     
    665637        msgHdr.msg_iovlen = pSgBuf->cSeg;
    666638        ssize_t cbWritten = sendmsg(pThis->hNative, &msgHdr, MSG_NOSIGNAL);
     639#endif
     640
    667641        RTMemTmpFree(paMsg);
    668 #endif
    669 
    670642        if (RT_LIKELY(cbWritten >= 0))
    671643            rc = VINF_SUCCESS;
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