aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSteve Markgraf <steve@steve-m.de>2014-02-09 15:50:32 +0100
committerSteve Markgraf <steve@steve-m.de>2014-02-09 15:50:32 +0100
commit5b0137abaf179e6ca4e90a6ea987a61823a09bb1 (patch)
treec9ee67dce1e8806c52386ee32616bb9a25640412 /src
parent929beafc6ec34e83262522a193aface26de42926 (diff)
lib: handle events after canceling transfers
Otherwise the new transfer status does not propagate into the xfer->status and we try to cancel all transfers twice. Also replace the ifdefs with a single macro for backwards compatibility. Signed-off-by: Steve Markgraf <steve@steve-m.de>
Diffstat (limited to 'src')
-rw-r--r--src/librtlsdr.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/librtlsdr.c b/src/librtlsdr.c
index f21b187..5062827 100644
--- a/src/librtlsdr.c
+++ b/src/librtlsdr.c
@@ -39,6 +39,12 @@
#define LIBUSB_CALL
#endif
+/* libusb < 1.0.9 doesn't have libusb_handle_events_timeout_completed */
+#ifndef HAVE_LIBUSB_HANDLE_EVENTS_TIMEOUT_COMPLETED
+#define libusb_handle_events_timeout_completed(ctx, tv, c) \
+ libusb_handle_events_timeout(ctx, tv)
+#endif
+
/* two raised to the power of n */
#define TWO_POW(n) ((double)(1ULL<<(n)))
@@ -1776,11 +1782,8 @@ int rtlsdr_read_async(rtlsdr_dev_t *dev, rtlsdr_read_async_cb_t cb, void *ctx,
}
while (RTLSDR_INACTIVE != dev->async_status) {
-#ifdef HAVE_LIBUSB_HANDLE_EVENTS_TIMEOUT_COMPLETED
- r = libusb_handle_events_timeout_completed(dev->ctx, &tv, &dev->async_cancel);
-#else
- r = libusb_handle_events_timeout(dev->ctx, &tv);
-#endif
+ r = libusb_handle_events_timeout_completed(dev->ctx, &tv,
+ &dev->async_cancel);
if (r < 0) {
/*fprintf(stderr, "handle_events returned: %d\n", r);*/
if (r == LIBUSB_ERROR_INTERRUPTED) /* stray signal */
@@ -1801,6 +1804,11 @@ int rtlsdr_read_async(rtlsdr_dev_t *dev, rtlsdr_read_async_cb_t cb, void *ctx,
if (LIBUSB_TRANSFER_CANCELLED !=
dev->xfer[i]->status) {
r = libusb_cancel_transfer(dev->xfer[i]);
+ /* handle events after canceling
+ * to allow transfer status to
+ * propagate */
+ libusb_handle_events_timeout_completed(dev->ctx,
+ &zerotv, NULL);
if (r < 0)
continue;
@@ -1812,11 +1820,8 @@ int rtlsdr_read_async(rtlsdr_dev_t *dev, rtlsdr_read_async_cb_t cb, void *ctx,
/* handle any events that still need to
* be handled before exiting after we
* just cancelled all transfers */
-#ifdef HAVE_LIBUSB_HANDLE_EVENTS_TIMEOUT_COMPLETED
- libusb_handle_events_timeout_completed(dev->ctx, &zerotv, NULL);
-#else
- libusb_handle_events_timeout(dev->ctx, &zerotv);
-#endif
+ libusb_handle_events_timeout_completed(dev->ctx,
+ &zerotv, NULL);
break;
}
}