diff options
Diffstat (limited to 'include/libusb-1.0/os/poll_windows.h')
| -rw-r--r-- | include/libusb-1.0/os/poll_windows.h | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/include/libusb-1.0/os/poll_windows.h b/include/libusb-1.0/os/poll_windows.h deleted file mode 100644 index a9e3e90..0000000 --- a/include/libusb-1.0/os/poll_windows.h +++ /dev/null | |||
| @@ -1,120 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Windows compat: POSIX compatibility wrapper | ||
| 3 | * Copyright (C) 2009-2010 Pete Batard <pbatard@gmail.com> | ||
| 4 | * With contributions from Michael Plante, Orin Eman et al. | ||
| 5 | * Parts of poll implementation from libusb-win32, by Stephan Meyer et al. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | * | ||
| 21 | */ | ||
| 22 | #pragma once | ||
| 23 | |||
| 24 | #if defined(_MSC_VER) | ||
| 25 | // disable /W4 MSVC warnings that are benign | ||
| 26 | #pragma warning(disable:4127) // conditional expression is constant | ||
| 27 | #endif | ||
| 28 | |||
| 29 | // Uncomment to have poll return with EINTR as soon as a new transfer (fd) is added | ||
| 30 | // This should result in a LIBUSB_ERROR_INTERRUPTED being returned by libusb calls, | ||
| 31 | // which should give the app an opportunity to resubmit a new fd set. | ||
| 32 | //#define DYNAMIC_FDS | ||
| 33 | |||
| 34 | // Handle synchronous completion through the overlapped structure | ||
| 35 | #if !defined(STATUS_REPARSE) // reuse the REPARSE status code | ||
| 36 | #define STATUS_REPARSE ((LONG)0x00000104L) | ||
| 37 | #endif | ||
| 38 | #define STATUS_COMPLETED_SYNCHRONOUSLY STATUS_REPARSE | ||
| 39 | #define HasOverlappedIoCompletedSync(lpOverlapped) (((DWORD)(lpOverlapped)->Internal) == STATUS_COMPLETED_SYNCHRONOUSLY) | ||
| 40 | |||
| 41 | enum windows_version { | ||
| 42 | WINDOWS_UNSUPPORTED, | ||
| 43 | WINDOWS_XP, | ||
| 44 | WINDOWS_2003, // also includes XP 64 | ||
| 45 | WINDOWS_VISTA_AND_LATER, | ||
| 46 | }; | ||
| 47 | extern enum windows_version windows_version; | ||
| 48 | |||
| 49 | #define MAX_FDS 256 | ||
| 50 | |||
| 51 | #define POLLIN 0x0001 /* There is data to read */ | ||
| 52 | #define POLLPRI 0x0002 /* There is urgent data to read */ | ||
| 53 | #define POLLOUT 0x0004 /* Writing now will not block */ | ||
| 54 | #define POLLERR 0x0008 /* Error condition */ | ||
| 55 | #define POLLHUP 0x0010 /* Hung up */ | ||
| 56 | #define POLLNVAL 0x0020 /* Invalid request: fd not open */ | ||
| 57 | |||
| 58 | struct pollfd { | ||
| 59 | int fd; /* file descriptor */ | ||
| 60 | short events; /* requested events */ | ||
| 61 | short revents; /* returned events */ | ||
| 62 | }; | ||
| 63 | |||
| 64 | typedef unsigned int nfds_t; | ||
| 65 | |||
| 66 | // access modes | ||
| 67 | enum rw_type { | ||
| 68 | RW_NONE, | ||
| 69 | RW_READ, | ||
| 70 | RW_WRITE, | ||
| 71 | }; | ||
| 72 | |||
| 73 | // fd struct that can be used for polling on Windows | ||
| 74 | struct winfd { | ||
| 75 | int fd; // what's exposed to libusb core | ||
| 76 | HANDLE handle; // what we need to attach overlapped to the I/O op, so we can poll it | ||
| 77 | OVERLAPPED* overlapped; // what will report our I/O status | ||
| 78 | enum rw_type rw; // I/O transfer direction: read *XOR* write (NOT BOTH) | ||
| 79 | }; | ||
| 80 | extern const struct winfd INVALID_WINFD; | ||
| 81 | |||
| 82 | int usbi_pipe(int pipefd[2]); | ||
| 83 | int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout); | ||
| 84 | ssize_t usbi_write(int fd, const void *buf, size_t count); | ||
| 85 | ssize_t usbi_read(int fd, void *buf, size_t count); | ||
| 86 | int usbi_close(int fd); | ||
| 87 | |||
| 88 | void init_polling(void); | ||
| 89 | void exit_polling(void); | ||
| 90 | struct winfd usbi_create_fd(HANDLE handle, int access_mode); | ||
| 91 | void usbi_free_fd(int fd); | ||
| 92 | struct winfd fd_to_winfd(int fd); | ||
| 93 | struct winfd handle_to_winfd(HANDLE handle); | ||
| 94 | struct winfd overlapped_to_winfd(OVERLAPPED* overlapped); | ||
| 95 | |||
| 96 | /* | ||
| 97 | * Timeval operations | ||
| 98 | */ | ||
| 99 | #if defined(DDKBUILD) | ||
| 100 | #include <winsock.h> // defines timeval functions on DDK | ||
| 101 | #endif | ||
| 102 | |||
| 103 | #if !defined(TIMESPEC_TO_TIMEVAL) | ||
| 104 | #define TIMESPEC_TO_TIMEVAL(tv, ts) { \ | ||
| 105 | (tv)->tv_sec = (long)(ts)->tv_sec; \ | ||
| 106 | (tv)->tv_usec = (long)(ts)->tv_nsec / 1000; \ | ||
| 107 | } | ||
| 108 | #endif | ||
| 109 | #if !defined(timersub) | ||
| 110 | #define timersub(a, b, result) \ | ||
| 111 | do { \ | ||
| 112 | (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ | ||
| 113 | (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ | ||
| 114 | if ((result)->tv_usec < 0) { \ | ||
| 115 | --(result)->tv_sec; \ | ||
| 116 | (result)->tv_usec += 1000000; \ | ||
| 117 | } \ | ||
| 118 | } while (0) | ||
| 119 | #endif | ||
| 120 | |||
