- Timestamp:
- Sep 10, 2008 12:15:20 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Serial/DrvHostSerial.cpp
r12334 r12347 46 46 # include <string.h> 47 47 # include <unistd.h> 48 # include <sys/poll.h> 48 # ifdef RT_OS_DARWIN 49 # include <sys/select.h> 50 # else 51 # include <sys/poll.h> 52 # endif 49 53 # include <sys/ioctl.h> 50 54 # include <pthread.h> … … 536 540 size_t cbRemaining = 0; /* start by reading host data */ 537 541 int rc = VINF_SUCCESS; 542 int rcThread = VINF_SUCCESS; 538 543 539 544 if (pThread->enmState == PDMTHREADSTATE_INITIALIZING) … … 541 546 542 547 #ifdef RT_OS_WINDOWS 543 HANDLE haWait[2];544 haWait[0] = pThis->hEventRecv;545 haWait[1] = pThis->hHaltEventSem;548 HANDLE ahWait[2]; 549 ahWait[0] = pThis->hEventRecv; 550 ahWait[1] = pThis->hHaltEventSem; 546 551 #endif 547 552 … … 552 557 /* Get a block of data from the host serial device. */ 553 558 554 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 559 #if defined(RT_OS_DARWIN) /* poll is broken on x86 darwin, returns POLLNVAL. */ 560 fdset RdSet; 561 FDSET_ZERO(&RdSet); 562 FDSET_SET(pThis->DeviceFile, &RdSet); 563 FDSET_SET(pThis->WakeupPipeR, &RdSet); 564 fdset XcptSet; 565 FDSET_ZERO(&XcptSet); 566 FDSET_SET(pThis->DeviceFile, &XcptSet); 567 FDSET_SET(pThis->WakeupPipeR, &XcptSet); 568 rc = select(RT_MAX(pThis->WakeupPipeR, pThis->DeviceFile) + 1, &RdSet, NULL, &XcptSet, NULL); 569 if (rc == -1) 570 { 571 int err = errno; 572 rcThread = RTErrConvertFromErrno(err); 573 LogRel(("HostSerial#%d: select failed with errno=%d / %Rrc, terminating the worker thread.\n", pDrvIns->iInstance, err, rcThread)); 574 break; 575 } 576 577 /* this might have changed in the meantime */ 578 if (pThread->enmState != PDMTHREADSTATE_RUNNING) 579 break; 580 if (rc == 0) 581 continue; 582 583 /* drain the wakeup pipe */ 584 if ( FDSET_ISSET(pThis->WakeupPipeR, &RdSet) 585 || FDSET_ISSET(pThis->WakeupPipeR, &XcptSet)) 586 { 587 rc = RTFileRead(pThis->WakeupPipeR, abBuffer, 1, &cbRead); 588 if (RT_FAILURE(rc)) 589 { 590 LogRel(("HostSerial#%d: draining the wakekup pipe failed with %Rrc, terminating the worker thread.\n", pDrvIns->iInstance, rc)); 591 rcThread = rc; 592 break; 593 } 594 continue; 595 } 596 597 /* read data from the serial port. */ 598 rc = RTFileRead(pThis->DeviceFile, abBuffer, sizeof(abBuffer), &cbRead); 599 if (RT_FAILURE(rc)) 600 { 601 LogRel(("HostSerial#%d: Read failed with %Rrc, terminating the worker thread.\n", pDrvIns->iInstance, rc)); 602 rcThread = rc; 603 break; 604 } 605 cbRemaining = cbRead; 606 607 #elif defined(RT_OS_LINUX) 555 608 556 609 size_t cbRead; … … 565 618 if (rc < 0) 566 619 { 567 /* poll failed for whatever reason */ 620 int err = errno; 621 rcThread = RTErrConvertFromErrno(err); 622 LogRel(("HostSerial#%d: poll failed with errno=%d / %Rrc, terminating the worker thread.\n", pDrvIns->iInstance, err, rcThread)); 568 623 break; 569 624 } … … 576 631 break; 577 632 /* notification to terminate -- drain the pipe */ 578 char ch; 579 size_t cbRead; 580 RTFileRead(pThis->WakeupPipeR, &ch, 1, &cbRead); 633 RTFileRead(pThis->WakeupPipeR, &abBuffer, 1, &cbRead); 581 634 continue; 582 635 } … … 585 638 { 586 639 LogRel(("HostSerial#%d: Read failed with %Rrc, terminating the worker thread.\n", pDrvIns->iInstance, rc)); 640 rcThread = rc; 587 641 break; 588 642 } … … 602 656 if (dwRet == ERROR_IO_PENDING) 603 657 { 604 dwRet = WaitForMultipleObjects(2, haWait, FALSE, INFINITE);658 dwRet = WaitForMultipleObjects(2, ahWait, FALSE, INFINITE); 605 659 if (dwRet != WAIT_OBJECT_0) 606 660 { … … 611 665 else 612 666 { 613 LogRel(("HostSerial#%d: Wait failed with error %Rrc; terminating the worker thread.\n", pDrvIns->iInstance, RTErrConvertFromWin32(dwRet))); 667 rcThread = RTErrConvertFromWin32(dwRet); 668 LogRel(("HostSerial#%d: Wait failed with error %Rrc; terminating the worker thread.\n", pDrvIns->iInstance, rcThread)); 614 669 break; 615 670 } … … 624 679 if (!ReadFile(pThis->hDeviceFile, abBuffer, sizeof(abBuffer), &dwNumberOfBytesTransferred, &pThis->overlappedRecv)) 625 680 { 626 LogRel(("HostSerial#%d: Read failed with error %Rrc; terminating the worker thread.\n", pDrvIns->iInstance, RTErrConvertFromWin32(GetLastError()))); 681 rcThread = RTErrConvertFromWin32(GetLastError()); 682 LogRel(("HostSerial#%d: Read failed with error %Rrc; terminating the worker thread.\n", pDrvIns->iInstance, rcThread)); 627 683 break; 628 684 } … … 685 741 { 686 742 LogRel(("HostSerial#%d: NotifyRead failed with %Rrc, terminating the worker thread.\n", pDrvIns->iInstance, rc)); 743 rcThread = rc; 687 744 break; 688 745 } … … 690 747 } 691 748 692 return VINF_SUCCESS;749 return rcThread; 693 750 } 694 751
Note:
See TracChangeset
for help on using the changeset viewer.