Changeset 49814 in vbox for trunk/src/VBox/Devices/USB/linux
- Timestamp:
- Dec 6, 2013 9:38:28 PM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 91156
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/USB/linux/USBProxyDevice-linux.cpp
r46326 r49814 33 33 #include <iprt/stdint.h> 34 34 #include <iprt/err.h> 35 #include <iprt/pipe.h> 35 36 36 37 #include <sys/types.h> … … 153 154 /** Are we using sysfs to find the active configuration? */ 154 155 bool fUsingSysfs; 156 /** Pipe handle for waiking up - writing end. */ 157 RTPIPE hPipeWakeupW; 158 /** Pipe handle for waiking up - reading end. */ 159 RTPIPE hPipeWakeupR; 155 160 /** The device node/sysfs path of the device. 156 161 * Used to figure out the configuration after a reset. */ … … 657 662 if (RT_SUCCESS(rc)) 658 663 { 659 /* 660 * Allocate and initialize the linux backend data. 661 */ 662 PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)RTMemAllocZVar(sizeof(*pDevLnx) + cchPath); 663 if (pDevLnx) 664 { 665 pDevLnx->fUsingSysfs = fUsingSysfs; 666 memcpy(&pDevLnx->szPath[0], pszPath, cchPath); 667 pDevLnx->szPath[cchPath] = '\0'; 668 pDevLnx->hFile = hFile; 669 rc = RTCritSectInit(&pDevLnx->CritSect); 670 if (RT_SUCCESS(rc)) 664 /* 665 * Allocate and initialize the linux backend data. 666 */ 667 PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)RTMemAllocZVar(sizeof(*pDevLnx) + cchPath); 668 if (pDevLnx) 671 669 { 672 pProxyDev->Backend.pv = pDevLnx; 673 674 LogFlow(("usbProxyLinuxOpen(%p, %s): returns successfully File=%RTfile iActiveCfg=%d\n", 675 pProxyDev, pszAddress, pDevLnx->hFile, pProxyDev->iActiveCfg)); 676 677 return VINF_SUCCESS; 670 671 rc = RTPipeCreate(&pDevLnx->hPipeWakeupR, &pDevLnx->hPipeWakeupW, 0); 672 if (RT_SUCCESS(rc)) 673 { 674 pDevLnx->fUsingSysfs = fUsingSysfs; 675 memcpy(&pDevLnx->szPath[0], pszPath, cchPath); 676 pDevLnx->szPath[cchPath] = '\0'; 677 pDevLnx->hFile = hFile; 678 rc = RTCritSectInit(&pDevLnx->CritSect); 679 if (RT_SUCCESS(rc)) 680 { 681 pProxyDev->Backend.pv = pDevLnx; 682 683 LogFlow(("usbProxyLinuxOpen(%p, %s): returns successfully File=%RTfile iActiveCfg=%d\n", 684 pProxyDev, pszAddress, pDevLnx->hFile, pProxyDev->iActiveCfg)); 685 686 return VINF_SUCCESS; 687 } 688 RTPipeClose(pDevLnx->hPipeWakeupR); 689 RTPipeClose(pDevLnx->hPipeWakeupW); 690 } 691 692 RTMemFree(pDevLnx); 678 693 } 679 680 RTMemFree(pDevLnx); 681 } 682 else 683 rc = VERR_NO_MEMORY; 694 else 695 rc = VERR_NO_MEMORY; 696 684 697 RTFileClose(hFile); 685 698 } … … 814 827 RTFileClose(pDevLnx->hFile); 815 828 pDevLnx->hFile = NIL_RTFILE; 829 830 RTPipeClose(pDevLnx->hPipeWakeupR); 831 RTPipeClose(pDevLnx->hPipeWakeupW); 816 832 817 833 RTMemFree(pDevLnx); … … 1745 1761 */ 1746 1762 if (!pDevLnx->pInFlightHead) 1763 { 1764 int cMilliesWait = cMillies == RT_INDEFINITE_WAIT ? -1 : cMillies; 1765 1766 LogFlow(("Nothing in flight, going to sleep\n")); 1767 1768 struct pollfd pfd; 1769 1770 pfd.fd = RTPipeToNative(pDevLnx->hPipeWakeupR); 1771 pfd.events = POLLIN | POLLHUP; 1772 pfd.revents = 0; 1773 1774 int rc = poll(&pfd, 1, cMilliesWait); 1775 Log(("usbProxyLinuxUrbReap: poll rc = %d\n", rc)); 1776 if (rc >= 1) 1777 { 1778 /* Drain pipe. */ 1779 uint8_t bRead; 1780 size_t cbIgnored = 0; 1781 RTPipeRead(pDevLnx->hPipeWakeupR, &bRead, 1, &cbIgnored); 1782 } 1747 1783 return NULL; 1784 } 1748 1785 1749 1786 /* … … 1756 1793 if (cMillies) 1757 1794 { 1795 int cMilliesWait = cMillies == RT_INDEFINITE_WAIT ? -1 : cMillies; 1758 1796 1759 1797 for (;;) 1760 1798 { 1761 struct pollfd pfd; 1762 pfd.fd = RTFileToNative(pDevLnx->hFile); 1763 pfd.events = POLLOUT | POLLWRNORM /* completed async */ 1764 | POLLERR | POLLHUP /* disconnected */; 1765 pfd.revents = 0; 1766 int rc = poll(&pfd, 1, cMillies); 1799 struct pollfd pfd[2]; 1800 pfd[0].fd = RTFileToNative(pDevLnx->hFile); 1801 pfd[0].events = POLLOUT | POLLWRNORM /* completed async */ 1802 | POLLERR | POLLHUP /* disconnected */; 1803 pfd[0].revents = 0; 1804 1805 pfd[1].fd = RTPipeToNative(pDevLnx->hPipeWakeupR); 1806 pfd[1].events = POLLIN | POLLHUP; 1807 pfd[1].revents = 0; 1808 1809 int rc = poll(&pfd[0], 2, cMilliesWait); 1767 1810 Log(("usbProxyLinuxUrbReap: poll rc = %d\n", rc)); 1768 1811 if (rc >= 1) 1812 { 1813 /* If the pipe caused the return drain it. */ 1814 if (pfd[1].revents & POLLIN) 1815 { 1816 uint8_t bRead; 1817 size_t cbIgnored = 0; 1818 RTPipeRead(pDevLnx->hPipeWakeupR, &bRead, 1, &cbIgnored); 1819 } 1769 1820 break; 1821 } 1770 1822 if (rc >= 0 /*|| errno == ETIMEOUT*/) 1771 1823 { … … 1947 1999 1948 2000 2001 static DECLCALLBACK(int) usbProxyLinuxWakeup(PUSBPROXYDEV pProxyDev) 2002 { 2003 PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv; 2004 size_t cbIgnored; 2005 2006 LogFlowFunc(("pProxyDev=%p\n", pProxyDev)); 2007 2008 return RTPipeWrite(pDevLnx->hPipeWakeupW, "", 1, &cbIgnored); 2009 } 2010 1949 2011 /** 1950 2012 * The Linux USB Proxy Backend. … … 1965 2027 usbProxyLinuxUrbCancel, 1966 2028 usbProxyLinuxUrbReap, 2029 usbProxyLinuxWakeup, 1967 2030 0 1968 2031 };
Note:
See TracChangeset
for help on using the changeset viewer.