From: Daniel Elstner Date: Sun, 30 Aug 2015 10:20:03 +0000 (+0200) Subject: session: Fix USB timeout handling X-Git-Tag: libsigrok-0.4.0~357 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=89efe06460024c2a33e57178f5812bf23c2f9888 session: Fix USB timeout handling In sr_session_iteration(), remove the inverted evaluation of the block parameter if a USB source is present. This stops the deluge of USB event callbacks due to the timeout always being zero. Also, just for cleanliness, initialize the revents member of each GPollFD instance to zero. --- diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index 12af5c1d..604849c4 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -165,6 +165,7 @@ static int dev_open(struct sr_dev_inst *sdi) /* Set fd and local attributes */ devc->pollfd.fd = devc->fd; devc->pollfd.events = G_IO_IN; + devc->pollfd.revents = 0; /* Get the default attributes */ beaglelogic_get_samplerate(devc); diff --git a/src/session.c b/src/session.c index 20c9ce5f..499025b5 100644 --- a/src/session.c +++ b/src/session.c @@ -389,7 +389,6 @@ static int sr_session_iteration(struct sr_session *session, gboolean block) #ifdef HAVE_LIBUSB_1_0 if (session->ctx->usb_source_present) { - timeout = block ? 0 : session->source_timeout; ret = libusb_get_next_timeout(session->ctx->libusb_ctx, &tv); if (ret < 0) { sr_err("Error getting libusb timeout: %s", @@ -856,6 +855,7 @@ SR_API int sr_session_source_add(struct sr_session *session, int fd, p.fd = fd; p.events = events; + p.revents = 0; return _sr_session_source_add(session, &p, timeout, cb, cb_data, (gintptr)fd); } @@ -908,6 +908,7 @@ SR_API int sr_session_source_add_channel(struct sr_session *session, #else p.fd = g_io_channel_unix_get_fd(channel); p.events = events; + p.revents = 0; #endif return _sr_session_source_add(session, &p, timeout, cb, cb_data, (gintptr)channel); diff --git a/src/usb.c b/src/usb.c index f5b20c99..5038441c 100644 --- a/src/usb.c +++ b/src/usb.c @@ -251,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,