VirtualBox

Changeset 22160 in vbox for trunk/src/VBox/Devices/Network


Ignore:
Timestamp:
Aug 11, 2009 11:55:43 AM (15 years ago)
Author:
vboxsync
Message:

NAT: splitting PDM consumer to serve slirp_can_output and slirp_output

File:
1 edited

Legend:

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

    r22020 r22160  
    148148    /* Send queue */
    149149    PPDMQUEUE               pSendQueue;
     150
     151    RTSEMEVENT semStatus;
    150152#ifdef VBOX_WITH_SLIRP_MT
    151153    PPDMTHREAD              pGuestThread;
     
    169171 * NAT queue item.
    170172 */
     173typedef enum SLIRP_EVENT {SLIRP_CHECK, SLIRP_SEND} SLIRP_EVENT;
    171174typedef struct DRVNATQUEUITEM
    172175{
    173176    /** The core part owned by the queue manager. */
    174177    PDMQUEUEITEMCORE    Core;
     178    SLIRP_EVENT enmType;
     179    int *pStatus;
    175180    /** The buffer for output to guest. */
    176181    const uint8_t       *pu8Buf;
     
    275280    /* nothing to do */
    276281}
    277 
    278282
    279283/**
     
    533537int slirp_can_output(void *pvUser)
    534538{
     539    int status = 0;
     540    int rc = 0;
    535541    PDRVNAT pThis = (PDRVNAT)pvUser;
    536542
    537     Assert(pThis);
    538     return 1;
     543    PDRVNATQUEUITEM pItem = (PDRVNATQUEUITEM)PDMQueueAlloc(pThis->pSendQueue);
     544    if (pItem)
     545    {
     546        pItem->enmType = SLIRP_CHECK;
     547        pItem->pStatus = &status;
     548        PDMQueueInsert(pThis->pSendQueue, &pItem->Core);
     549        rc = RTSemEventWait(pThis->semStatus, RT_INDEFINITE_WAIT);
     550        AssertRC(rc);
     551        return status;
     552    }
     553    return 0;
    539554}
    540555
     
    560575    if (pItem)
    561576    {
     577        pItem->enmType = SLIRP_SEND;
    562578        pItem->pu8Buf = pu8Buf;
    563579        pItem->cb = cb;
     
    591607static DECLCALLBACK(bool) drvNATQueueConsumer(PPDMDRVINS pDrvIns, PPDMQUEUEITEMCORE pItemCore)
    592608{
     609    int rc;
    593610    PDRVNAT pThis = PDMINS_2_DATA(pDrvIns, PDRVNAT);
    594611    PDRVNATQUEUITEM pItem = (PDRVNATQUEUITEM)pItemCore;
     
    596613    Log(("drvNATQueueConsumer(pItem:%p, pu8Buf:%p, cb:%d)\n", pItem, pItem->pu8Buf, pItem->cb));
    597614    Log2(("drvNATQueueConsumer: pu8Buf:\n%.Rhxd\n", pItem->pu8Buf));
    598     int rc = pThis->pPort->pfnWaitReceiveAvail(pThis->pPort, 0);
    599     if (RT_FAILURE(rc))
    600         return false;
    601     rc = pThis->pPort->pfnReceive(pThis->pPort, pItem->pu8Buf, pItem->cb);
     615    switch (pItem->enmType) {
     616        case SLIRP_SEND:
     617            rc = pThis->pPort->pfnReceive(pThis->pPort, pItem->pu8Buf, pItem->cb);
     618            RTMemFree((void *)pItem->pu8Buf);
     619            break;
     620        case SLIRP_CHECK:
     621           
     622            *pItem->pStatus = (RT_SUCCESS(pThis->pPort->pfnWaitReceiveAvail(pThis->pPort, 0))? 1 : 0);
     623             rc = RTSemEventSignal(pThis->semStatus);
     624             AssertRC(rc);
     625            break;
     626    }
     627    return true;
    602628
    603629#if 0
     
    613639    /*Copy buffer again, till seeking good way of syncronization with slirp mbuf management code*/
    614640    AssertRelease(pItem->mbuf == NULL);
    615     RTMemFree((void *)pItem->pu8Buf);
    616641#endif
    617642    return RT_SUCCESS(rc);
     
    937962                return rc;
    938963            }
     964
     965            rc = RTSemEventCreate(&pThis->semStatus);
     966            AssertRC(rc);
    939967
    940968#ifndef RT_OS_WINDOWS
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