- Timestamp:
- Dec 3, 2014 11:08:23 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/USB/freebsd/USBProxyDevice-freebsd.cpp
r52148 r53429 53 53 #include <iprt/string.h> 54 54 #include <iprt/file.h> 55 #include <iprt/pipe.h> 55 56 #include "../USBProxyDevice.h" 56 57 … … 96 97 /** The open file. */ 97 98 RTFILE hFile; 98 /** Software endpoint structures */99 USBENDPOINTFBSD aSwEndpoint[USBFBSD_MAXENDPOINTS];100 99 /** Flag whether an URB is cancelling. */ 101 100 bool fCancelling; 102 101 /** Flag whether initialised or not */ 103 102 bool fInit; 103 /** Pipe handle for waking up - writing end. */ 104 RTPIPE hPipeWakeupW; 105 /** Pipe handle for waking up - reading end. */ 106 RTPIPE hPipeWakeupR; 107 /** Software endpoint structures */ 108 USBENDPOINTFBSD aSwEndpoint[USBFBSD_MAXENDPOINTS]; 104 109 /** Kernel endpoint structures */ 105 110 struct usb_fs_endpoint aHwEndpoint[USBFBSD_MAXENDPOINTS]; … … 384 389 if (RT_SUCCESS(rc)) 385 390 { 386 LogFlow(("usbProxyFreeBSDOpen(%p, %s): returns successfully hFile=%RTfile iActiveCfg=%d\n", 387 pProxyDev, pszAddress, pDevFBSD->hFile, pProxyDev->iActiveCfg)); 388 389 return VINF_SUCCESS; 391 /* 392 * Create wakeup pipe. 393 */ 394 rc = RTPipeCreate(&pDevFBSD->hPipeWakeupR, &pDevFBSD->hPipeWakeupW, 0); 395 if (RT_SUCCESS(rc)) 396 { 397 LogFlow(("usbProxyFreeBSDOpen(%p, %s): returns successfully hFile=%RTfile iActiveCfg=%d\n", 398 pProxyDev, pszAddress, pDevFBSD->hFile, pProxyDev->iActiveCfg)); 399 400 return VINF_SUCCESS; 401 } 390 402 } 391 403 … … 450 462 usbProxyFreeBSDFsUnInit(pProxyDev); 451 463 464 RTPipeClose(pDevFBSD->hPipeWakeupR); 465 RTPipeClose(pDevFBSD->hPipeWakeupW); 466 452 467 RTFileClose(pDevFBSD->hFile); 453 468 pDevFBSD->hFile = NIL_RTFILE; 454 455 RTMemFree(pDevFBSD);456 pProxyDev->Backend.pv = NULL;457 469 458 470 LogFlow(("usbProxyFreeBSDClose: returns\n")); … … 689 701 690 702 ep_num = pUrb->EndPt; 691 692 if ((pUrb->enmType != VUSBXFERTYPE_MSG) && (pUrb->enmDir == VUSBDIRECTION_IN))703 if ((pUrb->enmType != VUSBXFERTYPE_MSG) && (pUrb->enmDir == VUSBDIRECTION_IN)) { 704 /* set IN-direction bit */ 693 705 ep_num |= 0x80; 706 } 694 707 695 708 index = 0; … … 823 836 PVUSBURB pUrb; 824 837 struct usb_fs_complete UsbFsComplete; 825 struct pollfd PollFd;838 struct pollfd pfd[2]; 826 839 int rc; 827 840 … … 947 960 948 961 } 949 else if (cMillies && rc == VERR_RESOURCE_BUSY) 950 { 951 /* Poll for finished transfers */ 952 PollFd.fd = RTFileToNative(pDevFBSD->hFile); 953 PollFd.events = POLLIN | POLLRDNORM; 954 PollFd.revents = 0; 955 956 rc = poll(&PollFd, 1, (cMillies == RT_INDEFINITE_WAIT) ? INFTIM : cMillies); 957 if (rc >= 1) 958 { 959 goto repeat; 960 } 961 else 962 { 963 LogFlow(("usbProxyFreeBSDUrbReap: " 964 "poll returned rc=%d\n", rc)); 965 } 962 else if (cMillies != 0 && rc == VERR_RESOURCE_BUSY) 963 { 964 for (;;) 965 { 966 pfd[0].fd = RTFileToNative(pDevFBSD->hFile); 967 pfd[0].events = POLLIN | POLLRDNORM; 968 pfd[0].revents = 0; 969 970 pfd[1].fd = RTPipeToNative(pDevFBSD->hPipeWakeupR); 971 pfd[1].events = POLLIN | POLLRDNORM; 972 pfd[1].revents = 0; 973 974 rc = poll(pfd, 2, (cMillies == RT_INDEFINITE_WAIT) ? INFTIM : cMillies); 975 if (rc > 0) 976 { 977 if (pfd[1].revents & POLLIN) 978 { 979 /* Got woken up, drain pipe. */ 980 uint8_t bRead; 981 size_t cbIgnored = 0; 982 RTPipeRead(pDevFBSD->hPipeWakeupR, &bRead, 1, &cbIgnored); 983 /* Make sure we return from this function */ 984 cMillies = 0; 985 } 986 break; 987 } 988 if (rc == 0) 989 return NULL; 990 if (errno != EAGAIN) 991 return NULL; 992 } 993 goto repeat; 966 994 } 967 995 return pUrb; … … 983 1011 LogFlow(("usbProxyFreeBSDUrbCancel: epindex=%u\n", (unsigned)index)); 984 1012 return usbProxyFreeBSDEndpointClose(pProxyDev, index); 1013 } 1014 1015 static DECLCALLBACK(int) usbProxyFreeBSDWakeup(PUSBPROXYDEV pProxyDev) 1016 { 1017 PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD); 1018 size_t cbIgnored; 1019 1020 LogFlowFunc(("pProxyDev=%p\n", pProxyDev)); 1021 1022 return RTPipeWrite(pDevFBSD->hPipeWakeupW, "", 1, &cbIgnored); 985 1023 } 986 1024 … … 993 1031 "host", 994 1032 /* cbBackend */ 995 sizeof( PUSBPROXYDEVFBSD),1033 sizeof(USBPROXYDEVFBSD), 996 1034 usbProxyFreeBSDOpen, 997 1035 usbProxyFreeBSDInit, … … 1006 1044 usbProxyFreeBSDUrbCancel, 1007 1045 usbProxyFreeBSDUrbReap, 1046 usbProxyFreeBSDWakeup, 1008 1047 0 1009 1048 };
Note:
See TracChangeset
for help on using the changeset viewer.