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>
master
Steve Markgraf 11 years ago
parent 929beafc6e
commit 5b0137abaf
  1. 25
      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;
}
}

Loading…
Cancel
Save