VirtualBox

Ignore:
Timestamp:
Apr 9, 2010 2:20:16 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
59875
Message:

NAT: Use poll/WSAWaitForMultipleEvents timeouts instead of timers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/NAT/VBoxNetNAT.cpp

    r28025 r28146  
    5151#include <VBox/intnet.h>
    5252#include <VBox/intnetinline.h>
     53#include <VBox/pdmnetinline.h>
    5354#include <VBox/vmm.h>
    5455#include <VBox/version.h>
     
    303304                    }
    304305
     306                    uint8_t abHdrScratch[256];
    305307                    uint32_t const cSegs = PDMNetGsoCalcSegmentCount(pGso, cbFrame - sizeof(*pGso));
    306308                    for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
     
    308310                        uint32_t cbSegFrame;
    309311                        void  *pvSegFrame = PDMNetGsoCarveSegmentQD(pGso, (uint8_t *)(pGso + 1), cbFrame, abHdrScratch,
    310                                                                     &cbSegFrame);
     312                                                                    iSeg, cSegs, &cbSegFrame);
    311313                        m = slirp_ext_m_get(g_pNAT->m_pNATState, cbFrame, &pvSlirpFrame, &cbIgnored);
    312314                        if (!m)
     
    318320
    319321                        rc = RTReqCallEx(m_pReqQueue, NULL /*ppReq*/, 0 /*cMillies*/, RTREQFLAGS_VOID | RTREQFLAGS_NO_WAIT,
    320                                          (PFNRT)SendWorker, 2, m, cbSubFrame);
     322                                         (PFNRT)SendWorker, 2, m, cbSegFrame);
    321323                        AssertReleaseRC(rc);
    322324                    }
     
    463465    VBoxNetNAT *pThis = (VBoxNetNAT *)pvUser;
    464466    int     nFDs = -1;
    465     unsigned int ms;
    466467#ifdef RT_OS_WINDOWS
    467     DWORD   event;
    468     HANDLE  *phEvents;
    469     unsigned int cBreak = 0;
     468    HANDLE *pahEvents = slirp_get_events(pThis->m_pNATState);
    470469#else /* RT_OS_WINDOWS */
    471     struct pollfd *polls = NULL;
    472470    unsigned int cPollNegRet = 0;
    473471#endif /* !RT_OS_WINDOWS */
    474472
    475473    LogFlow(("drvNATAsyncIoThread: pThis=%p\n", pThis));
    476 
    477 
    478 #ifdef RT_OS_WINDOWS
    479     phEvents = slirp_get_events(pThis->m_pNATState);
    480 #endif /* RT_OS_WINDOWS */
    481474
    482475    /*
     
    485478    for(;;)
    486479    {
    487         nFDs = -1;
    488 
    489480        /*
    490481         * To prevent concurent execution of sending/receving threads
     
    492483#ifndef RT_OS_WINDOWS
    493484        nFDs = slirp_get_nsock(pThis->m_pNATState);
    494         polls = NULL;
    495485        /* allocation for all sockets + Management pipe */
    496         polls = (struct pollfd *)RTMemAlloc((1 + nFDs) * sizeof(struct pollfd) + sizeof(uint32_t));
     486        struct pollfd *polls = (struct pollfd *)RTMemAlloc((1 + nFDs) * sizeof(struct pollfd) + sizeof(uint32_t));
    497487        if (polls == NULL)
    498488            return VERR_NO_MEMORY;
     
    500490        /* don't pass the managemant pipe */
    501491        slirp_select_fill(pThis->m_pNATState, &nFDs, &polls[1]);
    502         ms = slirp_get_timeout_ms(pThis->m_pNATState);
     492        unsigned int cMsTimeout = slirp_get_timeout_ms(pThis->m_pNATState);
    503493
    504494        polls[0].fd = pThis->m_PipeRead;
     
    507497        polls[0].revents = 0;
    508498
    509         int cChangedFDs = poll(polls, nFDs + 1, -1);
     499        int cChangedFDs = poll(polls, nFDs + 1, cMsTimeout);
    510500        if (cChangedFDs < 0)
    511501        {
     
    548538        RTReqProcess(pThis->m_pReqQueue, 0);
    549539        RTMemFree(polls);
     540
    550541#else /* RT_OS_WINDOWS */
     542        nFDs = -1;
    551543        slirp_select_fill(pThis->m_pNATState, &nFDs);
    552         event = WSAWaitForMultipleEvents(nFDs, phEvents, FALSE, WSA_INFINITE, FALSE);
    553         if (   (event < WSA_WAIT_EVENT_0 || event > WSA_WAIT_EVENT_0 + nFDs - 1)
    554             && event != WSA_WAIT_TIMEOUT)
     544        DWORD dwEvent = WSAWaitForMultipleEvents(nFDs, pahEvents, FALSE,
     545                                                 slirp_get_timeout_ms(pThis->m_pNATState),
     546                                                 FALSE);
     547        if (   (dwEvent < WSA_WAIT_EVENT_0 || dwEvent > WSA_WAIT_EVENT_0 + nFDs - 1)
     548            && dwEvent != WSA_WAIT_TIMEOUT)
    555549        {
    556550            int error = WSAGetLastError();
    557             LogRel(("NAT: WSAWaitForMultipleEvents returned %d (error %d)\n", event, error));
     551            LogRel(("NAT: WSAWaitForMultipleEvents returned %d (error %d)\n", dwEvent, error));
    558552            RTAssertReleasePanic();
    559553        }
    560554
    561         if (event == WSA_WAIT_TIMEOUT)
     555        if (dwEvent == WSA_WAIT_TIMEOUT)
    562556        {
    563557            /* only check for slow/fast timers */
     
    567561
    568562        /* poll the sockets in any case */
    569         slirp_select_poll(pThis->m_pNATState, /* fTimeout=*/false, /* fIcmp=*/(event == WSA_WAIT_EVENT_0));
     563        slirp_select_poll(pThis->m_pNATState, /* fTimeout=*/false, /* fIcmp=*/(dwEvent == WSA_WAIT_EVENT_0));
    570564        /* process _all_ outstanding requests but don't wait */
    571565        RTReqProcess(pThis->m_pReqQueue, 0);
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