Changeset 28943 in vbox for trunk/src/VBox/Additions/common/VBoxService
- Timestamp:
- Apr 30, 2010 3:47:23 PM (15 years ago)
- Location:
- trunk/src/VBox/Additions/common/VBoxService
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlExec.cpp
r28926 r28943 535 535 } 536 536 537 int VBoxServiceControlExecInitPipeBuffer(PVBOXSERVICECTRLEXECPIPEBUF pBuf) 538 { 539 AssertPtr(pBuf); 540 541 pBuf->pbData = (uint8_t*)RTMemAlloc(_64K); /* Start with a 64k buffer. */ 542 AssertReturn(pBuf->pbData, VERR_NO_MEMORY); 543 pBuf->cbSize = 0; 544 pBuf->cbOffset = 0; 545 pBuf->cbRead = 0; 546 547 return RTSemMutexCreate(&pBuf->mtx); 548 } 549 550 int VBoxServiceControlExecDestroyPipeBuffer(PVBOXSERVICECTRLEXECPIPEBUF pBuf) 551 { 552 if (pBuf) 553 { 554 if (pBuf->pbData) 555 RTMemFree(pBuf->pbData); 556 pBuf->pbData = NULL; 557 pBuf->cbSize = 0; 558 pBuf->cbOffset = 0; 559 pBuf->cbRead = 0; 560 } 561 return RTSemMutexDestroy(pBuf->mtx); 562 } 563 537 564 int VBoxServiceControlExecReadPipeBufferContent(PVBOXSERVICECTRLEXECPIPEBUF pBuf, 538 565 uint8_t *pbBuffer, uint32_t cbBuffer, uint32_t *pcbToRead) 539 566 { 567 AssertPtr(pBuf); 540 568 AssertPtr(pcbToRead); 541 569 542 // LOCKING 543 544 Assert(pBuf->cbOffset >= pBuf->cbRead); 545 if (*pcbToRead > pBuf->cbOffset - pBuf->cbRead) 546 *pcbToRead = pBuf->cbOffset - pBuf->cbRead; 547 548 if (*pcbToRead > cbBuffer) 549 *pcbToRead = cbBuffer; 550 551 if (*pcbToRead > 0) 552 { 553 memcpy(pbBuffer, pBuf->pbData + pBuf->cbRead, *pcbToRead); 554 pBuf->cbRead += *pcbToRead; 555 } 556 else 557 { 558 pbBuffer = NULL; 559 *pcbToRead = 0; 560 } 561 return VINF_SUCCESS; 570 int rc = RTSemMutexRequest(pBuf->mtx, RT_INDEFINITE_WAIT); 571 if (RT_SUCCESS(rc)) 572 { 573 Assert(pBuf->cbOffset >= pBuf->cbRead); 574 if (*pcbToRead > pBuf->cbOffset - pBuf->cbRead) 575 *pcbToRead = pBuf->cbOffset - pBuf->cbRead; 576 577 if (*pcbToRead > cbBuffer) 578 *pcbToRead = cbBuffer; 579 580 if (*pcbToRead > 0) 581 { 582 memcpy(pbBuffer, pBuf->pbData + pBuf->cbRead, *pcbToRead); 583 pBuf->cbRead += *pcbToRead; 584 } 585 else 586 { 587 pbBuffer = NULL; 588 *pcbToRead = 0; 589 } 590 rc = RTSemMutexRelease(pBuf->mtx); 591 } 592 return rc; 562 593 } 563 594 … … 567 598 AssertPtr(pBuf); 568 599 569 // LOCKING 570 571 /** @todo Use RTMemCache or RTMemObj here? */ 572 uint8_t *pNewBuf; 573 while (pBuf->cbSize - pBuf->cbOffset < cbData) 574 { 575 pNewBuf = (uint8_t*)RTMemRealloc(pBuf->pbData, pBuf->cbSize + _4K); 576 if (pNewBuf == NULL) 577 break; 578 pBuf->cbSize += _4K; 579 pBuf->pbData = pNewBuf; 580 } 581 582 int rc = VINF_SUCCESS; 583 if (pBuf->pbData) 584 { 585 memcpy(pBuf->pbData + pBuf->cbOffset, pbData, cbData); 586 pBuf->cbOffset += cbData; 587 /** @todo Add offset clamping! */ 588 } 589 else 590 rc = VERR_NO_MEMORY; 600 int rc = RTSemMutexRequest(pBuf->mtx, RT_INDEFINITE_WAIT); 601 if (RT_SUCCESS(rc)) 602 { 603 /** @todo Use RTMemCache or RTMemObj here? */ 604 uint8_t *pNewBuf; 605 while (pBuf->cbSize - pBuf->cbOffset < cbData) 606 { 607 pNewBuf = (uint8_t*)RTMemRealloc(pBuf->pbData, pBuf->cbSize + _4K); 608 if (pNewBuf == NULL) 609 break; 610 pBuf->cbSize += _4K; 611 pBuf->pbData = pNewBuf; 612 } 613 614 int rc = VINF_SUCCESS; 615 if (pBuf->pbData) 616 { 617 memcpy(pBuf->pbData + pBuf->cbOffset, pbData, cbData); 618 pBuf->cbOffset += cbData; 619 /** @todo Add offset clamping! */ 620 } 621 else 622 rc = VERR_NO_MEMORY; 623 int rc2 = RTSemMutexRelease(pBuf->mtx); 624 if (RT_SUCCESS(rc)) 625 rc = rc2; 626 } 591 627 return rc; 592 628 } … … 668 704 669 705 /* Init buffers. */ 670 pData->stdOut.pbData = NULL; 671 pData->stdOut.cbSize = 0; 672 pData->stdOut.cbOffset = 0; 673 pData->stdOut.cbRead = 0; 674 675 pData->stdErr.pbData = NULL; 676 pData->stdErr.cbSize = 0; 677 pData->stdErr.cbOffset = 0; 678 pData->stdErr.cbRead = 0; 706 rc = VBoxServiceControlExecInitPipeBuffer(&pData->stdOut); 707 if (RT_SUCCESS(rc)) 708 rc = VBoxServiceControlExecInitPipeBuffer(&pData->stdErr); 679 709 } 680 710 … … 689 719 } 690 720 return rc; 691 }692 693 void VBoxServiceControlExecDestroyPipeBuffer(PVBOXSERVICECTRLEXECPIPEBUF pBuf)694 {695 if (pBuf)696 {697 if (pBuf->pbData)698 RTMemFree(pBuf->pbData);699 pBuf->pbData = NULL;700 pBuf->cbSize = 0;701 pBuf->cbOffset = 0;702 pBuf->cbRead = 0;703 }704 721 } 705 722 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h
r28800 r28943 27 27 #ifdef VBOX_WITH_GUEST_CONTROL 28 28 # include <iprt/list.h> 29 # include <iprt/semaphore.h> 29 30 #endif 30 31 … … 134 135 typedef struct 135 136 { 136 uint8_t *pbData; 137 uint32_t cbSize; 138 uint32_t cbOffset; 139 uint32_t cbRead; 137 uint8_t *pbData; 138 uint32_t cbSize; 139 uint32_t cbOffset; 140 uint32_t cbRead; 141 RTSEMMUTEX mtx; 140 142 } VBOXSERVICECTRLEXECPIPEBUF; 141 143 /** Pointer to thread data. */
Note:
See TracChangeset
for help on using the changeset viewer.