VirtualBox

儲存庫 vbox 的更動 49842


忽略:
時間撮記:
2013-12-9 下午01:49:46 (11 年 以前)
作者:
vboxsync
訊息:

DHCP/NAT and NAT are acting in the same manner: polling for events on main thread and waiting for packets on internal network on RECV thread. DHCP/Host-Only waits for packets on main thread.

位置:
trunk/src/VBox/NetworkServices
檔案:
修改 4 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/NetworkServices/DHCP/VBoxNetDHCP.cpp

    r49838 r49842  
    9393
    9494    int                 init();
    95     int                 run(void);
    9695    void                usage(void) { /* XXX: document options */ };
    9796    int                 parseOpt(int rc, const RTGETOPTUNION& getOptVal);
     
    283282}
    284283
    285 /**
    286  * Runs the DHCP server.
    287  *
    288  * @returns exit code + error message to stderr on failure, won't return on
    289  *          success (you must kill this process).
    290  */
    291 int VBoxNetDhcp::run(void)
    292 {
    293     doReceiveLoop();
    294     return 0;
    295 }
    296 
    297284
    298285int  VBoxNetDhcp::processUDP(void *pv, size_t cbPv)
     
    306293    {
    307294        m_uCurMsgType = uMsgType;
    308         handleDhcpMsg(uMsgType, pDhcpMsg, cbPv);
     295        {
     296            /* To avoid fight with event processing thread */
     297            VBoxNetALock(this);
     298            handleDhcpMsg(uMsgType, pDhcpMsg, cbPv);
     299        }
    309300        m_uCurMsgType = UINT8_MAX;
    310301    }
     
    565556
    566557        {
     558            VBoxNetALock(this);   
    567559            ConfigurationManager *confManager = ConfigurationManager::getConfigurationManager();
    568560            confManager->flushAddressList(RTNET_DHCP_OPT_DNS);
  • trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp

    r49839 r49842  
    1818#include "winutils.h"
    1919
     20#include <VBox/com/assert.h>
    2021#include <VBox/com/com.h>
    2122#include <VBox/com/listeners.h>
     
    2627#include <VBox/com/errorprint.h>
    2728#include <VBox/com/VirtualBox.h>
    28 #include <VBox/com/NativeEventQueue.h>
    2929
    3030#include <iprt/net.h>
     
    131131    int run();
    132132    virtual int init(void);
    133     /* @todo: when configuration would be really needed */
    134133    virtual int parseOpt(int rc, const RTGETOPTUNION& getOptVal);
    135134    /* VBoxNetNAT always needs Main */
     
    151150    uint16_t m_u16Mtu;
    152151    netif m_LwipNetIf;
    153     /* thread where we're waiting for a frames, no semaphores needed */
    154     RTTHREAD hThrIntNetRecv;
    155152
    156153    /* Our NAT network descriptor in Main */
     
    187184INTNETSEG VBoxNetLwipNAT::aXmitSeg[64];
    188185
     186/**
     187 * @note: this work on Event thread.
     188 */
    189189HRESULT VBoxNetLwipNAT::HandleEvent(VBoxEventType_T aEventType,
    190190                                                  IEvent *pEvent)
     
    515515
    516516
    517 /**
    518  * Intnet-recv thread
    519  */
    520 int VBoxNetLwipNAT::intNetThreadRecv(RTTHREAD, void *)
    521 {
    522     int rc = VINF_SUCCESS;
    523 
    524     /* 1. initialization and connection */
    525     HRESULT hrc = com::Initialize();
    526     if (FAILED(hrc))
    527         return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to initialize COM!");
    528 
    529     g_pLwipNat->doReceiveLoop();
    530     /* 3. deinitilization and termination */
    531     LogFlowFuncLeaveRC(rc);
    532     return rc;
    533 }
    534 
    535 
    536517err_t VBoxNetLwipNAT::netifLinkoutput(netif *pNetif, pbuf *pPBuf)
    537518{
     
    699680
    700681
     682/** This method executed on main thread, only at the end threr're one threads started explcitly (LWIP and later in ::run()
     683 * RECV)
     684 */
    701685int VBoxNetLwipNAT::init()
    702686{
     
    808792    }
    809793
     794    /* this starts LWIP thread */
    810795    vboxLwipCoreInitialize(VBoxNetLwipNAT::onLwipTcpIpInit, this);
    811 
    812     rc = RTThreadCreate(&g_pLwipNat->hThrIntNetRecv, /* thread handle*/
    813                         VBoxNetLwipNAT::intNetThreadRecv,  /* routine */
    814                         NULL, /* user data */
    815                         128 * _1K, /* stack size */
    816                         RTTHREADTYPE_IO, /* type */
    817                         0, /* flags, @todo: waitable ?*/
    818                         "INTNET-RECV");
    819     AssertRCReturn(rc,rc);
    820 
    821 
    822796
    823797    LogFlowFuncLeaveRC(rc);
     
    963937int VBoxNetLwipNAT::run()
    964938{
    965     /* EventQueue processing from VBoxHeadless.cpp */
    966     com::NativeEventQueue         *gEventQ = NULL;
    967     gEventQ = com::NativeEventQueue::getMainEventQueue();
    968     while(true)
    969     {
    970         /* XXX:todo: graceful termination */
    971         gEventQ->processEventQueue(0);
    972         gEventQ->processEventQueue(500);
    973     }
     939    /* Father starts receiving thread and enter event loop. */
     940    VBoxNetBaseService::run();
    974941
    975942    vboxLwipCoreFinalize(VBoxNetLwipNAT::onLwipTcpIpFini, this);
  • trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp

    r49831 r49842  
    2929#include <VBox/com/ErrorInfo.h>
    3030#include <VBox/com/errorprint.h>
    31 #include <VBox/com/EventQueue.h>
    3231#include <VBox/com/VirtualBox.h>
     32#include <VBox/com/NativeEventQueue.h>
    3333
    3434#include <iprt/alloca.h>
     
    4444#include <iprt/string.h>
    4545#include <iprt/time.h>
     46#include <iprt/thread.h>
    4647#include <iprt/mem.h>
    4748#include <iprt/message.h>
     
    8384      m_pIfBuf(NULL),
    8485      m_cVerbosity(0),
    85       m_fNeedMain(false)
     86      m_fNeedMain(false),
     87      m_EventQ(NULL),
     88      m_hThrRecv(NIL_RTTHREAD),
     89      fShutdown(false)
    8690    {
    8791        int rc = RTCritSectInit(&m_csThis);
     
    113117    /* Controls whether service will connect SVC for runtime needs */
    114118    bool                m_fNeedMain;
     119    /* Event Queue */
     120    com::NativeEventQueue  *m_EventQ;
     121
     122    /** receiving thread, used only if main is used */
     123    RTTHREAD m_hThrRecv;
     124
     125    bool fShutdown;
     126    static int recvLoop(RTTHREAD, void *);
    115127};
    116128
     
    133145
    134146
     147int VBoxNetBaseService::Data::recvLoop(RTTHREAD, void *pvUser)
     148{
     149    VBoxNetBaseService *pThis = static_cast<VBoxNetBaseService *>(pvUser);
     150
     151    HRESULT hrc = com::Initialize();
     152    AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
     153
     154    pThis->doReceiveLoop();
     155
     156    return VINF_SUCCESS;
     157}
     158
     159
    135160VBoxNetBaseService::VBoxNetBaseService(const std::string& aName, const std::string& aNetworkName):m(NULL)
    136161{
     
    149174    if (m != NULL)
    150175    {
     176        shutdown();
    151177        if (m->m_hIf != INTNET_HANDLE_INVALID)
    152178        {
     
    193219{
    194220    return m->m_fNeedMain;
     221}
     222
     223
     224int VBoxNetBaseService::run()
     225{
     226    /**
     227     * If child class need Main we start receving thread which calls doReceiveLoop and enter to event polling loop
     228     * and for the rest clients we do receiving on the current (main) thread.
     229     */
     230    if (isMainNeeded())
     231        return startReceiveThreadAndEnterEventLoop();
     232    else
     233    {
     234        doReceiveLoop();
     235        return VINF_SUCCESS;
     236    }
    195237}
    196238
     
    414456void VBoxNetBaseService::shutdown(void)
    415457{
     458    syncEnter();
     459    m->fShutdown = true;
     460    syncLeave();
    416461}
    417462
     
    678723
    679724
     725int VBoxNetBaseService::startReceiveThreadAndEnterEventLoop()
     726{
     727    AssertMsgReturn(isMainNeeded(), ("It's expected that we need Main"), VERR_INTERNAL_ERROR);
     728       
     729    /* start receiving thread */
     730    int rc = RTThreadCreate(&m->m_hThrRecv, /* thread handle*/
     731                            &VBoxNetBaseService::Data::recvLoop,  /* routine */
     732                            this, /* user data */
     733                            128 * _1K, /* stack size */
     734                            RTTHREADTYPE_IO, /* type */
     735                            0, /* flags, @todo: waitable ?*/
     736                            "RECV");
     737    AssertRCReturn(rc,rc);
     738
     739    m->m_EventQ = com::NativeEventQueue::getMainEventQueue();
     740    AssertPtrReturn(m->m_EventQ, VERR_INTERNAL_ERROR);
     741
     742    while(true)
     743    {
     744        m->m_EventQ->processEventQueue(0);
     745           
     746        if (m->fShutdown)
     747            break;
     748
     749        m->m_EventQ->processEventQueue(500);
     750    }
     751
     752    return VINF_SUCCESS;
     753}
     754
     755
    680756void VBoxNetBaseService::debugPrint(int32_t iMinLevel, bool fMsg, const char *pszFmt, ...) const
    681757{
  • trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.h

    r49832 r49842  
    3030
    3131
     32class VBoxNetLockee
     33{
     34public:
     35    virtual int  syncEnter() = 0;
     36    virtual int  syncLeave() = 0;
     37};
     38
     39
     40class VBoxNetALock
     41{
     42public:
     43    VBoxNetALock(VBoxNetLockee *a_lck):m_lck(a_lck)
     44    {
     45        if (m_lck)
     46            m_lck->syncEnter();
     47    }
     48
     49    ~VBoxNetALock()
     50    {
     51        if (m_lck)
     52            m_lck->syncLeave();
     53    }
     54
     55private:
     56    VBoxNetLockee *m_lck;
     57};
     58
    3259# ifndef BASE_SERVICES_ONLY
    33 class VBoxNetBaseService: public VBoxNetHlpUDPService
     60class VBoxNetBaseService: public VBoxNetHlpUDPService, public VBoxNetLockee
    3461{
    3562public:
     
    4875                                        void const *pvData, size_t cbData) const;
    4976    virtual void        usage(void) = 0;
    50     virtual int         run(void) = 0;
    5177    virtual int         parseOpt(int rc, const RTGETOPTUNION& getOptVal) = 0;
    5278    virtual int         processFrame(void *, size_t) = 0;
     
    5682
    5783    virtual int         init(void);
     84    virtual int         run(void);
    5885    virtual bool        isMainNeeded() const;
    5986
     
    96123    virtual void debugPrintV(int32_t iMinLevel, bool fMsg, const char *pszFmt, va_list va) const;
    97124
     125    private:
    98126    void doReceiveLoop();
    99127
    100 protected:
     128    /** starts receiving thread and enter event polling loop. */
     129    int startReceiveThreadAndEnterEventLoop();
     130
     131    protected:
    101132    /* VirtualBox instance */
    102133    ComPtr<IVirtualBox> virtualbox;
    103134
    104 private:
     135    private:
    105136    struct Data;
    106137    Data *m;
    107138
    108 private:
     139    private:
    109140    PRTGETOPTDEF getOptionsPtr();
    110141};
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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