VirtualBox

Changeset 28146 in vbox


Ignore:
Timestamp:
Apr 9, 2010 2:20:16 PM (15 years ago)
Author:
vboxsync
Message:

NAT: Use poll/WSAWaitForMultipleEvents timeouts instead of timers.

Location:
trunk/src/VBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/DrvNAT.cpp

    r28143 r28146  
    675675    int     ms;
    676676#ifdef RT_OS_WINDOWS
    677     DWORD   event;
    678     HANDLE  *phEvents;
     677    HANDLE  *phEvents = slirp_get_events(pThis->pNATState);
    679678    unsigned int cBreak = 0;
    680679#else /* RT_OS_WINDOWS */
    681     struct pollfd *polls = NULL;
    682680    unsigned int cPollNegRet = 0;
    683681#endif /* !RT_OS_WINDOWS */
     
    687685    if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
    688686        return VINF_SUCCESS;
    689 
    690 #ifdef RT_OS_WINDOWS
    691     phEvents = slirp_get_events(pThis->pNATState);
    692 #endif /* RT_OS_WINDOWS */
    693687
    694688    /*
     
    697691    while (pThread->enmState == PDMTHREADSTATE_RUNNING)
    698692    {
    699         nFDs = -1;
    700693        /*
    701694         * To prevent concurent execution of sending/receving threads
     
    703696#ifndef RT_OS_WINDOWS
    704697        nFDs = slirp_get_nsock(pThis->pNATState);
    705         polls = NULL;
    706698        /* allocation for all sockets + Management pipe */
    707         polls = (struct pollfd *)RTMemAlloc((1 + nFDs) * sizeof(struct pollfd) + sizeof(uint32_t));
     699        struct pollfd *polls = (struct pollfd *)RTMemAlloc((1 + nFDs) * sizeof(struct pollfd) + sizeof(uint32_t));
    708700        if (polls == NULL)
    709701            return VERR_NO_MEMORY;
     
    711703        /* don't pass the managemant pipe */
    712704        slirp_select_fill(pThis->pNATState, &nFDs, &polls[1]);
    713 #if 0
    714         ms = slirp_get_timeout_ms(pThis->pNATState);
    715 #else
    716         ms = 0;
    717 #endif
    718705
    719706        polls[0].fd = pThis->PipeRead;
     
    722709        polls[0].revents = 0;
    723710
    724         int cChangedFDs = poll(polls, nFDs + 1, ms ? ms : -1);
     711        int cChangedFDs = poll(polls, nFDs + 1, slirp_get_timeout_ms(pThis->pNATState));
    725712        if (cChangedFDs < 0)
    726713        {
     
    765752        RTReqProcess(pThis->pSlirpReqQueue, 0);
    766753        RTMemFree(polls);
     754
    767755#else /* RT_OS_WINDOWS */
     756        nFDs = -1;
    768757        slirp_select_fill(pThis->pNATState, &nFDs);
    769 #if 0
    770         ms = slirp_get_timeout_ms(pThis->pNATState);
    771 #else
    772         ms = 0;
    773 #endif
    774         struct timeval tv = { 0, ms*1000 };
    775         event = WSAWaitForMultipleEvents(nFDs, phEvents, FALSE, ms ? ms : WSA_INFINITE, FALSE);
    776         if (   (event < WSA_WAIT_EVENT_0 || event > WSA_WAIT_EVENT_0 + nFDs - 1)
    777             && event != WSA_WAIT_TIMEOUT)
     758        DWORD dwEvent = WSAWaitForMultipleEvents(nFDs, phEvents, FALSE,
     759                                                 slirp_get_timeout_ms(pThis->pNATState),
     760                                                 FALSE);
     761        if (   (dwEvent < WSA_WAIT_EVENT_0 || dwEvent > WSA_WAIT_EVENT_0 + nFDs - 1)
     762            && dwEvent != WSA_WAIT_TIMEOUT)
    778763        {
    779764            int error = WSAGetLastError();
    780             LogRel(("NAT: WSAWaitForMultipleEvents returned %d (error %d)\n", event, error));
     765            LogRel(("NAT: WSAWaitForMultipleEvents returned %d (error %d)\n", dwEvent, error));
    781766            RTAssertPanic();
    782767        }
    783768
    784         if (event == WSA_WAIT_TIMEOUT)
     769        if (dwEvent == WSA_WAIT_TIMEOUT)
    785770        {
    786771            /* only check for slow/fast timers */
     
    790775        /* poll the sockets in any case */
    791776        Log2(("%s: poll\n", __FUNCTION__));
    792         slirp_select_poll(pThis->pNATState, /* fTimeout=*/false, /* fIcmp=*/(event == WSA_WAIT_EVENT_0));
     777        slirp_select_poll(pThis->pNATState, /* fTimeout=*/false, /* fIcmp=*/(dwEvent == WSA_WAIT_EVENT_0));
    793778        /* process _all_ outstanding requests but don't wait */
    794779        RTReqProcess(pThis->pSlirpReqQueue, 0);
     
    863848void slirp_arm_fast_timer(void *pvUser)
    864849{
     850#if 0
    865851    PDRVNAT pThis = (PDRVNAT)pvUser;
    866852    AssertPtr(pThis);
    867853    TMTimerSetMillies(pThis->pTmrFast, 2);
     854#endif
    868855}
    869856
     
    883870void slirp_arm_slow_timer(void *pvUser)
    884871{
     872#if 0
    885873    PDRVNAT pThis = (PDRVNAT)pvUser;
    886874    AssertPtr(pThis);
     875
    887876    TMTimerSetMillies(pThis->pTmrSlow, 500);
     877#endif
    888878}
    889879
  • trunk/src/VBox/Devices/Network/slirp/slirp.c

    r28141 r28146  
    18511851            return 500; /* see PR_SLOWHZ */
    18521852    }
    1853     return 0;
     1853    return 3600*1000;   /* one hour */
    18541854}
    18551855
  • 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