VirtualBox

Changeset 106608 in vbox for trunk/src


Ignore:
Timestamp:
Oct 23, 2024 4:20:54 AM (5 weeks ago)
Author:
vboxsync
Message:

Devices/Network: switched back to poll paradigm for windows and non-windows. bugref:10268

Location:
trunk/src/VBox/Devices
Files:
2 deleted
2 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Makefile.kmk

    r106345 r106608  
    780780        Network/DrvNATlibslirp.cpp
    781781  VBoxDD_SOURCES.win += \
    782         Network/RTWinPollLibslirp.cpp
     782        Network/RTWinSocketPair.cpp
    783783  Network/DrvNATlibslirp.cpp_INCS   += \
    784784        $(PATH_ROOT)/src/libs/libslirp-4.8.0/src \
  • trunk/src/VBox/Devices/Network/DrvNATlibslirp.cpp

    r106273 r106608  
    3737# include <iprt/win/winsock2.h>
    3838# include <iprt/win/ws2tcpip.h>
     39# include "winutils.h"
     40# define inet_aton(x, y) inet_pton(2, x, y)
     41# define AF_INET6 23
    3942#endif
    4043
     
    5255# include <errno.h>
    5356#endif
     57
    5458#ifdef RT_OS_FREEBSD
    5559# include <netinet/in.h>
    5660#endif
    5761
    58 #ifdef RT_OS_WINDOWS
    59 # include <iprt/win/winsock2.h>
    60 # include "winpoll.h"
    61 # define inet_aton(x, y) inet_pton(2, x, y)
    62 # define AF_INET6 23
    63 #endif
    64 
     62#include <iprt/asm.h>
    6563#include <iprt/assert.h>
    6664#include <iprt/critsect.h>
     
    221219    /** The read end of the control pipe. */
    222220    RTPIPE                  hPipeRead;
    223 # if HC_ARCH_BITS == 32
    224     uint32_t                u32Padding;
    225 # endif
    226221#else
    227     /** for external notification */
    228     HANDLE                  hWakeupEvent;
     222    /* wakeup socket pair for NAT thread */
     223    SOCKET                  pWakeupSockPair[2];
    229224#endif
     225    /* count of bytes sent to notify NAT thread */
     226    volatile uint64_t       cbWakeupNotifs;
    230227
    231228#define DRV_PROFILE_COUNTER(name, dsc)     STAMPROFILE Stat ## name
     
    603600    size_t cbIgnored;
    604601    rc = RTPipeWrite(pThis->hPipeWrite, "", 1, &cbIgnored);
     602    if (RT_SUCCESS(rc))
     603    {
     604        /* Count how many bites we send down the socket */
     605        ASMAtomicIncU64(&pThis->cbWakeupNotifs);
     606    }
    605607#else
    606     /* kick WSAWaitForMultipleEvents */
    607     rc = WSASetEvent(pThis->hWakeupEvent);
     608    int cbWritten = send(pThis->pWakeupSockPair[0], "", 1, NULL);
     609    if (cbWritten == SOCKET_ERROR)
     610    {
     611        int error = WSAGetLastError();
     612        Log4(("Notify NAT Thread Error %d\n", error));
     613    }
     614    else
     615    {
     616        /* Count how many bites we send down the socket */
     617        ASMAtomicIncU64(&pThis->cbWakeupNotifs);
     618    }
    608619#endif
    609620    AssertRC(rc);
     
    704715{
    705716    PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
    706 #ifdef VBOX_NAT_DELAY_HACK
    707     unsigned int cBreak = 0;
    708 #endif
    709 #ifndef RT_OS_WINDOWS
     717#ifdef RT_OS_WINDOWS
     718    drvNAT_AddPollCb(pThis->pWakeupSockPair[1], SLIRP_POLL_IN | SLIRP_POLL_HUP, pThis);
     719    pThis->pNATState->polls[0].fd = pThis->pWakeupSockPair[1];
     720#else
    710721    unsigned int cPollNegRet = 0;
    711722    drvNAT_AddPollCb(RTPipeToNative(pThis->hPipeRead), SLIRP_POLL_IN | SLIRP_POLL_HUP, pThis);
     
    764775             * device's thread sends before we've entered multiplex,
    765776             * so to avoid false alarm drain pipe here to the very end
    766              *
    767              * @todo: Probably we should counter drvNATSend to count how
    768              * deep pipe has been filed before drain.
    769              *
    770777             */
    771             /** @todo XXX: Make it reading exactly we need to drain the
    772              * pipe.*/
    773778            char ch;
    774779            size_t cbRead;
    775             RTPipeRead(pThis->hPipeRead, &ch, 1, &cbRead);
     780            uint64_t cbWakeupNotifs = ASMAtomicReadU64(&pThis->cbWakeupNotifs);
     781            RTPipeRead(pThis->hPipeRead, &ch, cbWakeupNotifs, &cbRead);
     782            ASMAtomicSubU64(&pThis->cbWakeupNotifs, cbRead);
    776783        }
    777784
     
    782789#else /* RT_OS_WINDOWS */
    783790        uint32_t msTimeout = DRVNAT_DEFAULT_TIMEOUT;
    784         pThis->pNATState->nsock = 0;
     791        pThis->pNATState->nsock = 1;
    785792        slirp_pollfds_fill(pThis->pNATState->pSlirp, &msTimeout, drvNAT_AddPollCb /* SlirpAddPollCb */, pThis /* opaque */);
    786793        drvNAT_UpdateTimeout(&msTimeout, pThis);
    787794
    788         int cChangedFDs = 0;
    789         int vrc = RTWinPoll(pThis->pNATState->polls, pThis->pNATState->nsock, msTimeout, &cChangedFDs, pThis->hWakeupEvent);
    790         if (vrc != VINF_SUCCESS)
    791         {
    792             if (vrc != VERR_TIMEOUT)
    793                 LogRel(("NAT: RTWinPoll returned vrc=%Rrc (cChangedFDs=%d)\n", vrc, cChangedFDs));
     795        int cChangedFDs = WSAPoll(pThis->pNATState->polls, pThis->pNATState->nsock, msTimeout /* timeout */);
     796        int error = WSAGetLastError();
     797        if (cChangedFDs == SOCKET_ERROR)
     798        {
     799            LogRel(("NAT: RTWinPoll returned error=%Rrc (cChangedFDs=%d)\n", error, cChangedFDs));
    794800            Log4(("NAT: NSOCK = %d\n", pThis->pNATState->nsock));
     801        }
     802
     803        if (pThis->pNATState->polls[0].revents & (POLLIN))
     804        {
     805            /* drain the pipe
     806             *
     807             * Note! drvNATSend decoupled so we don't know how many times
     808             * device's thread sends before we've entered multiplex,
     809             * so to avoid false alarm drain pipe here to the very end
     810             */
     811            char ch;
     812            size_t cbRead;
     813            uint64_t cbWakeupNotifs = ASMAtomicReadU64(&pThis->cbWakeupNotifs);
     814            cbRead = recv(pThis->pWakeupSockPair[1], &ch, cbWakeupNotifs, NULL);
     815            ASMAtomicSubU64(&pThis->cbWakeupNotifs, cbRead);
    795816        }
    796817
     
    809830        RTReqQueueProcess(pThis->hSlirpReqQueue, 0);
    810831        drvNAT_CheckTimeout(pThis);
    811 # ifdef VBOX_NAT_DELAY_HACK
    812         if (cBreak++ > 128)
    813         {
    814             cBreak = 0;
    815             RTThreadSleep(2);
    816         }
    817 # endif
    818832#endif /* RT_OS_WINDOWS */
    819833    }
     
    17031717    AssertRCReturn(rc, rc);
    17041718#else
    1705     // Create the wakeup event handle.
    1706     pThis->hWakeupEvent = NULL;
    1707     pThis->hWakeupEvent = CreateEvent(NULL, FALSE, FALSE, NULL); /* auto-reset event */
    1708     Assert(pThis->hWakeupEvent != NULL);
     1719    // Create the wakeup socket pair.
     1720    pThis->pWakeupSockPair[0] = NULL;
     1721    pThis->pWakeupSockPair[1] = NULL;
     1722
     1723    /* idx=0 is write, idx=1 is read */
     1724    rc = RTWinSocketPair(AF_INET, SOCK_DGRAM, 0, pThis->pWakeupSockPair);
     1725    AssertRCReturn(rc, rc);
    17091726#endif
     1727    /* initalize the notifier counter */
     1728    pThis->cbWakeupNotifs = 0;
    17101729
    17111730    rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pSlirpThread, pThis, drvNATAsyncIoThread,
  • trunk/src/VBox/Devices/Network/winutils.h

    r106585 r106608  
    2626 */
    2727
    28 #ifndef VBOX_INCLUDED_SRC_NAT_winutils_h
    29 #define VBOX_INCLUDED_SRC_NAT_winutils_h
     28#ifndef VBOX_INCLUDED_SRC_Network_winutils_h
     29#define VBOX_INCLUDED_SRC_Network_winutils_h
    3030#ifndef RT_WITHOUT_PRAGMA_ONCE
    3131# pragma once
     
    218218}
    219219
    220 #endif /* !VBOX_INCLUDED_SRC_NAT_winutils_h */
     220#endif /* !VBOX_INCLUDED_SRC_Network_winutils_h */
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