VirtualBox

Changeset 35692 in vbox


Ignore:
Timestamp:
Jan 24, 2011 5:11:41 PM (14 years ago)
Author:
vboxsync
Message:

VBoxService/ControlExec: Update.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlExec.cpp

    r35690 r35692  
    9595 * @retval  VINF_TRY_AGAIN if there is still data left in the buffer.
    9696 *
     97 * @param   hPollSet            The polling set.
    9798 * @param   pStdInBuf           The standard input buffer.
    9899 * @param   hStdInW             The standard input pipe.
    99100 * @param   pfClose             Pointer to a flag whether the pipe needs to be closed afterwards.
    100101 */
    101 static int VBoxServiceControlExecProcWriteStdIn(PVBOXSERVICECTRLEXECPIPEBUF pStdInBuf, RTPIPE hStdInW,
     102static int VBoxServiceControlExecProcWriteStdIn(RTPOLLSET hPollSet, PVBOXSERVICECTRLEXECPIPEBUF pStdInBuf, RTPIPE hStdInW,
    102103                                                size_t *pcbWritten, bool *pfClose)
    103104{
     
    108109    if (RT_SUCCESS(rc))
    109110    {
     111        Assert(pStdInBuf->cbSize >= pStdInBuf->cbOffset);
    110112        size_t cbToWrite = pStdInBuf->cbSize - pStdInBuf->cbOffset;
    111113        cbToWrite = RT_MIN(cbToWrite, _1M);
    112114        *pfClose = false;
    113         if (cbToWrite && pStdInBuf->fAlive)
     115        if (   pStdInBuf->fAlive
     116            && cbToWrite)
    114117        {
    115118            rc = RTPipeWrite(hStdInW, &pStdInBuf->pbData[pStdInBuf->cbOffset], cbToWrite, pcbWritten);
     
    117120            {
    118121                pStdInBuf->fNeedNotification = true;
    119                 if (rc == VINF_TRY_AGAIN)
    120                 {
    121                     //if (pStdInBuf->fNeedNotification)
    122                 }
    123                 else
    124                 {
     122                if (rc != VINF_TRY_AGAIN)
    125123                    pStdInBuf->cbOffset += *pcbWritten;
    126                 }
    127124
    128125                /* Did somebody tell us that we should come to an end,
     
    163160            *pcbWritten = 0;
    164161            pStdInBuf->fNeedNotification = pStdInBuf->fAlive;
    165             //rc = VERR_BAD_PIPE;
    166         }
     162        }
     163
     164        if (   !*pcbWritten
     165            && pStdInBuf->fAlive)
     166        {
     167            /*
     168             * Nothing else left to write now? Remove the writable event from the poll set
     169             * to not trigger too high CPU loads.
     170             */
     171            rc = RTPollSetRemove(hPollSet, VBOXSERVICECTRLPIPEID_STDIN_WRITABLE);
     172            AssertRC(rc);
     173        }
     174
    167175        int rc2 = RTCritSectLeave(&pStdInBuf->CritSect);
    168176        if (RT_SUCCESS(rc))
     
    192200    {
    193201        bool fClose;
    194         rc = VBoxServiceControlExecProcWriteStdIn(pStdInBuf, *phStdInW, pcbWritten, &fClose);
     202        rc = VBoxServiceControlExecProcWriteStdIn(hPollSet,
     203                                                  pStdInBuf, *phStdInW,
     204                                                  pcbWritten, &fClose);
    195205        if (rc == VINF_TRY_AGAIN)
    196206            rc = VINF_SUCCESS;
     
    213223            /* If the pipe needs to be closed, do so. */
    214224            rc = VBoxServiceControlExecProcHandleStdInErrorEvent(hPollSet, fPollEvt, phStdInW, pStdInBuf);
    215         }
    216         else if (!*pcbWritten)
    217         {
    218             /* Nothing else left to write now? Remove the writable event from the poll set
    219              * to not trigger too high CPU loads. */
    220             rc = RTPollSetRemove(hPollSet, VBOXSERVICECTRLPIPEID_STDIN_WRITABLE);
    221             AssertRC(rc);
    222225        }
    223226    }
     
    325328        AssertRC(rc2);
    326329        *phPipeR = NIL_RTPIPE;
     330    }
     331    return rc;
     332}
     333
     334
     335int VBoxServiceControlExecProcHandleStdInputNotify(RTPOLLSET hPollSet,
     336                                                   PRTPIPE phNotificationPipeR, PRTPIPE phInputPipeW)
     337{
     338#ifdef DEBUG
     339    VBoxServiceVerbose(4, "ControlExec: HandleStdInputNotify\n");
     340#endif
     341    /* Drain the notification pipe. */
     342    uint8_t abBuf[8];
     343    size_t cbIgnore;
     344    int rc = RTPipeRead(*phNotificationPipeR, abBuf, sizeof(abBuf), &cbIgnore);
     345    if (RT_SUCCESS(rc))
     346    {
     347        /*
     348         * When the writable handle previously was removed from the poll set we need to add
     349         * it here again so that writable events from the started procecss get handled correctly.
     350         */
     351        RTHANDLE hWritableIgnored;
     352        rc = RTPollSetQueryHandle(hPollSet, VBOXSERVICECTRLPIPEID_STDIN_WRITABLE, &hWritableIgnored);
     353        if (rc == VERR_POLL_HANDLE_ID_NOT_FOUND)
     354            rc = RTPollSetAddPipe(hPollSet, *phInputPipeW, RTPOLL_EVT_WRITE, VBOXSERVICECTRLPIPEID_STDIN_WRITABLE);
    327355    }
    328356    return rc;
     
    408436
    409437                case VBOXSERVICECTRLPIPEID_STDIN_INPUT_NOTIFY:
    410                 {
    411                     /* Drain the notification pipe. */
    412                     uint8_t abBuf[8];
    413                     size_t cbIgnore;
    414                     rc = RTPipeRead(pData->stdIn.hNotificationPipeR, abBuf, sizeof(abBuf), &cbIgnore);
    415                     if (RT_SUCCESS(rc))
    416                     {
    417                         /*
    418                          * When the writable handle previously was removed from the poll set we need to add
    419                          * it here again so that writable events from the started procecss get handled correctly.
    420                          */
    421                         RTHANDLE hWritableIgnored;
    422                         rc = RTPollSetQueryHandle(hPollSet, VBOXSERVICECTRLPIPEID_STDIN_WRITABLE, &hWritableIgnored);
    423                         if (rc == VERR_POLL_HANDLE_ID_NOT_FOUND)
    424                         {
    425                             rc = RTPollSetAddPipe(hPollSet, pData->pipeStdInW, RTPOLL_EVT_WRITE, VBOXSERVICECTRLPIPEID_STDIN_WRITABLE);
    426                             AssertRC(rc);
    427                             break;
    428                         }
    429                         AssertRC(rc);
    430                     }
    431                 }
    432                 /* Fall through. */
     438                    rc = VBoxServiceControlExecProcHandleStdInputNotify(hPollSet,
     439                                                                        &pData->stdIn.hNotificationPipeR, &pData->pipeStdInW);
     440                    AssertRC(rc);
     441                    /* Fall through. */
    433442                case VBOXSERVICECTRLPIPEID_STDIN_WRITABLE:
    434443                {
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