diff options
author | Toby Gray <toby.gray@realvnc.com> | 2013-05-24 10:35:24 +0200 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2013-05-28 12:29:02 +0200 |
commit | 51655d74909fca03209cb5de5b90fb8d4e7dc465 (patch) | |
tree | 017dc6e3f6dff89445bde9ed2fe5b8f451b7c9d3 | |
parent | 4527d16c5c22a0d04f65dfadbb20b8a5d762f5fe (diff) | |
download | libusb-51655d74909fca03209cb5de5b90fb8d4e7dc465.tar.gz |
POSIX: Move setting of pipes to non-blocking into usbi_pipe
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r-- | libusb/Makefile.am | 12 | ||||
-rw-r--r-- | libusb/io.c | 6 | ||||
-rw-r--r-- | libusb/os/poll_posix.c | 41 | ||||
-rw-r--r-- | libusb/os/poll_posix.h | 3 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
5 files changed, 52 insertions, 12 deletions
diff --git a/libusb/Makefile.am b/libusb/Makefile.am index c5e3387..cd6db9c 100644 --- a/libusb/Makefile.am +++ b/libusb/Makefile.am @@ -2,6 +2,7 @@ all: libusb-1.0.la libusb-1.0.dll lib_LTLIBRARIES = libusb-1.0.la +POSIX_POLL_SRC = os/poll_posix.c LINUX_USBFS_SRC = os/linux_usbfs.c DARWIN_USB_SRC = os/darwin_usb.c OPENBSD_USB_SRC = os/openbsd_usb.c @@ -10,26 +11,29 @@ WINCE_USB_SRC = os/wince_usb.c os/wince_usb.h EXTRA_DIST = $(LINUX_USBFS_SRC) $(DARWIN_USB_SRC) $(OPENBSD_USB_SRC) \ $(WINDOWS_USB_SRC) $(WINCE_USB_SRC) \ + $(POSIX_POLL_SRC) \ os/threads_posix.c os/threads_windows.c \ os/linux_udev.c os/linux_netlink.c if OS_LINUX if USE_UDEV -OS_SRC = $(LINUX_USBFS_SRC) os/linux_udev.c +OS_SRC = $(LINUX_USBFS_SRC) $(POSIX_POLL_SRC) \ + os/linux_udev.c else -OS_SRC = $(LINUX_USBFS_SRC) os/linux_netlink.c +OS_SRC = $(LINUX_USBFS_SRC) $(POSIX_POLL_SRC) \ + os/linux_netlink.c endif endif if OS_DARWIN -OS_SRC = $(DARWIN_USB_SRC) +OS_SRC = $(DARWIN_USB_SRC) $(POSIX_POLL_SRC) AM_CFLAGS_EXT = -no-cpp-precomp endif if OS_OPENBSD -OS_SRC = $(OPENBSD_USB_SRC) +OS_SRC = $(OPENBSD_USB_SRC) $(POSIX_POLL_SRC) endif if OS_WINDOWS diff --git a/libusb/io.c b/libusb/io.c index b8b31f7..b27e082 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -25,9 +25,6 @@ #include <stdlib.h> #include <string.h> #include <time.h> -#ifndef OS_WINDOWS -#include <fcntl.h> -#endif #ifdef HAVE_SIGNAL_H #include <signal.h> #endif @@ -1082,9 +1079,6 @@ int usbi_io_init(struct libusb_context *ctx) goto err; } -#ifndef OS_WINDOWS - fcntl(ctx->hotplug_pipe[1], F_SETFD, O_NONBLOCK); -#endif r = usbi_add_pollfd(ctx, ctx->hotplug_pipe[0], POLLIN); if (r < 0) goto err_close_hp_pipe; diff --git a/libusb/os/poll_posix.c b/libusb/os/poll_posix.c new file mode 100644 index 0000000..bd1c538 --- /dev/null +++ b/libusb/os/poll_posix.c @@ -0,0 +1,41 @@ +/* + * poll_posix: poll compatibility wrapper for POSIX systems + * Copyright © 2013 RealVNC Ltd. + * + * 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 + * + */ + +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <stdlib.h> + +#include "libusbi.h" + +int usbi_pipe(int pipefd[2]) +{ + int ret = pipe(pipefd); + if (ret != 0) { + return ret; + } + ret = fcntl(pipefd[1], F_SETFD, O_NONBLOCK); + if (ret != 0) { + usbi_dbg("Failed to set non-blocking on new pipe: %d", errno); + usbi_close(pipefd[0]); + usbi_close(pipefd[1]); + } + return ret; +} diff --git a/libusb/os/poll_posix.h b/libusb/os/poll_posix.h index 0e5e7f5..5b4b2c9 100644 --- a/libusb/os/poll_posix.h +++ b/libusb/os/poll_posix.h @@ -4,7 +4,8 @@ #define usbi_write write #define usbi_read read #define usbi_close close -#define usbi_pipe pipe #define usbi_poll poll +int usbi_pipe(int pipefd[2]); + #endif /* LIBUSB_POLL_POSIX_H */ diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 1195a17..994efe8 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10716 +#define LIBUSB_NANO 10717 |