- Timestamp:
- Sep 24, 2007 9:02:26 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Serial/DrvHostSerial.cpp
r4928 r4993 81 81 RTSEMEVENT SendSem; 82 82 83 #ifdef RT_OS_LINUX 84 /** The receive thread wakeup pipe. */ 85 RTFILE WakeupPipeR; 86 RTFILE WakeupPipeW; 87 #endif 88 83 89 /** the device path */ 84 90 char *pszDevicePath; … … 100 106 #define PDMICHAR_2_DRVHOSTSERIAL(pInterface) ( (PDRVHOSTSERIAL)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTSERIAL, IChar)) ) 101 107 102 108 #ifdef RT_OS_LINUX 109 /** String written to the wakeup pipe. */ 110 #define WAKE_UP_STRING "WakeUp!" 111 /** Length of the string written. */ 112 #define WAKE_UP_STRING_LEN ( sizeof (WAKE_UP_STRING) - 1 ) 113 #endif 103 114 /* -=-=-=-=- IBase -=-=-=-=- */ 104 115 … … 445 456 446 457 #ifdef RT_OS_LINUX 447 struct pollfd pfd; 448 449 pfd.fd = pData->DeviceFile; 450 pfd.events = POLLIN; 451 452 rc = poll(&pfd, 1, -1); 458 struct pollfd pfd[2]; 459 460 pfd[0].fd = pData->DeviceFile; 461 pfd[0].events = POLLIN; 462 pfd[1].fd = pData->WakeupPipeR; 463 pfd[1].events = POLLIN | POLLERR | POLLHUP; 464 465 rc = poll(&pfd[0], 2, -1); 466 453 467 if (rc < 0) 454 468 break; 469 470 if (rc > 0) 471 { 472 if (pfd[1].revents & POLLIN) 473 { 474 /* Empty the pipe. */ 475 char szBuf[WAKE_UP_STRING_LEN]; 476 rc = RTFileRead (pData->WakeupPipeR, szBuf, sizeof (szBuf), NULL); 477 AssertRC (rc); 478 break; 479 } 480 } 455 481 #elif defined(RT_OS_WINDOWS) 456 482 BOOL retval; … … 523 549 { 524 550 PDRVHOSTSERIAL pData = PDMINS2DATA(pDrvIns, PDRVHOSTSERIAL); 551 #ifdef RT_OS_LINUX 552 int filedes[2]; 553 #endif 554 525 555 LogFlow(("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance)); 526 556 … … 579 609 #ifdef RT_OS_LINUX 580 610 fcntl(pData->DeviceFile, F_SETFL, O_NONBLOCK); 611 /* Create the wakeup pipe. */ 612 if (!pipe(filedes)) 613 { 614 pData->WakeupPipeR = filedes[0]; 615 pData->WakeupPipeW = filedes[1]; 616 } 581 617 #elif defined(RT_OS_WINDOWS) 582 618 /* Set the COMMTIMEOUTS to get non blocking I/O */ … … 629 665 { 630 666 PDRVHOSTSERIAL pData = PDMINS2DATA(pDrvIns, PDRVHOSTSERIAL); 667 int rc; 631 668 632 669 LogFlow(("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance)); 633 670 634 671 ASMAtomicXchgBool(&pData->fShutdown, true); 672 673 #ifdef RT_OS_LINUX 674 /* Notify the receive thread that we want to shutdown. */ 675 rc = RTFileWrite (pData->WakeupPipeW, WAKE_UP_STRING, WAKE_UP_STRING_LEN, NULL); 676 if (VBOX_SUCCESS (rc)) 677 RTFileFlush (pData->WakeupPipeW); 678 #endif 635 679 if (pData->ReceiveThread != NIL_RTTHREAD) 636 680 { 637 intrc = RTThreadWait(pData->ReceiveThread, 15000, NULL);681 rc = RTThreadWait(pData->ReceiveThread, 15000, NULL); 638 682 if (RT_FAILURE(rc)) 639 683 LogRel(("HostSerial%d: receive thread did not terminate (rc=%Rrc)\n", pDrvIns->iInstance, rc)); … … 655 699 pData->SendThread = NIL_RTTHREAD; 656 700 } 701 702 #ifdef RT_OS_LINUX 703 RTFileClose(pData->WakeupPipeR); 704 RTFileClose(pData->WakeupPipeW); 705 #endif 706 707 RTFileClose(pData->DeviceFile); 657 708 } 658 709
Note:
See TracChangeset
for help on using the changeset viewer.