Fix issue 1) not recognizes some usb device, 2) reconnect when ffmpeg encoder error
[rtmpclient.git] / app / src / main / jni / libusb-1.0.22 / libusb / os / poll_windows.h
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 MAX_FDS     256
45
46 #define POLLIN      0x0001    /* There is data to read */
47 #define POLLPRI     0x0002    /* There is urgent data to read */
48 #define POLLOUT     0x0004    /* Writing now will not block */
49 #define POLLERR     0x0008    /* Error condition */
50 #define POLLHUP     0x0010    /* Hung up */
51 #define POLLNVAL    0x0020    /* Invalid request: fd not open */
52
53 struct pollfd {
54         int fd;         /* file descriptor */
55         short events;   /* requested events */
56         short revents;  /* returned events */
57 };
58
59 struct winfd {
60         int fd;                         // what's exposed to libusb core
61         OVERLAPPED *overlapped;         // what will report our I/O status
62 };
63
64 extern const struct winfd INVALID_WINFD;
65
66 struct winfd usbi_create_fd(void);
67
68 int usbi_pipe(int pipefd[2]);
69 int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout);
70 ssize_t usbi_write(int fd, const void *buf, size_t count);
71 ssize_t usbi_read(int fd, void *buf, size_t count);
72 int usbi_close(int fd);
73
74 /*
75  * Timeval operations
76  */
77 #if defined(DDKBUILD)
78 #include <winsock.h>    // defines timeval functions on DDK
79 #endif
80
81 #if !defined(TIMESPEC_TO_TIMEVAL)
82 #define TIMESPEC_TO_TIMEVAL(tv, ts) {                   \
83         (tv)->tv_sec = (long)(ts)->tv_sec;                  \
84         (tv)->tv_usec = (long)(ts)->tv_nsec / 1000;         \
85 }
86 #endif
87 #if !defined(timersub)
88 #define timersub(a, b, result)                          \
89 do {                                                    \
90         (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;       \
91         (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;    \
92         if ((result)->tv_usec < 0) {                        \
93                 --(result)->tv_sec;                             \
94                 (result)->tv_usec += 1000000;                   \
95         }                                                   \
96 } while (0)
97 #endif