Fix a USB timeout related issue in sr_session_iteration().

This issue could lead to e.g. crashes when an OLS was used.

This fixes bug #571.
This commit is contained in:
Uwe Hermann 2015-04-12 16:34:26 +02:00
parent b65630f78d
commit 1190c65397
1 changed files with 12 additions and 9 deletions

View File

@ -385,17 +385,20 @@ static int sr_session_iteration(struct sr_session *session, gboolean block)
struct timeval tv; struct timeval tv;
#endif #endif
timeout = block ? 0 : session->source_timeout; timeout = block ? session->source_timeout : 0;
#ifdef HAVE_LIBUSB_1_0 #ifdef HAVE_LIBUSB_1_0
ret = libusb_get_next_timeout(session->ctx->libusb_ctx, &tv); if (session->ctx->usb_source_present) {
if (ret < 0) { timeout = block ? 0 : session->source_timeout;
sr_err("Error getting libusb timeout: %s", ret = libusb_get_next_timeout(session->ctx->libusb_ctx, &tv);
libusb_error_name(ret)); if (ret < 0) {
return SR_ERR; sr_err("Error getting libusb timeout: %s",
} else if (ret == 1) { libusb_error_name(ret));
usb_timeout = tv.tv_sec * 1000 + tv.tv_usec / 1000; return SR_ERR;
timeout = MIN(timeout, usb_timeout); } else if (ret == 1) {
usb_timeout = tv.tv_sec * 1000 + tv.tv_usec / 1000;
timeout = MIN(timeout, usb_timeout);
}
} }
#endif #endif