]> sigrok.org Git - libsigrok.git/blobdiff - src/usb.c
session: Fix USB timeout handling
[libsigrok.git] / src / usb.c
index b0ea618cd573019d4f6f4094e09a142f4eb97e04..5038441cc97c3db869ff5969097baaa6e36e439a 100644 (file)
--- a/src/usb.c
+++ b/src/usb.c
@@ -23,7 +23,7 @@
 #include <memory.h>
 #include <glib.h>
 #include <libusb.h>
-#include "libsigrok.h"
+#include <libsigrok/libsigrok.h>
 #include "libsigrok-internal.h"
 
 /* SR_CONF_CONN takes one of these: */
@@ -177,6 +177,13 @@ SR_PRIV int sr_usb_open(libusb_context *usb_ctx, struct sr_usb_dev_inst *usb)
        return ret;
 }
 
+SR_PRIV void sr_usb_close(struct sr_usb_dev_inst *usb)
+{
+       libusb_close(usb->devhdl);
+       usb->devhdl = NULL;
+       sr_dbg("Closed USB device %d.%d.", usb->bus, usb->address);
+}
+
 #ifdef _WIN32
 /* Thread used to run libusb_wait_for_event() and set a pollable event. */
 static gpointer usb_thread(gpointer data)
@@ -244,6 +251,7 @@ SR_PRIV int usb_source_add(struct sr_session *session, struct sr_context *ctx,
        /* Add event, set by USB wait thread, to session poll set. */
        ctx->usb_pollfd.fd = ctx->usb_wait_complete_event;
        ctx->usb_pollfd.events = G_IO_IN;
+       ctx->usb_pollfd.revents = 0;
        ctx->usb_cb = cb;
        ctx->usb_cb_data = cb_data;
        sr_session_source_add_pollfd(session, &ctx->usb_pollfd, timeout,