Changeset 35692 in vbox
- Timestamp:
- Jan 24, 2011 5:11:41 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlExec.cpp
r35690 r35692 95 95 * @retval VINF_TRY_AGAIN if there is still data left in the buffer. 96 96 * 97 * @param hPollSet The polling set. 97 98 * @param pStdInBuf The standard input buffer. 98 99 * @param hStdInW The standard input pipe. 99 100 * @param pfClose Pointer to a flag whether the pipe needs to be closed afterwards. 100 101 */ 101 static int VBoxServiceControlExecProcWriteStdIn( PVBOXSERVICECTRLEXECPIPEBUF pStdInBuf, RTPIPE hStdInW,102 static int VBoxServiceControlExecProcWriteStdIn(RTPOLLSET hPollSet, PVBOXSERVICECTRLEXECPIPEBUF pStdInBuf, RTPIPE hStdInW, 102 103 size_t *pcbWritten, bool *pfClose) 103 104 { … … 108 109 if (RT_SUCCESS(rc)) 109 110 { 111 Assert(pStdInBuf->cbSize >= pStdInBuf->cbOffset); 110 112 size_t cbToWrite = pStdInBuf->cbSize - pStdInBuf->cbOffset; 111 113 cbToWrite = RT_MIN(cbToWrite, _1M); 112 114 *pfClose = false; 113 if (cbToWrite && pStdInBuf->fAlive) 115 if ( pStdInBuf->fAlive 116 && cbToWrite) 114 117 { 115 118 rc = RTPipeWrite(hStdInW, &pStdInBuf->pbData[pStdInBuf->cbOffset], cbToWrite, pcbWritten); … … 117 120 { 118 121 pStdInBuf->fNeedNotification = true; 119 if (rc == VINF_TRY_AGAIN) 120 { 121 //if (pStdInBuf->fNeedNotification) 122 } 123 else 124 { 122 if (rc != VINF_TRY_AGAIN) 125 123 pStdInBuf->cbOffset += *pcbWritten; 126 }127 124 128 125 /* Did somebody tell us that we should come to an end, … … 163 160 *pcbWritten = 0; 164 161 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 167 175 int rc2 = RTCritSectLeave(&pStdInBuf->CritSect); 168 176 if (RT_SUCCESS(rc)) … … 192 200 { 193 201 bool fClose; 194 rc = VBoxServiceControlExecProcWriteStdIn(pStdInBuf, *phStdInW, pcbWritten, &fClose); 202 rc = VBoxServiceControlExecProcWriteStdIn(hPollSet, 203 pStdInBuf, *phStdInW, 204 pcbWritten, &fClose); 195 205 if (rc == VINF_TRY_AGAIN) 196 206 rc = VINF_SUCCESS; … … 213 223 /* If the pipe needs to be closed, do so. */ 214 224 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 set219 * to not trigger too high CPU loads. */220 rc = RTPollSetRemove(hPollSet, VBOXSERVICECTRLPIPEID_STDIN_WRITABLE);221 AssertRC(rc);222 225 } 223 226 } … … 325 328 AssertRC(rc2); 326 329 *phPipeR = NIL_RTPIPE; 330 } 331 return rc; 332 } 333 334 335 int 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); 327 355 } 328 356 return rc; … … 408 436 409 437 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. */ 433 442 case VBOXSERVICECTRLPIPEID_STDIN_WRITABLE: 434 443 {
Note:
See TracChangeset
for help on using the changeset viewer.

