diff options
Diffstat (limited to 'host/lib/transport/libusb1_zero_copy.cpp')
-rw-r--r-- | host/lib/transport/libusb1_zero_copy.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index b425843fa..697944089 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -20,7 +20,7 @@ #include <uhd/transport/bounded_buffer.hpp> #include <uhd/transport/buffer_pool.hpp> #include <uhd/utils/thread_priority.hpp> -#include <uhd/utils/assert.hpp> +#include <uhd/exception.hpp> #include <boost/function.hpp> #include <boost/foreach.hpp> #include <boost/thread/thread.hpp> @@ -33,6 +33,17 @@ using namespace uhd::transport; static const size_t DEFAULT_NUM_XFERS = 16; //num xfers static const size_t DEFAULT_XFER_SIZE = 32*512; //bytes +//! helper function: handles all async callbacks +static void libusb_async_cb(libusb_transfer *lut){ + (*static_cast<boost::function<void()> *>(lut->user_data))(); +} + +//! callback to free transfer upon cancellation +static void cancel_transfer_cb(libusb_transfer *lut){ + if (lut->status == LIBUSB_TRANSFER_CANCELLED) libusb_free_transfer(lut); + else std::cout << "libusb cancel_transfer unexpected status " << lut->status << std::endl; +} + /*********************************************************************** * Reusable managed receiver buffer: * - Associated with a particular libusb transfer struct. @@ -79,7 +90,8 @@ public: void commit(size_t len){ if (_expired) return; _lut->length = len; - UHD_ASSERT_THROW(libusb_submit_transfer(_lut) == 0); + if(len == 0) libusb_async_cb(_lut); + else UHD_ASSERT_THROW(libusb_submit_transfer(_lut) == 0); _expired = true; } @@ -100,17 +112,6 @@ private: bool _expired; }; -//! helper function: handles all async callbacks -static void libusb_async_cb(libusb_transfer *lut){ - (*static_cast<boost::function<void()> *>(lut->user_data))(); -} - -//! callback to free transfer upon cancellation -static void cancel_transfer_cb(libusb_transfer *lut) { - if(lut->status == LIBUSB_TRANSFER_CANCELLED) libusb_free_transfer(lut); - else std::cout << "cancel_transfer unexpected status " << lut->status << std::endl; -} - /*********************************************************************** * USB zero_copy device class **********************************************************************/ |