openbsd: Transition to use new transfer completion API
authorChris Dickens <christopher.a.dickens@gmail.com>
Wed, 21 Jan 2015 08:18:43 +0000 (00:18 -0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Tue, 27 Jan 2015 02:57:44 +0000 (18:57 -0800)
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/os/openbsd_usb.c
libusb/version_nano.h

index 1b96f34..2fc069d 100644 (file)
@@ -41,7 +41,6 @@ struct device_priv {
 };
 
 struct handle_priv {
-       int pipe[2];                            /* for event notification */
        int endpoints[USB_MAX_ENDPOINTS];
 };
 
@@ -75,8 +74,7 @@ static void obsd_destroy_device(struct libusb_device *);
 static int obsd_submit_transfer(struct usbi_transfer *);
 static int obsd_cancel_transfer(struct usbi_transfer *);
 static void obsd_clear_transfer_priv(struct usbi_transfer *);
-static int obsd_handle_events(struct libusb_context *ctx, struct pollfd *,
-    nfds_t, int);
+static int obsd_handle_transfer_completion(struct usbi_transfer *);
 static int obsd_clock_gettime(int, struct timespec *);
 
 /*
@@ -129,8 +127,8 @@ const struct usbi_os_backend openbsd_backend = {
        obsd_cancel_transfer,
        obsd_clear_transfer_priv,
 
-       obsd_handle_events,
-       NULL,                           /* handle_transfer_completion() */
+       NULL,                           /* handle_events() */
+       obsd_handle_transfer_completion,
 
        obsd_clock_gettime,
        sizeof(struct device_priv),
@@ -264,10 +262,7 @@ obsd_open(struct libusb_device_handle *handle)
                usbi_dbg("open %s: fd %d", devnode, dpriv->fd);
        }
 
-       if (pipe(hpriv->pipe) < 0)
-               return _errno_to_libusb(errno);
-
-       return usbi_add_pollfd(HANDLE_CTX(handle), hpriv->pipe[0], POLLIN);
+       return (LIBUSB_SUCCESS);
 }
 
 void
@@ -282,11 +277,6 @@ obsd_close(struct libusb_device_handle *handle)
                close(dpriv->fd);
                dpriv->fd = -1;
        }
-
-       usbi_remove_pollfd(HANDLE_CTX(handle), hpriv->pipe[0]);
-
-       close(hpriv->pipe[0]);
-       close(hpriv->pipe[1]);
 }
 
 int
@@ -517,8 +507,7 @@ obsd_submit_transfer(struct usbi_transfer *itransfer)
        if (err)
                return (err);
 
-       if (write(hpriv->pipe[1], &itransfer, sizeof(itransfer)) < 0)
-               return _errno_to_libusb(errno);
+       usbi_signal_transfer_completion(itransfer);
 
        return (LIBUSB_SUCCESS);
 }
@@ -540,63 +529,9 @@ obsd_clear_transfer_priv(struct usbi_transfer *itransfer)
 }
 
 int
-obsd_handle_events(struct libusb_context *ctx, struct pollfd *fds, nfds_t nfds,
-    int num_ready)
+obsd_handle_transfer_completion(struct usbi_transfer *itransfer)
 {
-       struct libusb_device_handle *handle;
-       struct handle_priv *hpriv = NULL;
-       struct usbi_transfer *itransfer;
-       struct pollfd *pollfd;
-       int i, err = 0;
-
-       usbi_dbg("");
-
-       pthread_mutex_lock(&ctx->open_devs_lock);
-       for (i = 0; i < nfds && num_ready > 0; i++) {
-               pollfd = &fds[i];
-
-               if (!pollfd->revents)
-                       continue;
-
-               hpriv = NULL;
-               num_ready--;
-               list_for_each_entry(handle, &ctx->open_devs, list,
-                   struct libusb_device_handle) {
-                       hpriv = (struct handle_priv *)handle->os_priv;
-
-                       if (hpriv->pipe[0] == pollfd->fd)
-                               break;
-
-                       hpriv = NULL;
-               }
-
-               if (NULL == hpriv) {
-                       usbi_dbg("fd %d is not an event pipe!", pollfd->fd);
-                       err = ENOENT;
-                       break;
-               }
-
-               if (pollfd->revents & POLLERR) {
-                       usbi_remove_pollfd(HANDLE_CTX(handle), hpriv->pipe[0]);
-                       usbi_handle_disconnect(handle);
-                       continue;
-               }
-
-               if (read(hpriv->pipe[0], &itransfer, sizeof(itransfer)) < 0) {
-                       err = errno;
-                       break;
-               }
-
-               if ((err = usbi_handle_transfer_completion(itransfer,
-                   LIBUSB_TRANSFER_COMPLETED)))
-                       break;
-       }
-       pthread_mutex_unlock(&ctx->open_devs_lock);
-
-       if (err)
-               return _errno_to_libusb(err);
-
-       return (LIBUSB_SUCCESS);
+       return usbi_handle_transfer_completion(itransfer, LIBUSB_TRANSFER_COMPLETED);
 }
 
 int
index 5e0caf3..7a69b84 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10956
+#define LIBUSB_NANO 10957