usb 2.1.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/README.md +20 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/usb/bindings.d.ts +4 -0
- package/dist/usb/device.js +5 -0
- package/dist/usb/device.js.map +1 -1
- package/dist/usb/index.js +7 -16
- package/dist/usb/index.js.map +1 -1
- package/dist/webusb/webusb-device.d.ts +2 -1
- package/dist/webusb/webusb-device.js +21 -14
- package/dist/webusb/webusb-device.js.map +1 -1
- package/libusb/.gitattributes +2 -6
- package/libusb/.private/appveyor_build.sh +22 -0
- package/libusb/.private/bm.sh +1 -1
- package/libusb/.private/ci-build.sh +67 -0
- package/libusb/.private/ci-container-build.sh +70 -0
- package/libusb/.private/post-rewrite.sh +5 -1
- package/libusb/.private/pre-commit.sh +5 -1
- package/libusb/.private/wbs.txt +4 -19
- package/libusb/.travis.yml +32 -23
- package/libusb/AUTHORS +86 -3
- package/libusb/ChangeLog +54 -3
- package/libusb/INSTALL_WIN.txt +22 -44
- package/libusb/Makefile.am +32 -10
- package/libusb/{README.md → README} +2 -2
- package/libusb/README.git +3 -3
- package/libusb/Xcode/common.xcconfig +23 -19
- package/libusb/Xcode/config.h +25 -13
- package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +511 -109
- package/libusb/android/README +90 -54
- package/libusb/android/config.h +23 -43
- package/libusb/android/examples/unrooted_android.c +300 -0
- package/libusb/android/examples/unrooted_android.h +36 -0
- package/libusb/android/jni/Android.mk +1 -1
- package/libusb/android/jni/Application.mk +16 -0
- package/libusb/android/jni/examples.mk +63 -29
- package/libusb/android/jni/libusb.mk +14 -8
- package/libusb/android/jni/tests.mk +13 -24
- package/libusb/appveyor.yml +73 -30
- package/libusb/autogen.sh +5 -3
- package/libusb/bootstrap.sh +6 -2
- package/libusb/configure.ac +314 -227
- package/libusb/doc/Makefile.in +22 -0
- package/libusb/doc/doxygen.cfg.in +460 -223
- package/libusb/examples/Makefile.am +6 -13
- package/libusb/examples/dpfp.c +276 -73
- package/libusb/examples/ezusb.c +18 -8
- package/libusb/examples/ezusb.h +6 -17
- package/libusb/examples/fxload.c +4 -5
- package/libusb/examples/hotplugtest.c +1 -1
- package/libusb/examples/sam3u_benchmark.c +59 -24
- package/libusb/examples/testlibusb.c +138 -104
- package/libusb/examples/xusb.c +26 -22
- package/libusb/libusb/Makefile.am +57 -70
- package/libusb/libusb/Makefile.am.extra +26 -0
- package/libusb/libusb/core.c +432 -423
- package/libusb/libusb/descriptor.c +365 -419
- package/libusb/libusb/hotplug.c +200 -104
- package/libusb/libusb/io.c +522 -535
- package/libusb/libusb/libusb-1.0.def +7 -3
- package/libusb/libusb/libusb-1.0.rc +1 -9
- package/libusb/libusb/libusb.h +302 -226
- package/libusb/libusb/libusbi.h +607 -316
- package/libusb/libusb/os/darwin_usb.c +703 -329
- package/libusb/libusb/os/darwin_usb.h +39 -15
- package/libusb/libusb/os/events_posix.c +300 -0
- package/libusb/libusb/os/events_posix.h +59 -0
- package/libusb/libusb/os/events_windows.c +214 -0
- package/libusb/{msvc/missing.h → libusb/os/events_windows.h} +25 -11
- package/libusb/libusb/os/haiku_pollfs.cpp +14 -9
- package/libusb/libusb/os/haiku_usb.h +12 -12
- package/libusb/libusb/os/haiku_usb_backend.cpp +36 -37
- package/libusb/libusb/os/haiku_usb_raw.cpp +80 -116
- package/libusb/libusb/os/linux_netlink.c +55 -63
- package/libusb/libusb/os/linux_udev.c +61 -69
- package/libusb/libusb/os/linux_usbfs.c +926 -1015
- package/libusb/libusb/os/linux_usbfs.h +74 -57
- package/libusb/libusb/os/netbsd_usb.c +103 -168
- package/libusb/libusb/os/null_usb.c +111 -0
- package/libusb/libusb/os/openbsd_usb.c +71 -120
- package/libusb/libusb/os/sunos_usb.c +289 -375
- package/libusb/libusb/os/sunos_usb.h +0 -1
- package/libusb/libusb/os/threads_posix.c +81 -32
- package/libusb/libusb/os/threads_posix.h +19 -23
- package/libusb/libusb/os/threads_windows.c +9 -95
- package/libusb/libusb/os/threads_windows.h +33 -31
- package/libusb/libusb/os/windows_common.c +915 -0
- package/libusb/libusb/os/windows_common.h +330 -42
- package/libusb/libusb/os/windows_usbdk.c +161 -267
- package/libusb/libusb/os/windows_usbdk.h +5 -2
- package/libusb/libusb/os/windows_winusb.c +1355 -1192
- package/libusb/libusb/os/windows_winusb.h +167 -167
- package/libusb/libusb/strerror.c +20 -30
- package/libusb/libusb/sync.c +20 -21
- package/libusb/libusb/version.h +1 -1
- package/libusb/libusb/version_nano.h +1 -1
- package/libusb/msvc/.gitattributes +3 -0
- package/libusb/msvc/config.h +27 -20
- package/libusb/msvc/{hotplugtest_2012.vcxproj → dpfp_2013.vcxproj} +14 -10
- package/libusb/msvc/dpfp_2013.vcxproj.filters +26 -0
- package/libusb/msvc/{listdevs_2010.vcxproj → dpfp_2015.vcxproj} +14 -9
- package/libusb/msvc/dpfp_2015.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_2017.vcxproj +106 -0
- package/libusb/msvc/dpfp_2017.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_2019.vcxproj +106 -0
- package/libusb/msvc/dpfp_2019.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_threaded_2013.vcxproj +87 -0
- package/libusb/msvc/dpfp_threaded_2013.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_threaded_2015.vcxproj +87 -0
- package/libusb/msvc/dpfp_threaded_2015.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_threaded_2017.vcxproj +106 -0
- package/libusb/msvc/dpfp_threaded_2017.vcxproj.filters +26 -0
- package/libusb/msvc/{fxload_2012.vcxproj → dpfp_threaded_2019.vcxproj} +32 -17
- package/libusb/msvc/dpfp_threaded_2019.vcxproj.filters +26 -0
- package/libusb/msvc/fxload_2013.vcxproj +6 -3
- package/libusb/msvc/fxload_2013.vcxproj.filters +35 -0
- package/libusb/msvc/fxload_2015.vcxproj +6 -3
- package/libusb/msvc/fxload_2015.vcxproj.filters +35 -0
- package/libusb/msvc/fxload_2017.vcxproj +6 -7
- package/libusb/msvc/fxload_2017.vcxproj.filters +35 -0
- package/libusb/msvc/{fxload_2010.vcxproj → fxload_2019.vcxproj} +29 -6
- package/libusb/msvc/fxload_2019.vcxproj.filters +35 -0
- package/libusb/{examples → msvc}/getopt/getopt.c +0 -0
- package/libusb/{examples → msvc}/getopt/getopt.h +0 -0
- package/libusb/{examples → msvc}/getopt/getopt1.c +0 -0
- package/libusb/msvc/getopt_2013.vcxproj +4 -5
- package/libusb/msvc/getopt_2013.vcxproj.filters +26 -0
- package/libusb/msvc/getopt_2015.vcxproj +4 -4
- package/libusb/msvc/getopt_2015.vcxproj.filters +26 -0
- package/libusb/msvc/getopt_2017.vcxproj +4 -10
- package/libusb/msvc/getopt_2017.vcxproj.filters +26 -0
- package/libusb/msvc/{getopt_2012.vcxproj → getopt_2019.vcxproj} +25 -6
- package/libusb/msvc/getopt_2019.vcxproj.filters +26 -0
- package/libusb/msvc/hotplugtest_2013.vcxproj +6 -3
- package/libusb/msvc/hotplugtest_2013.vcxproj.filters +23 -0
- package/libusb/msvc/hotplugtest_2015.vcxproj +6 -3
- package/libusb/msvc/hotplugtest_2015.vcxproj.filters +23 -0
- package/libusb/msvc/hotplugtest_2017.vcxproj +6 -7
- package/libusb/msvc/hotplugtest_2017.vcxproj.filters +23 -0
- package/libusb/msvc/hotplugtest_2019.vcxproj +105 -0
- package/libusb/msvc/hotplugtest_2019.vcxproj.filters +23 -0
- package/libusb/msvc/libusb_2013.sln +50 -20
- package/libusb/msvc/libusb_2015.sln +51 -21
- package/libusb/msvc/libusb_2017.sln +90 -36
- package/libusb/msvc/libusb_2019.sln +240 -0
- package/libusb/msvc/libusb_dll_2013.vcxproj +6 -9
- package/libusb/msvc/libusb_dll_2013.vcxproj.filters +94 -0
- package/libusb/msvc/libusb_dll_2015.vcxproj +6 -8
- package/libusb/msvc/libusb_dll_2015.vcxproj.filters +94 -0
- package/libusb/msvc/libusb_dll_2017.vcxproj +6 -16
- package/libusb/msvc/libusb_dll_2017.vcxproj.filters +94 -0
- package/libusb/msvc/{libusb_dll_2010.vcxproj → libusb_dll_2019.vcxproj} +27 -9
- package/libusb/msvc/libusb_dll_2019.vcxproj.filters +94 -0
- package/libusb/msvc/libusb_static_2013.vcxproj +5 -9
- package/libusb/msvc/libusb_static_2013.vcxproj.filters +80 -0
- package/libusb/msvc/libusb_static_2015.vcxproj +5 -8
- package/libusb/msvc/libusb_static_2015.vcxproj.filters +80 -0
- package/libusb/msvc/libusb_static_2017.vcxproj +5 -8
- package/libusb/msvc/libusb_static_2017.vcxproj.filters +80 -0
- package/libusb/msvc/{libusb_static_2010.vcxproj → libusb_static_2019.vcxproj} +26 -9
- package/libusb/msvc/libusb_static_2019.vcxproj.filters +80 -0
- package/libusb/msvc/listdevs_2013.vcxproj +6 -3
- package/libusb/msvc/listdevs_2013.vcxproj.filters +23 -0
- package/libusb/msvc/listdevs_2015.vcxproj +6 -3
- package/libusb/msvc/listdevs_2015.vcxproj.filters +23 -0
- package/libusb/msvc/listdevs_2017.vcxproj +6 -7
- package/libusb/msvc/listdevs_2017.vcxproj.filters +23 -0
- package/libusb/msvc/listdevs_2019.vcxproj +105 -0
- package/libusb/msvc/listdevs_2019.vcxproj.filters +23 -0
- package/libusb/msvc/{listdevs_2012.vcxproj → sam3u_benchmark_2013.vcxproj} +13 -9
- package/libusb/msvc/sam3u_benchmark_2013.vcxproj.filters +26 -0
- package/libusb/msvc/{hotplugtest_2010.vcxproj → sam3u_benchmark_2015.vcxproj} +13 -8
- package/libusb/msvc/sam3u_benchmark_2015.vcxproj.filters +26 -0
- package/libusb/msvc/sam3u_benchmark_2017.vcxproj +106 -0
- package/libusb/msvc/sam3u_benchmark_2017.vcxproj.filters +26 -0
- package/libusb/msvc/sam3u_benchmark_2019.vcxproj +106 -0
- package/libusb/msvc/sam3u_benchmark_2019.vcxproj.filters +26 -0
- package/libusb/msvc/stress_2013.vcxproj +4 -2
- package/libusb/msvc/stress_2013.vcxproj.filters +32 -0
- package/libusb/msvc/stress_2015.vcxproj +4 -2
- package/libusb/msvc/stress_2015.vcxproj.filters +32 -0
- package/libusb/msvc/stress_2017.vcxproj +4 -6
- package/libusb/msvc/stress_2017.vcxproj.filters +32 -0
- package/libusb/msvc/{stress_2010.vcxproj → stress_2019.vcxproj} +26 -4
- package/libusb/msvc/stress_2019.vcxproj.filters +32 -0
- package/libusb/msvc/testlibusb_2013.vcxproj +6 -3
- package/libusb/msvc/testlibusb_2013.vcxproj.filters +23 -0
- package/libusb/msvc/testlibusb_2015.vcxproj +6 -3
- package/libusb/msvc/testlibusb_2015.vcxproj.filters +23 -0
- package/libusb/msvc/testlibusb_2017.vcxproj +6 -7
- package/libusb/msvc/testlibusb_2017.vcxproj.filters +23 -0
- package/libusb/msvc/{testlibusb_2010.vcxproj → testlibusb_2019.vcxproj} +28 -5
- package/libusb/msvc/testlibusb_2019.vcxproj.filters +23 -0
- package/libusb/msvc/xusb_2013.vcxproj +6 -3
- package/libusb/msvc/xusb_2013.vcxproj.filters +23 -0
- package/libusb/msvc/xusb_2015.vcxproj +6 -3
- package/libusb/msvc/xusb_2015.vcxproj.filters +23 -0
- package/libusb/msvc/xusb_2017.vcxproj +6 -7
- package/libusb/msvc/xusb_2017.vcxproj.filters +23 -0
- package/libusb/msvc/{xusb_2010.vcxproj → xusb_2019.vcxproj} +28 -5
- package/libusb/msvc/xusb_2019.vcxproj.filters +23 -0
- package/libusb/tests/Makefile.am +13 -1
- package/libusb/tests/libusb_testlib.h +12 -43
- package/libusb/tests/stress.c +59 -50
- package/libusb/tests/testlib.c +78 -171
- package/libusb/tests/umockdev.c +1175 -0
- package/libusb.gypi +10 -11
- package/package.json +2 -2
- package/prebuilds/android-arm/node.napi.armv7.node +0 -0
- package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
- package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/linux-ia32/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
- package/prebuilds/linux-x64/node.napi.musl.node +0 -0
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/device.cc +12 -7
- package/src/node_usb.cc +10 -0
- package/test/usb.coffee +6 -0
- package/tsc/index.ts +2 -0
- package/tsc/usb/bindings.ts +5 -0
- package/tsc/usb/device.ts +6 -0
- package/tsc/usb/index.ts +5 -8
- package/tsc/webusb/webusb-device.ts +12 -8
- package/libusb/.private/bd.cmd +0 -89
- package/libusb/.private/bwince.cmd +0 -57
- package/libusb/.private/wbs_wince.txt +0 -42
- package/libusb/Brewfile +0 -4
- package/libusb/appveyor_cygwin.bat +0 -11
- package/libusb/appveyor_minGW.bat +0 -19
- package/libusb/doc/Makefile.am +0 -9
- package/libusb/examples/dpfp_threaded.c +0 -557
- package/libusb/libusb/hotplug.h +0 -99
- package/libusb/libusb/os/poll_posix.c +0 -84
- package/libusb/libusb/os/poll_posix.h +0 -14
- package/libusb/libusb/os/poll_windows.c +0 -447
- package/libusb/libusb/os/poll_windows.h +0 -98
- package/libusb/libusb/os/wince_usb.c +0 -888
- package/libusb/libusb/os/wince_usb.h +0 -126
- package/libusb/libusb/os/windows_nt_common.c +0 -1010
- package/libusb/libusb/os/windows_nt_common.h +0 -110
- package/libusb/libusb/os/windows_nt_shared_types.h +0 -147
- package/libusb/msvc/appveyor.bat +0 -27
- package/libusb/msvc/ddk_build.cmd +0 -219
- package/libusb/msvc/errno.h +0 -102
- package/libusb/msvc/fxload_sources +0 -23
- package/libusb/msvc/getopt_2005.vcproj +0 -288
- package/libusb/msvc/getopt_2010.vcxproj +0 -72
- package/libusb/msvc/getopt_sources +0 -24
- package/libusb/msvc/hotplugtest_sources +0 -20
- package/libusb/msvc/inttypes.h +0 -295
- package/libusb/msvc/libusb.dsw +0 -71
- package/libusb/msvc/libusb_2005.sln +0 -95
- package/libusb/msvc/libusb_2010.sln +0 -105
- package/libusb/msvc/libusb_2012.sln +0 -105
- package/libusb/msvc/libusb_dll.dsp +0 -194
- package/libusb/msvc/libusb_dll_2005.vcproj +0 -464
- package/libusb/msvc/libusb_dll_2012.vcxproj +0 -107
- package/libusb/msvc/libusb_dll_wince.vcproj +0 -1251
- package/libusb/msvc/libusb_sources +0 -43
- package/libusb/msvc/libusb_static.dsp +0 -174
- package/libusb/msvc/libusb_static_2005.vcproj +0 -390
- package/libusb/msvc/libusb_static_2012.vcxproj +0 -98
- package/libusb/msvc/libusb_static_wince.vcproj +0 -1179
- package/libusb/msvc/libusb_wince.sln +0 -246
- package/libusb/msvc/listdevs.dsp +0 -103
- package/libusb/msvc/listdevs_2005.vcproj +0 -360
- package/libusb/msvc/listdevs_sources +0 -20
- package/libusb/msvc/listdevs_wince.vcproj +0 -1120
- package/libusb/msvc/missing.c +0 -80
- package/libusb/msvc/stdint.h +0 -256
- package/libusb/msvc/stress_2005.vcproj +0 -390
- package/libusb/msvc/stress_2012.vcxproj +0 -87
- package/libusb/msvc/stress_sources +0 -21
- package/libusb/msvc/stress_wince.vcproj +0 -1128
- package/libusb/msvc/testlibusb_2012.vcxproj +0 -83
- package/libusb/msvc/testlibusb_sources +0 -20
- package/libusb/msvc/xusb.dsp +0 -102
- package/libusb/msvc/xusb_2005.vcproj +0 -344
- package/libusb/msvc/xusb_2012.vcxproj +0 -83
- package/libusb/msvc/xusb_sources +0 -20
- package/libusb/msvc/xusb_wince.vcproj +0 -1120
- package/libusb/travis-autogen.sh +0 -39
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* poll_posix: poll compatibility wrapper for POSIX systems
|
|
3
|
-
* Copyright © 2013 RealVNC Ltd.
|
|
4
|
-
*
|
|
5
|
-
* This library is free software; you can redistribute it and/or
|
|
6
|
-
* modify it under the terms of the GNU Lesser General Public
|
|
7
|
-
* License as published by the Free Software Foundation; either
|
|
8
|
-
* version 2.1 of the License, or (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This library is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
-
* Lesser General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU Lesser General Public
|
|
16
|
-
* License along with this library; if not, write to the Free Software
|
|
17
|
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
#include <config.h>
|
|
22
|
-
|
|
23
|
-
#include <unistd.h>
|
|
24
|
-
#include <fcntl.h>
|
|
25
|
-
#include <errno.h>
|
|
26
|
-
#include <stdlib.h>
|
|
27
|
-
|
|
28
|
-
#include "libusbi.h"
|
|
29
|
-
|
|
30
|
-
int usbi_pipe(int pipefd[2])
|
|
31
|
-
{
|
|
32
|
-
#if defined(HAVE_PIPE2)
|
|
33
|
-
int ret = pipe2(pipefd, O_CLOEXEC);
|
|
34
|
-
#else
|
|
35
|
-
int ret = pipe(pipefd);
|
|
36
|
-
#endif
|
|
37
|
-
|
|
38
|
-
if (ret != 0) {
|
|
39
|
-
usbi_err(NULL, "failed to create pipe (%d)", errno);
|
|
40
|
-
return ret;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
#if !defined(HAVE_PIPE2) && defined(FD_CLOEXEC)
|
|
44
|
-
ret = fcntl(pipefd[0], F_GETFD);
|
|
45
|
-
if (ret == -1) {
|
|
46
|
-
usbi_err(NULL, "failed to get pipe fd flags (%d)", errno);
|
|
47
|
-
goto err_close_pipe;
|
|
48
|
-
}
|
|
49
|
-
ret = fcntl(pipefd[0], F_SETFD, ret | FD_CLOEXEC);
|
|
50
|
-
if (ret == -1) {
|
|
51
|
-
usbi_err(NULL, "failed to set pipe fd flags (%d)", errno);
|
|
52
|
-
goto err_close_pipe;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
ret = fcntl(pipefd[1], F_GETFD);
|
|
56
|
-
if (ret == -1) {
|
|
57
|
-
usbi_err(NULL, "failed to get pipe fd flags (%d)", errno);
|
|
58
|
-
goto err_close_pipe;
|
|
59
|
-
}
|
|
60
|
-
ret = fcntl(pipefd[1], F_SETFD, ret | FD_CLOEXEC);
|
|
61
|
-
if (ret == -1) {
|
|
62
|
-
usbi_err(NULL, "failed to set pipe fd flags (%d)", errno);
|
|
63
|
-
goto err_close_pipe;
|
|
64
|
-
}
|
|
65
|
-
#endif
|
|
66
|
-
|
|
67
|
-
ret = fcntl(pipefd[1], F_GETFL);
|
|
68
|
-
if (ret == -1) {
|
|
69
|
-
usbi_err(NULL, "failed to get pipe fd status flags (%d)", errno);
|
|
70
|
-
goto err_close_pipe;
|
|
71
|
-
}
|
|
72
|
-
ret = fcntl(pipefd[1], F_SETFL, ret | O_NONBLOCK);
|
|
73
|
-
if (ret == -1) {
|
|
74
|
-
usbi_err(NULL, "failed to set pipe fd status flags (%d)", errno);
|
|
75
|
-
goto err_close_pipe;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return 0;
|
|
79
|
-
|
|
80
|
-
err_close_pipe:
|
|
81
|
-
close(pipefd[0]);
|
|
82
|
-
close(pipefd[1]);
|
|
83
|
-
return ret;
|
|
84
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#ifndef LIBUSB_POLL_POSIX_H
|
|
2
|
-
#define LIBUSB_POLL_POSIX_H
|
|
3
|
-
|
|
4
|
-
#define usbi_write write
|
|
5
|
-
#define usbi_read read
|
|
6
|
-
#define usbi_close close
|
|
7
|
-
#define usbi_poll poll
|
|
8
|
-
|
|
9
|
-
int usbi_pipe(int pipefd[2]);
|
|
10
|
-
|
|
11
|
-
#define usbi_inc_fds_ref(x, y)
|
|
12
|
-
#define usbi_dec_fds_ref(x, y)
|
|
13
|
-
|
|
14
|
-
#endif /* LIBUSB_POLL_POSIX_H */
|
|
@@ -1,447 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* poll_windows: poll compatibility wrapper for Windows
|
|
3
|
-
* Copyright © 2017 Chris Dickens <christopher.a.dickens@gmail.com>
|
|
4
|
-
*
|
|
5
|
-
* This library is free software; you can redistribute it and/or
|
|
6
|
-
* modify it under the terms of the GNU Lesser General Public
|
|
7
|
-
* License as published by the Free Software Foundation; either
|
|
8
|
-
* version 2.1 of the License, or (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This library is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13
|
-
* Lesser General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU Lesser General Public
|
|
16
|
-
* License along with this library; if not, write to the Free Software
|
|
17
|
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/*
|
|
22
|
-
* poll() and pipe() Windows compatibility layer for libusb 1.0
|
|
23
|
-
*
|
|
24
|
-
* The way this layer works is by using OVERLAPPED with async I/O transfers, as
|
|
25
|
-
* OVERLAPPED have an associated event which is flagged for I/O completion.
|
|
26
|
-
*
|
|
27
|
-
* For USB pollable async I/O, you would typically:
|
|
28
|
-
* - obtain a Windows HANDLE to a file or device that has been opened in
|
|
29
|
-
* OVERLAPPED mode
|
|
30
|
-
* - call usbi_create_fd with this handle to obtain a custom fd.
|
|
31
|
-
* - leave the core functions call the poll routine and flag POLLIN/POLLOUT
|
|
32
|
-
*
|
|
33
|
-
* The pipe pollable synchronous I/O works using the overlapped event associated
|
|
34
|
-
* with a fake pipe. The read/write functions are only meant to be used in that
|
|
35
|
-
* context.
|
|
36
|
-
*/
|
|
37
|
-
#include <config.h>
|
|
38
|
-
|
|
39
|
-
#include <assert.h>
|
|
40
|
-
#include <errno.h>
|
|
41
|
-
#include <stdlib.h>
|
|
42
|
-
|
|
43
|
-
#include "libusbi.h"
|
|
44
|
-
#include "windows_common.h"
|
|
45
|
-
|
|
46
|
-
// public fd data
|
|
47
|
-
const struct winfd INVALID_WINFD = { -1, NULL };
|
|
48
|
-
|
|
49
|
-
// private data
|
|
50
|
-
struct file_descriptor {
|
|
51
|
-
enum fd_type { FD_TYPE_PIPE, FD_TYPE_TRANSFER } type;
|
|
52
|
-
OVERLAPPED overlapped;
|
|
53
|
-
int refcount;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
static usbi_mutex_static_t fd_table_lock = USBI_MUTEX_INITIALIZER;
|
|
57
|
-
|
|
58
|
-
static struct file_descriptor **fd_table;
|
|
59
|
-
static size_t fd_count;
|
|
60
|
-
static size_t fd_size;
|
|
61
|
-
#define INC_FDS_EACH 256
|
|
62
|
-
|
|
63
|
-
static void usbi_dec_fd_table()
|
|
64
|
-
{
|
|
65
|
-
fd_count--;
|
|
66
|
-
if (fd_count == 0) {
|
|
67
|
-
free(fd_table);
|
|
68
|
-
fd_size = 0;
|
|
69
|
-
fd_table = NULL;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
static void smart_realloc_fd_table_space(int inc)
|
|
74
|
-
{
|
|
75
|
-
if (fd_table == NULL || fd_count + inc > fd_size) {
|
|
76
|
-
struct file_descriptor **p = (struct file_descriptor **)realloc(fd_table, (fd_size + INC_FDS_EACH) * sizeof(struct file_descriptor *));
|
|
77
|
-
if (p != NULL) {
|
|
78
|
-
memset(p + fd_size, 0, INC_FDS_EACH * sizeof(struct file_descriptor *));
|
|
79
|
-
fd_size += INC_FDS_EACH;
|
|
80
|
-
fd_table = p;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
static struct file_descriptor *create_fd(enum fd_type type)
|
|
86
|
-
{
|
|
87
|
-
struct file_descriptor *fd = calloc(1, sizeof(*fd));
|
|
88
|
-
if (fd == NULL)
|
|
89
|
-
return NULL;
|
|
90
|
-
fd->overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
|
91
|
-
if (fd->overlapped.hEvent == NULL) {
|
|
92
|
-
free(fd);
|
|
93
|
-
return NULL;
|
|
94
|
-
}
|
|
95
|
-
fd->type = type;
|
|
96
|
-
fd->refcount = 1;
|
|
97
|
-
return fd;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
static void free_fd(struct file_descriptor *fd)
|
|
101
|
-
{
|
|
102
|
-
CloseHandle(fd->overlapped.hEvent);
|
|
103
|
-
free(fd);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/*
|
|
107
|
-
* Create both an fd and an OVERLAPPED, so that it can be used with our
|
|
108
|
-
* polling function
|
|
109
|
-
* The handle MUST support overlapped transfers (usually requires CreateFile
|
|
110
|
-
* with FILE_FLAG_OVERLAPPED)
|
|
111
|
-
* Return a pollable file descriptor struct, or INVALID_WINFD on error
|
|
112
|
-
*
|
|
113
|
-
* Note that the fd returned by this function is a per-transfer fd, rather
|
|
114
|
-
* than a per-session fd and cannot be used for anything else but our
|
|
115
|
-
* custom functions.
|
|
116
|
-
* if you plan to do R/W on the same handle, you MUST create 2 fds: one for
|
|
117
|
-
* read and one for write. Using a single R/W fd is unsupported and will
|
|
118
|
-
* produce unexpected results
|
|
119
|
-
*/
|
|
120
|
-
struct winfd usbi_create_fd(void)
|
|
121
|
-
{
|
|
122
|
-
struct file_descriptor *fd;
|
|
123
|
-
struct winfd wfd;
|
|
124
|
-
|
|
125
|
-
fd = create_fd(FD_TYPE_TRANSFER);
|
|
126
|
-
if (fd == NULL)
|
|
127
|
-
return INVALID_WINFD;
|
|
128
|
-
|
|
129
|
-
usbi_mutex_static_lock(&fd_table_lock);
|
|
130
|
-
|
|
131
|
-
smart_realloc_fd_table_space(1);
|
|
132
|
-
|
|
133
|
-
for (wfd.fd = 0; wfd.fd < fd_size; wfd.fd++) {
|
|
134
|
-
if (fd_table[wfd.fd] != NULL)
|
|
135
|
-
continue;
|
|
136
|
-
fd_table[wfd.fd] = fd;
|
|
137
|
-
fd_count++;
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
usbi_mutex_static_unlock(&fd_table_lock);
|
|
141
|
-
|
|
142
|
-
if (wfd.fd == fd_size) {
|
|
143
|
-
free_fd(fd);
|
|
144
|
-
return INVALID_WINFD;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
wfd.overlapped = &fd->overlapped;
|
|
148
|
-
|
|
149
|
-
return wfd;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
void usbi_inc_fds_ref(struct pollfd *fds, unsigned int nfds)
|
|
153
|
-
{
|
|
154
|
-
int n;
|
|
155
|
-
usbi_mutex_static_lock(&fd_table_lock);
|
|
156
|
-
for (n = 0; n < nfds; ++n) {
|
|
157
|
-
fd_table[fds[n].fd]->refcount++;
|
|
158
|
-
}
|
|
159
|
-
usbi_mutex_static_unlock(&fd_table_lock);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
void usbi_dec_fds_ref(struct pollfd *fds, unsigned int nfds)
|
|
163
|
-
{
|
|
164
|
-
int n;
|
|
165
|
-
struct file_descriptor *fd;
|
|
166
|
-
|
|
167
|
-
usbi_mutex_static_lock(&fd_table_lock);
|
|
168
|
-
for (n = 0; n < nfds; ++n) {
|
|
169
|
-
fd = fd_table[fds[n].fd];
|
|
170
|
-
fd->refcount--;
|
|
171
|
-
//FD_TYPE_PIPE map fd to two _fd
|
|
172
|
-
if (fd->refcount == 0 || (fd->refcount == 1 && fd->type == FD_TYPE_PIPE))
|
|
173
|
-
{
|
|
174
|
-
if (fd->type == FD_TYPE_PIPE) {
|
|
175
|
-
// InternalHigh is our reference count
|
|
176
|
-
fd->overlapped.InternalHigh--;
|
|
177
|
-
if (fd->overlapped.InternalHigh == 0)
|
|
178
|
-
free_fd(fd);
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
free_fd(fd);
|
|
182
|
-
}
|
|
183
|
-
fd_table[fds[n].fd] = NULL;
|
|
184
|
-
usbi_dec_fd_table();
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
usbi_mutex_static_unlock(&fd_table_lock);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
static int check_pollfds(struct pollfd *fds, unsigned int nfds,
|
|
192
|
-
HANDLE *wait_handles, DWORD *nb_wait_handles)
|
|
193
|
-
{
|
|
194
|
-
struct file_descriptor *fd;
|
|
195
|
-
unsigned int n;
|
|
196
|
-
int nready = 0;
|
|
197
|
-
|
|
198
|
-
usbi_mutex_static_lock(&fd_table_lock);
|
|
199
|
-
|
|
200
|
-
for (n = 0; n < nfds; ++n) {
|
|
201
|
-
fds[n].revents = 0;
|
|
202
|
-
|
|
203
|
-
// Keep it simple - only allow either POLLIN *or* POLLOUT
|
|
204
|
-
assert((fds[n].events == POLLIN) || (fds[n].events == POLLOUT));
|
|
205
|
-
if ((fds[n].events != POLLIN) && (fds[n].events != POLLOUT)) {
|
|
206
|
-
fds[n].revents = POLLNVAL;
|
|
207
|
-
nready++;
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if ((fds[n].fd >= 0) && (fds[n].fd < fd_size))
|
|
212
|
-
fd = fd_table[fds[n].fd];
|
|
213
|
-
else
|
|
214
|
-
fd = NULL;
|
|
215
|
-
|
|
216
|
-
assert(fd != NULL);
|
|
217
|
-
if (fd == NULL) {
|
|
218
|
-
fds[n].revents = POLLNVAL;
|
|
219
|
-
nready++;
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (HasOverlappedIoCompleted(&fd->overlapped)
|
|
224
|
-
&& (WaitForSingleObject(fd->overlapped.hEvent, 0) == WAIT_OBJECT_0)) {
|
|
225
|
-
fds[n].revents = fds[n].events;
|
|
226
|
-
nready++;
|
|
227
|
-
} else if (wait_handles != NULL) {
|
|
228
|
-
if (*nb_wait_handles == MAXIMUM_WAIT_OBJECTS) {
|
|
229
|
-
usbi_warn(NULL, "too many HANDLEs to wait on");
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
wait_handles[*nb_wait_handles] = fd->overlapped.hEvent;
|
|
233
|
-
(*nb_wait_handles)++;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
usbi_mutex_static_unlock(&fd_table_lock);
|
|
238
|
-
|
|
239
|
-
return nready;
|
|
240
|
-
}
|
|
241
|
-
/*
|
|
242
|
-
* POSIX poll equivalent, using Windows OVERLAPPED
|
|
243
|
-
* Currently, this function only accepts one of POLLIN or POLLOUT per fd
|
|
244
|
-
* (but you can create multiple fds from the same handle for read and write)
|
|
245
|
-
*/
|
|
246
|
-
int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout)
|
|
247
|
-
{
|
|
248
|
-
HANDLE wait_handles[MAXIMUM_WAIT_OBJECTS];
|
|
249
|
-
DWORD nb_wait_handles = 0;
|
|
250
|
-
DWORD ret;
|
|
251
|
-
int nready;
|
|
252
|
-
|
|
253
|
-
nready = check_pollfds(fds, nfds, wait_handles, &nb_wait_handles);
|
|
254
|
-
|
|
255
|
-
// If nothing was triggered, wait on all fds that require it
|
|
256
|
-
if ((nready == 0) && (nb_wait_handles != 0) && (timeout != 0)) {
|
|
257
|
-
ret = WaitForMultipleObjects(nb_wait_handles, wait_handles,
|
|
258
|
-
FALSE, (timeout < 0) ? INFINITE : (DWORD)timeout);
|
|
259
|
-
if (ret < (WAIT_OBJECT_0 + nb_wait_handles)) {
|
|
260
|
-
nready = check_pollfds(fds, nfds, NULL, NULL);
|
|
261
|
-
} else if (ret != WAIT_TIMEOUT) {
|
|
262
|
-
if (ret == WAIT_FAILED)
|
|
263
|
-
usbi_err(NULL, "WaitForMultipleObjects failed: %u", (unsigned int)GetLastError());
|
|
264
|
-
nready = -1;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return nready;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/*
|
|
272
|
-
* close a fake file descriptor
|
|
273
|
-
*/
|
|
274
|
-
int usbi_close(int _fd)
|
|
275
|
-
{
|
|
276
|
-
struct file_descriptor *fd;
|
|
277
|
-
|
|
278
|
-
if (_fd < 0 || _fd >= fd_size)
|
|
279
|
-
goto err_badfd;
|
|
280
|
-
|
|
281
|
-
usbi_mutex_static_lock(&fd_table_lock);
|
|
282
|
-
fd = fd_table[_fd];
|
|
283
|
-
fd->refcount--;
|
|
284
|
-
//FD_TYPE_PIPE map fd to two _fd
|
|
285
|
-
if(fd->refcount==0 || (fd->refcount == 1 && fd->type == FD_TYPE_PIPE))
|
|
286
|
-
{ fd_table[_fd] = NULL;
|
|
287
|
-
usbi_dec_fd_table();
|
|
288
|
-
|
|
289
|
-
if (fd->type == FD_TYPE_PIPE) {
|
|
290
|
-
// InternalHigh is our reference count
|
|
291
|
-
fd->overlapped.InternalHigh--;
|
|
292
|
-
if (fd->overlapped.InternalHigh == 0)
|
|
293
|
-
free_fd(fd);
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
free_fd(fd);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
usbi_mutex_static_unlock(&fd_table_lock);
|
|
300
|
-
|
|
301
|
-
if (fd == NULL)
|
|
302
|
-
goto err_badfd;
|
|
303
|
-
|
|
304
|
-
return 0;
|
|
305
|
-
|
|
306
|
-
err_badfd:
|
|
307
|
-
errno = EBADF;
|
|
308
|
-
return -1;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/*
|
|
312
|
-
* Create a fake pipe.
|
|
313
|
-
* As libusb only uses pipes for signaling, all we need from a pipe is an
|
|
314
|
-
* event. To that extent, we create a single wfd and overlapped as a means
|
|
315
|
-
* to access that event.
|
|
316
|
-
*/
|
|
317
|
-
int usbi_pipe(int filedes[2])
|
|
318
|
-
{
|
|
319
|
-
struct file_descriptor *fd;
|
|
320
|
-
int r_fd = -1, w_fd = -1;
|
|
321
|
-
int i;
|
|
322
|
-
|
|
323
|
-
fd = create_fd(FD_TYPE_PIPE);
|
|
324
|
-
if (fd == NULL) {
|
|
325
|
-
errno = ENOMEM;
|
|
326
|
-
return -1;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
// Use InternalHigh as a reference count
|
|
330
|
-
fd->overlapped.Internal = STATUS_PENDING;
|
|
331
|
-
fd->overlapped.InternalHigh = 2;
|
|
332
|
-
|
|
333
|
-
usbi_mutex_static_lock(&fd_table_lock);
|
|
334
|
-
do {
|
|
335
|
-
smart_realloc_fd_table_space(2);
|
|
336
|
-
|
|
337
|
-
for (i = 0; i < fd_size; i++) {
|
|
338
|
-
if (fd_table[i] != NULL)
|
|
339
|
-
continue;
|
|
340
|
-
if (r_fd == -1) {
|
|
341
|
-
r_fd = i;
|
|
342
|
-
} else if (w_fd == -1) {
|
|
343
|
-
w_fd = i;
|
|
344
|
-
break;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
if (i == fd_size)
|
|
349
|
-
break;
|
|
350
|
-
|
|
351
|
-
fd_table[r_fd] = fd;
|
|
352
|
-
fd_table[w_fd] = fd;
|
|
353
|
-
|
|
354
|
-
fd->refcount++; //this fd reference twice for r and w.
|
|
355
|
-
|
|
356
|
-
fd_count += 2;
|
|
357
|
-
|
|
358
|
-
} while (0);
|
|
359
|
-
usbi_mutex_static_unlock(&fd_table_lock);
|
|
360
|
-
|
|
361
|
-
if (i == fd_size) {
|
|
362
|
-
free_fd(fd);
|
|
363
|
-
errno = EMFILE;
|
|
364
|
-
return -1;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
filedes[0] = r_fd;
|
|
368
|
-
filedes[1] = w_fd;
|
|
369
|
-
|
|
370
|
-
return 0;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/*
|
|
374
|
-
* synchronous write for fake "pipe" signaling
|
|
375
|
-
*/
|
|
376
|
-
ssize_t usbi_write(int fd, const void *buf, size_t count)
|
|
377
|
-
{
|
|
378
|
-
int error = EBADF;
|
|
379
|
-
|
|
380
|
-
UNUSED(buf);
|
|
381
|
-
|
|
382
|
-
if (fd < 0 || fd >= fd_size)
|
|
383
|
-
goto err_out;
|
|
384
|
-
|
|
385
|
-
if (count != sizeof(unsigned char)) {
|
|
386
|
-
usbi_err(NULL, "this function should only used for signaling");
|
|
387
|
-
error = EINVAL;
|
|
388
|
-
goto err_out;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
usbi_mutex_static_lock(&fd_table_lock);
|
|
392
|
-
if ((fd_table[fd] != NULL) && (fd_table[fd]->type == FD_TYPE_PIPE)) {
|
|
393
|
-
assert(fd_table[fd]->overlapped.Internal == STATUS_PENDING);
|
|
394
|
-
assert(fd_table[fd]->overlapped.InternalHigh == 2);
|
|
395
|
-
fd_table[fd]->overlapped.Internal = STATUS_WAIT_0;
|
|
396
|
-
SetEvent(fd_table[fd]->overlapped.hEvent);
|
|
397
|
-
error = 0;
|
|
398
|
-
}
|
|
399
|
-
usbi_mutex_static_unlock(&fd_table_lock);
|
|
400
|
-
|
|
401
|
-
if (error)
|
|
402
|
-
goto err_out;
|
|
403
|
-
|
|
404
|
-
return sizeof(unsigned char);
|
|
405
|
-
|
|
406
|
-
err_out:
|
|
407
|
-
errno = error;
|
|
408
|
-
return -1;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/*
|
|
412
|
-
* synchronous read for fake "pipe" signaling
|
|
413
|
-
*/
|
|
414
|
-
ssize_t usbi_read(int fd, void *buf, size_t count)
|
|
415
|
-
{
|
|
416
|
-
int error = EBADF;
|
|
417
|
-
|
|
418
|
-
UNUSED(buf);
|
|
419
|
-
|
|
420
|
-
if (fd < 0 || fd >= fd_size)
|
|
421
|
-
goto err_out;
|
|
422
|
-
|
|
423
|
-
if (count != sizeof(unsigned char)) {
|
|
424
|
-
usbi_err(NULL, "this function should only used for signaling");
|
|
425
|
-
error = EINVAL;
|
|
426
|
-
goto err_out;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
usbi_mutex_static_lock(&fd_table_lock);
|
|
430
|
-
if ((fd_table[fd] != NULL) && (fd_table[fd]->type == FD_TYPE_PIPE)) {
|
|
431
|
-
assert(fd_table[fd]->overlapped.Internal == STATUS_WAIT_0);
|
|
432
|
-
assert(fd_table[fd]->overlapped.InternalHigh == 2);
|
|
433
|
-
fd_table[fd]->overlapped.Internal = STATUS_PENDING;
|
|
434
|
-
ResetEvent(fd_table[fd]->overlapped.hEvent);
|
|
435
|
-
error = 0;
|
|
436
|
-
}
|
|
437
|
-
usbi_mutex_static_unlock(&fd_table_lock);
|
|
438
|
-
|
|
439
|
-
if (error)
|
|
440
|
-
goto err_out;
|
|
441
|
-
|
|
442
|
-
return sizeof(unsigned char);
|
|
443
|
-
|
|
444
|
-
err_out:
|
|
445
|
-
errno = error;
|
|
446
|
-
return -1;
|
|
447
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Windows compat: POSIX compatibility wrapper
|
|
3
|
-
* Copyright © 2012-2013 RealVNC Ltd.
|
|
4
|
-
* Copyright © 2009-2010 Pete Batard <pete@akeo.ie>
|
|
5
|
-
* Copyright © 2016-2018 Chris Dickens <christopher.a.dickens@gmail.com>
|
|
6
|
-
* With contributions from Michael Plante, Orin Eman et al.
|
|
7
|
-
* Parts of poll implementation from libusb-win32, by Stephan Meyer et al.
|
|
8
|
-
*
|
|
9
|
-
* This library is free software; you can redistribute it and/or
|
|
10
|
-
* modify it under the terms of the GNU Lesser General Public
|
|
11
|
-
* License as published by the Free Software Foundation; either
|
|
12
|
-
* version 2.1 of the License, or (at your option) any later version.
|
|
13
|
-
*
|
|
14
|
-
* This library is distributed in the hope that it will be useful,
|
|
15
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17
|
-
* Lesser General Public License for more details.
|
|
18
|
-
*
|
|
19
|
-
* You should have received a copy of the GNU Lesser General Public
|
|
20
|
-
* License along with this library; if not, write to the Free Software
|
|
21
|
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
#pragma once
|
|
25
|
-
|
|
26
|
-
#if defined(_MSC_VER)
|
|
27
|
-
// disable /W4 MSVC warnings that are benign
|
|
28
|
-
#pragma warning(disable:4127) // conditional expression is constant
|
|
29
|
-
#endif
|
|
30
|
-
|
|
31
|
-
// Handle synchronous completion through the overlapped structure
|
|
32
|
-
#if !defined(STATUS_REPARSE) // reuse the REPARSE status code
|
|
33
|
-
#define STATUS_REPARSE ((LONG)0x00000104L)
|
|
34
|
-
#endif
|
|
35
|
-
#define STATUS_COMPLETED_SYNCHRONOUSLY STATUS_REPARSE
|
|
36
|
-
#if defined(_WIN32_WCE)
|
|
37
|
-
// WinCE doesn't have a HasOverlappedIoCompleted() macro, so attempt to emulate it
|
|
38
|
-
#define HasOverlappedIoCompleted(lpOverlapped) (((DWORD)(lpOverlapped)->Internal) != STATUS_PENDING)
|
|
39
|
-
#endif
|
|
40
|
-
#define HasOverlappedIoCompletedSync(lpOverlapped) (((DWORD)(lpOverlapped)->Internal) == STATUS_COMPLETED_SYNCHRONOUSLY)
|
|
41
|
-
|
|
42
|
-
#define DUMMY_HANDLE ((HANDLE)(LONG_PTR)-2)
|
|
43
|
-
|
|
44
|
-
#define POLLIN 0x0001 /* There is data to read */
|
|
45
|
-
#define POLLPRI 0x0002 /* There is urgent data to read */
|
|
46
|
-
#define POLLOUT 0x0004 /* Writing now will not block */
|
|
47
|
-
#define POLLERR 0x0008 /* Error condition */
|
|
48
|
-
#define POLLHUP 0x0010 /* Hung up */
|
|
49
|
-
#define POLLNVAL 0x0020 /* Invalid request: fd not open */
|
|
50
|
-
|
|
51
|
-
struct pollfd {
|
|
52
|
-
int fd; /* file descriptor */
|
|
53
|
-
short events; /* requested events */
|
|
54
|
-
short revents; /* returned events */
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
struct winfd {
|
|
58
|
-
int fd; // what's exposed to libusb core
|
|
59
|
-
OVERLAPPED *overlapped; // what will report our I/O status
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
extern const struct winfd INVALID_WINFD;
|
|
63
|
-
|
|
64
|
-
struct winfd usbi_create_fd(void);
|
|
65
|
-
|
|
66
|
-
int usbi_pipe(int pipefd[2]);
|
|
67
|
-
int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout);
|
|
68
|
-
ssize_t usbi_write(int fd, const void *buf, size_t count);
|
|
69
|
-
ssize_t usbi_read(int fd, void *buf, size_t count);
|
|
70
|
-
int usbi_close(int fd);
|
|
71
|
-
|
|
72
|
-
void usbi_inc_fds_ref(struct pollfd *fds, unsigned int nfds);
|
|
73
|
-
void usbi_dec_fds_ref(struct pollfd *fds, unsigned int nfds);
|
|
74
|
-
|
|
75
|
-
/*
|
|
76
|
-
* Timeval operations
|
|
77
|
-
*/
|
|
78
|
-
#if defined(DDKBUILD)
|
|
79
|
-
#include <winsock.h> // defines timeval functions on DDK
|
|
80
|
-
#endif
|
|
81
|
-
|
|
82
|
-
#if !defined(TIMESPEC_TO_TIMEVAL)
|
|
83
|
-
#define TIMESPEC_TO_TIMEVAL(tv, ts) { \
|
|
84
|
-
(tv)->tv_sec = (long)(ts)->tv_sec; \
|
|
85
|
-
(tv)->tv_usec = (long)(ts)->tv_nsec / 1000; \
|
|
86
|
-
}
|
|
87
|
-
#endif
|
|
88
|
-
#if !defined(timersub)
|
|
89
|
-
#define timersub(a, b, result) \
|
|
90
|
-
do { \
|
|
91
|
-
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
|
|
92
|
-
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
|
|
93
|
-
if ((result)->tv_usec < 0) { \
|
|
94
|
-
--(result)->tv_sec; \
|
|
95
|
-
(result)->tv_usec += 1000000; \
|
|
96
|
-
} \
|
|
97
|
-
} while (0)
|
|
98
|
-
#endif
|