Project directory change
This commit is contained in:
@@ -1,167 +0,0 @@
|
||||
/* config.h. Generated from config.h.in by configure. */
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
#include "../checkm8_conf.h"
|
||||
|
||||
/* Default visibility */
|
||||
#define DEFAULT_VISIBILITY __attribute__((visibility("default")))
|
||||
|
||||
#ifdef LIBUSB_LOGGING
|
||||
/* Start with debug message logging enabled */
|
||||
#define ENABLE_DEBUG_LOGGING 1
|
||||
|
||||
/* Message logging */
|
||||
#define ENABLE_LOGGING 1
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <asm/types.h> header file. */
|
||||
/* #undef HAVE_ASM_TYPES_H */
|
||||
|
||||
/* Define to 1 if you have the declaration of `TFD_CLOEXEC', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_TFD_CLOEXEC 1
|
||||
|
||||
/* Define to 1 if you have the declaration of `TFD_NONBLOCK', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_TFD_NONBLOCK 1
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#define HAVE_DLFCN_H 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `udev' library (-ludev). */
|
||||
#define HAVE_LIBUDEV 1
|
||||
|
||||
/* Define to 1 if you have the <libudev.h> header file. */
|
||||
#define HAVE_LIBUDEV_H 1
|
||||
|
||||
/* Define to 1 if you have the <linux/netlink.h> header file. */
|
||||
/* #undef HAVE_LINUX_NETLINK_H */
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `pipe2' function. */
|
||||
#define HAVE_PIPE2 1
|
||||
|
||||
/* Define to 1 if you have the <poll.h> header file. */
|
||||
#define HAVE_POLL_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if the system has the type `struct timespec'. */
|
||||
#define HAVE_STRUCT_TIMESPEC 1
|
||||
|
||||
/* syslog() function available */
|
||||
/* #undef HAVE_SYSLOG_FUNC */
|
||||
|
||||
/* Define to 1 if you have the <syslog.h> header file. */
|
||||
/* #undef HAVE_SYSLOG_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
/* #undef HAVE_SYS_SOCKET_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to the sub-directory where libtool stores uninstalled libraries. */
|
||||
#define LT_OBJDIR ".libs/"
|
||||
|
||||
/* Darwin backend */
|
||||
/* #undef OS_DARWIN */
|
||||
|
||||
/* Haiku backend */
|
||||
/* #undef OS_HAIKU */
|
||||
|
||||
/* Linux backend */
|
||||
#define OS_LINUX 1
|
||||
|
||||
/* NetBSD backend */
|
||||
/* #undef OS_NETBSD */
|
||||
|
||||
/* OpenBSD backend */
|
||||
/* #undef OS_OPENBSD */
|
||||
|
||||
/* SunOS backend */
|
||||
/* #undef OS_SUNOS */
|
||||
|
||||
/* Windows backend */
|
||||
/* #undef OS_WINDOWS */
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "src"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "src-devel@lists.sourceforge.net"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "src"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "src 1.0.23"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "src"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL "http://src.info"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "1.0.23"
|
||||
|
||||
/* type of second poll() argument */
|
||||
#define POLL_NFDS_TYPE nfds_t
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Use POSIX Threads */
|
||||
#define THREADS_POSIX 1
|
||||
|
||||
/* timerfd headers available */
|
||||
#define USBI_TIMERFD_AVAILABLE 1
|
||||
|
||||
/* Enable output to system log */
|
||||
/* #undef USE_SYSTEM_LOGGING_FACILITY */
|
||||
|
||||
/* Use udev for device enumeration/hotplug */
|
||||
#define USE_UDEV 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "1.0.23"
|
||||
|
||||
/* Oldest Windows version supported */
|
||||
/* #undef WINVER */
|
||||
|
||||
/* Use GNU extensions */
|
||||
#define _GNU_SOURCE 1
|
||||
|
||||
/* Oldest Windows version supported */
|
||||
/* #undef _WIN32_WINNT */
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
/* #undef inline */
|
||||
#endif
|
||||
@@ -20,7 +20,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
#include "libusb_config.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
#include "libusb_config.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
#include "libusb_config.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
#include "libusb_config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -23,7 +23,7 @@
|
||||
#ifndef LIBUSBI_H
|
||||
#define LIBUSBI_H
|
||||
|
||||
#include "../config.h"
|
||||
#include "libusb_config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../../config.h"
|
||||
#include "libusb_config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../../config.h"
|
||||
#include "libusb_config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../../config.h"
|
||||
#include "libusb_config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../config.h"
|
||||
#include "libusb_config.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
@@ -1,447 +0,0 @@
|
||||
/*
|
||||
* poll_windows: poll compatibility wrapper for Windows
|
||||
* Copyright © 2017 Chris Dickens <christopher.a.dickens@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* poll() and pipe() Windows compatibility layer for src 1.0
|
||||
*
|
||||
* The way this layer works is by using OVERLAPPED with async I/O transfers, as
|
||||
* OVERLAPPED have an associated event which is flagged for I/O completion.
|
||||
*
|
||||
* For USB pollable async I/O, you would typically:
|
||||
* - obtain a Windows HANDLE to a file or device that has been opened in
|
||||
* OVERLAPPED mode
|
||||
* - call usbi_create_fd with this handle to obtain a custom fd.
|
||||
* - leave the core functions call the poll routine and flag POLLIN/POLLOUT
|
||||
*
|
||||
* The pipe pollable synchronous I/O works using the overlapped event associated
|
||||
* with a fake pipe. The read/write functions are only meant to be used in that
|
||||
* context.
|
||||
*/
|
||||
#include <config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libusbi.h"
|
||||
#include "windows_common.h"
|
||||
|
||||
// public fd data
|
||||
const struct winfd INVALID_WINFD = { -1, NULL };
|
||||
|
||||
// private data
|
||||
struct file_descriptor {
|
||||
enum fd_type { FD_TYPE_PIPE, FD_TYPE_TRANSFER } type;
|
||||
OVERLAPPED overlapped;
|
||||
int refcount;
|
||||
};
|
||||
|
||||
static usbi_mutex_static_t fd_table_lock = USBI_MUTEX_INITIALIZER;
|
||||
|
||||
static struct file_descriptor **fd_table;
|
||||
static size_t fd_count;
|
||||
static size_t fd_size;
|
||||
#define INC_FDS_EACH 256
|
||||
|
||||
static void usbi_dec_fd_table()
|
||||
{
|
||||
fd_count--;
|
||||
if (fd_count == 0) {
|
||||
free(fd_table);
|
||||
fd_size = 0;
|
||||
fd_table = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void smart_realloc_fd_table_space(int inc)
|
||||
{
|
||||
if (fd_table == NULL || fd_count + inc > fd_size) {
|
||||
struct file_descriptor **p = (struct file_descriptor **)realloc(fd_table, (fd_size + INC_FDS_EACH) * sizeof(struct file_descriptor *));
|
||||
if (p != NULL) {
|
||||
memset(p + fd_size, 0, INC_FDS_EACH * sizeof(struct file_descriptor *));
|
||||
fd_size += INC_FDS_EACH;
|
||||
fd_table = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static struct file_descriptor *create_fd(enum fd_type type)
|
||||
{
|
||||
struct file_descriptor *fd = calloc(1, sizeof(*fd));
|
||||
if (fd == NULL)
|
||||
return NULL;
|
||||
fd->overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if (fd->overlapped.hEvent == NULL) {
|
||||
free(fd);
|
||||
return NULL;
|
||||
}
|
||||
fd->type = type;
|
||||
fd->refcount = 1;
|
||||
return fd;
|
||||
}
|
||||
|
||||
static void free_fd(struct file_descriptor *fd)
|
||||
{
|
||||
CloseHandle(fd->overlapped.hEvent);
|
||||
free(fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create both an fd and an OVERLAPPED, so that it can be used with our
|
||||
* polling function
|
||||
* The handle MUST support overlapped transfers (usually requires CreateFile
|
||||
* with FILE_FLAG_OVERLAPPED)
|
||||
* Return a pollable file descriptor struct, or INVALID_WINFD on error
|
||||
*
|
||||
* Note that the fd returned by this function is a per-transfer fd, rather
|
||||
* than a per-session fd and cannot be used for anything else but our
|
||||
* custom functions.
|
||||
* if you plan to do R/W on the same handle, you MUST create 2 fds: one for
|
||||
* read and one for write. Using a single R/W fd is unsupported and will
|
||||
* produce unexpected results
|
||||
*/
|
||||
struct winfd usbi_create_fd(void)
|
||||
{
|
||||
struct file_descriptor *fd;
|
||||
struct winfd wfd;
|
||||
|
||||
fd = create_fd(FD_TYPE_TRANSFER);
|
||||
if (fd == NULL)
|
||||
return INVALID_WINFD;
|
||||
|
||||
usbi_mutex_static_lock(&fd_table_lock);
|
||||
|
||||
smart_realloc_fd_table_space(1);
|
||||
|
||||
for (wfd.fd = 0; wfd.fd < fd_size; wfd.fd++) {
|
||||
if (fd_table[wfd.fd] != NULL)
|
||||
continue;
|
||||
fd_table[wfd.fd] = fd;
|
||||
fd_count++;
|
||||
break;
|
||||
}
|
||||
usbi_mutex_static_unlock(&fd_table_lock);
|
||||
|
||||
if (wfd.fd == fd_size) {
|
||||
free_fd(fd);
|
||||
return INVALID_WINFD;
|
||||
}
|
||||
|
||||
wfd.overlapped = &fd->overlapped;
|
||||
|
||||
return wfd;
|
||||
}
|
||||
|
||||
void usbi_inc_fds_ref(struct pollfd *fds, unsigned int nfds)
|
||||
{
|
||||
int n;
|
||||
usbi_mutex_static_lock(&fd_table_lock);
|
||||
for (n = 0; n < nfds; ++n) {
|
||||
fd_table[fds[n].fd]->refcount++;
|
||||
}
|
||||
usbi_mutex_static_unlock(&fd_table_lock);
|
||||
}
|
||||
|
||||
void usbi_dec_fds_ref(struct pollfd *fds, unsigned int nfds)
|
||||
{
|
||||
int n;
|
||||
struct file_descriptor *fd;
|
||||
|
||||
usbi_mutex_static_lock(&fd_table_lock);
|
||||
for (n = 0; n < nfds; ++n) {
|
||||
fd = fd_table[fds[n].fd];
|
||||
fd->refcount--;
|
||||
//FD_TYPE_PIPE map fd to two _fd
|
||||
if (fd->refcount == 0 || (fd->refcount == 1 && fd->type == FD_TYPE_PIPE))
|
||||
{
|
||||
if (fd->type == FD_TYPE_PIPE) {
|
||||
// InternalHigh is our reference count
|
||||
fd->overlapped.InternalHigh--;
|
||||
if (fd->overlapped.InternalHigh == 0)
|
||||
free_fd(fd);
|
||||
}
|
||||
else {
|
||||
free_fd(fd);
|
||||
}
|
||||
fd_table[fds[n].fd] = NULL;
|
||||
usbi_dec_fd_table();
|
||||
}
|
||||
}
|
||||
usbi_mutex_static_unlock(&fd_table_lock);
|
||||
}
|
||||
|
||||
|
||||
static int check_pollfds(struct pollfd *fds, unsigned int nfds,
|
||||
HANDLE *wait_handles, DWORD *nb_wait_handles)
|
||||
{
|
||||
struct file_descriptor *fd;
|
||||
unsigned int n;
|
||||
int nready = 0;
|
||||
|
||||
usbi_mutex_static_lock(&fd_table_lock);
|
||||
|
||||
for (n = 0; n < nfds; ++n) {
|
||||
fds[n].revents = 0;
|
||||
|
||||
// Keep it simple - only allow either POLLIN *or* POLLOUT
|
||||
assert((fds[n].events == POLLIN) || (fds[n].events == POLLOUT));
|
||||
if ((fds[n].events != POLLIN) && (fds[n].events != POLLOUT)) {
|
||||
fds[n].revents = POLLNVAL;
|
||||
nready++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((fds[n].fd >= 0) && (fds[n].fd < fd_size))
|
||||
fd = fd_table[fds[n].fd];
|
||||
else
|
||||
fd = NULL;
|
||||
|
||||
assert(fd != NULL);
|
||||
if (fd == NULL) {
|
||||
fds[n].revents = POLLNVAL;
|
||||
nready++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (HasOverlappedIoCompleted(&fd->overlapped)
|
||||
&& (WaitForSingleObject(fd->overlapped.hEvent, 0) == WAIT_OBJECT_0)) {
|
||||
fds[n].revents = fds[n].events;
|
||||
nready++;
|
||||
} else if (wait_handles != NULL) {
|
||||
if (*nb_wait_handles == MAXIMUM_WAIT_OBJECTS) {
|
||||
usbi_warn(NULL, "too many HANDLEs to wait on");
|
||||
continue;
|
||||
}
|
||||
wait_handles[*nb_wait_handles] = fd->overlapped.hEvent;
|
||||
(*nb_wait_handles)++;
|
||||
}
|
||||
}
|
||||
|
||||
usbi_mutex_static_unlock(&fd_table_lock);
|
||||
|
||||
return nready;
|
||||
}
|
||||
/*
|
||||
* POSIX poll equivalent, using Windows OVERLAPPED
|
||||
* Currently, this function only accepts one of POLLIN or POLLOUT per fd
|
||||
* (but you can create multiple fds from the same handle for read and write)
|
||||
*/
|
||||
int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout)
|
||||
{
|
||||
HANDLE wait_handles[MAXIMUM_WAIT_OBJECTS];
|
||||
DWORD nb_wait_handles = 0;
|
||||
DWORD ret;
|
||||
int nready;
|
||||
|
||||
nready = check_pollfds(fds, nfds, wait_handles, &nb_wait_handles);
|
||||
|
||||
// If nothing was triggered, wait on all fds that require it
|
||||
if ((nready == 0) && (nb_wait_handles != 0) && (timeout != 0)) {
|
||||
ret = WaitForMultipleObjects(nb_wait_handles, wait_handles,
|
||||
FALSE, (timeout < 0) ? INFINITE : (DWORD)timeout);
|
||||
if (ret < (WAIT_OBJECT_0 + nb_wait_handles)) {
|
||||
nready = check_pollfds(fds, nfds, NULL, NULL);
|
||||
} else if (ret != WAIT_TIMEOUT) {
|
||||
if (ret == WAIT_FAILED)
|
||||
usbi_err(NULL, "WaitForMultipleObjects failed: %u", (unsigned int)GetLastError());
|
||||
nready = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return nready;
|
||||
}
|
||||
|
||||
/*
|
||||
* close a fake file descriptor
|
||||
*/
|
||||
int usbi_close(int _fd)
|
||||
{
|
||||
struct file_descriptor *fd;
|
||||
|
||||
if (_fd < 0 || _fd >= fd_size)
|
||||
goto err_badfd;
|
||||
|
||||
usbi_mutex_static_lock(&fd_table_lock);
|
||||
fd = fd_table[_fd];
|
||||
fd->refcount--;
|
||||
//FD_TYPE_PIPE map fd to two _fd
|
||||
if(fd->refcount==0 || (fd->refcount == 1 && fd->type == FD_TYPE_PIPE))
|
||||
{ fd_table[_fd] = NULL;
|
||||
usbi_dec_fd_table();
|
||||
|
||||
if (fd->type == FD_TYPE_PIPE) {
|
||||
// InternalHigh is our reference count
|
||||
fd->overlapped.InternalHigh--;
|
||||
if (fd->overlapped.InternalHigh == 0)
|
||||
free_fd(fd);
|
||||
}
|
||||
else {
|
||||
free_fd(fd);
|
||||
}
|
||||
}
|
||||
usbi_mutex_static_unlock(&fd_table_lock);
|
||||
|
||||
if (fd == NULL)
|
||||
goto err_badfd;
|
||||
|
||||
return 0;
|
||||
|
||||
err_badfd:
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a fake pipe.
|
||||
* As src only uses pipes for signaling, all we need from a pipe is an
|
||||
* event. To that extent, we create a single wfd and overlapped as a means
|
||||
* to access that event.
|
||||
*/
|
||||
int usbi_pipe(int filedes[2])
|
||||
{
|
||||
struct file_descriptor *fd;
|
||||
int r_fd = -1, w_fd = -1;
|
||||
int i;
|
||||
|
||||
fd = create_fd(FD_TYPE_PIPE);
|
||||
if (fd == NULL) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Use InternalHigh as a reference count
|
||||
fd->overlapped.Internal = STATUS_PENDING;
|
||||
fd->overlapped.InternalHigh = 2;
|
||||
|
||||
usbi_mutex_static_lock(&fd_table_lock);
|
||||
do {
|
||||
smart_realloc_fd_table_space(2);
|
||||
|
||||
for (i = 0; i < fd_size; i++) {
|
||||
if (fd_table[i] != NULL)
|
||||
continue;
|
||||
if (r_fd == -1) {
|
||||
r_fd = i;
|
||||
} else if (w_fd == -1) {
|
||||
w_fd = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == fd_size)
|
||||
break;
|
||||
|
||||
fd_table[r_fd] = fd;
|
||||
fd_table[w_fd] = fd;
|
||||
|
||||
fd->refcount++; //this fd reference twice for r and w.
|
||||
|
||||
fd_count += 2;
|
||||
|
||||
} while (0);
|
||||
usbi_mutex_static_unlock(&fd_table_lock);
|
||||
|
||||
if (i == fd_size) {
|
||||
free_fd(fd);
|
||||
errno = EMFILE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
filedes[0] = r_fd;
|
||||
filedes[1] = w_fd;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* synchronous write for fake "pipe" signaling
|
||||
*/
|
||||
ssize_t usbi_write(int fd, const void *buf, size_t count)
|
||||
{
|
||||
int error = EBADF;
|
||||
|
||||
UNUSED(buf);
|
||||
|
||||
if (fd < 0 || fd >= fd_size)
|
||||
goto err_out;
|
||||
|
||||
if (count != sizeof(unsigned char)) {
|
||||
usbi_err(NULL, "this function should only used for signaling");
|
||||
error = EINVAL;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
usbi_mutex_static_lock(&fd_table_lock);
|
||||
if ((fd_table[fd] != NULL) && (fd_table[fd]->type == FD_TYPE_PIPE)) {
|
||||
assert(fd_table[fd]->overlapped.Internal == STATUS_PENDING);
|
||||
assert(fd_table[fd]->overlapped.InternalHigh == 2);
|
||||
fd_table[fd]->overlapped.Internal = STATUS_WAIT_0;
|
||||
SetEvent(fd_table[fd]->overlapped.hEvent);
|
||||
error = 0;
|
||||
}
|
||||
usbi_mutex_static_unlock(&fd_table_lock);
|
||||
|
||||
if (error)
|
||||
goto err_out;
|
||||
|
||||
return sizeof(unsigned char);
|
||||
|
||||
err_out:
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* synchronous read for fake "pipe" signaling
|
||||
*/
|
||||
ssize_t usbi_read(int fd, void *buf, size_t count)
|
||||
{
|
||||
int error = EBADF;
|
||||
|
||||
UNUSED(buf);
|
||||
|
||||
if (fd < 0 || fd >= fd_size)
|
||||
goto err_out;
|
||||
|
||||
if (count != sizeof(unsigned char)) {
|
||||
usbi_err(NULL, "this function should only used for signaling");
|
||||
error = EINVAL;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
usbi_mutex_static_lock(&fd_table_lock);
|
||||
if ((fd_table[fd] != NULL) && (fd_table[fd]->type == FD_TYPE_PIPE)) {
|
||||
assert(fd_table[fd]->overlapped.Internal == STATUS_WAIT_0);
|
||||
assert(fd_table[fd]->overlapped.InternalHigh == 2);
|
||||
fd_table[fd]->overlapped.Internal = STATUS_PENDING;
|
||||
ResetEvent(fd_table[fd]->overlapped.hEvent);
|
||||
error = 0;
|
||||
}
|
||||
usbi_mutex_static_unlock(&fd_table_lock);
|
||||
|
||||
if (error)
|
||||
goto err_out;
|
||||
|
||||
return sizeof(unsigned char);
|
||||
|
||||
err_out:
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* Windows compat: POSIX compatibility wrapper
|
||||
* Copyright © 2012-2013 RealVNC Ltd.
|
||||
* Copyright © 2009-2010 Pete Batard <pete@akeo.ie>
|
||||
* Copyright © 2016-2018 Chris Dickens <christopher.a.dickens@gmail.com>
|
||||
* With contributions from Michael Plante, Orin Eman et al.
|
||||
* Parts of poll implementation from src-win32, by Stephan Meyer et al.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
// disable /W4 MSVC warnings that are benign
|
||||
#pragma warning(disable:4127) // conditional expression is constant
|
||||
#endif
|
||||
|
||||
// Handle synchronous completion through the overlapped structure
|
||||
#if !defined(STATUS_REPARSE) // reuse the REPARSE status code
|
||||
#define STATUS_REPARSE ((LONG)0x00000104L)
|
||||
#endif
|
||||
#define STATUS_COMPLETED_SYNCHRONOUSLY STATUS_REPARSE
|
||||
#if defined(_WIN32_WCE)
|
||||
// WinCE doesn't have a HasOverlappedIoCompleted() macro, so attempt to emulate it
|
||||
#define HasOverlappedIoCompleted(lpOverlapped) (((DWORD)(lpOverlapped)->Internal) != STATUS_PENDING)
|
||||
#endif
|
||||
#define HasOverlappedIoCompletedSync(lpOverlapped) (((DWORD)(lpOverlapped)->Internal) == STATUS_COMPLETED_SYNCHRONOUSLY)
|
||||
|
||||
#define DUMMY_HANDLE ((HANDLE)(LONG_PTR)-2)
|
||||
|
||||
#define POLLIN 0x0001 /* There is data to read */
|
||||
#define POLLPRI 0x0002 /* There is urgent data to read */
|
||||
#define POLLOUT 0x0004 /* Writing now will not block */
|
||||
#define POLLERR 0x0008 /* Error condition */
|
||||
#define POLLHUP 0x0010 /* Hung up */
|
||||
#define POLLNVAL 0x0020 /* Invalid request: fd not open */
|
||||
|
||||
struct pollfd {
|
||||
int fd; /* file descriptor */
|
||||
short events; /* requested events */
|
||||
short revents; /* returned events */
|
||||
};
|
||||
|
||||
struct winfd {
|
||||
int fd; // what's exposed to src core
|
||||
OVERLAPPED *overlapped; // what will report our I/O status
|
||||
};
|
||||
|
||||
extern const struct winfd INVALID_WINFD;
|
||||
|
||||
struct winfd usbi_create_fd(void);
|
||||
|
||||
int usbi_pipe(int pipefd[2]);
|
||||
int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout);
|
||||
ssize_t usbi_write(int fd, const void *buf, size_t count);
|
||||
ssize_t usbi_read(int fd, void *buf, size_t count);
|
||||
int usbi_close(int fd);
|
||||
|
||||
void usbi_inc_fds_ref(struct pollfd *fds, unsigned int nfds);
|
||||
void usbi_dec_fds_ref(struct pollfd *fds, unsigned int nfds);
|
||||
|
||||
/*
|
||||
* Timeval operations
|
||||
*/
|
||||
#if defined(DDKBUILD)
|
||||
#include <winsock.h> // defines timeval functions on DDK
|
||||
#endif
|
||||
|
||||
#if !defined(TIMESPEC_TO_TIMEVAL)
|
||||
#define TIMESPEC_TO_TIMEVAL(tv, ts) { \
|
||||
(tv)->tv_sec = (long)(ts)->tv_sec; \
|
||||
(tv)->tv_usec = (long)(ts)->tv_nsec / 1000; \
|
||||
}
|
||||
#endif
|
||||
#if !defined(timersub)
|
||||
#define timersub(a, b, result) \
|
||||
do { \
|
||||
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
|
||||
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
|
||||
if ((result)->tv_usec < 0) { \
|
||||
--(result)->tv_sec; \
|
||||
(result)->tv_usec += 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
@@ -19,7 +19,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../../config.h"
|
||||
#include "libusb_config.h"
|
||||
|
||||
#include <time.h>
|
||||
#if defined(__linux__) || defined(__OpenBSD__)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
#include "libusb_config.h"
|
||||
|
||||
#include <locale.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../config.h"
|
||||
#include "libusb_config.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
|
||||
Reference in New Issue
Block a user