summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Tsou <ttsou@vt.edu>2010-08-27 15:59:05 -0700
committerThomas Tsou <ttsou@vt.edu>2010-08-27 16:05:28 -0700
commit7f8c73faa22aaf2a381193d9f460857785e45023 (patch)
tree5eab9442faa819f65c5de146f592b22895003050
parent72fc20bc8ba4cb636a04de78210aac483f4ffaf3 (diff)
downloaduhd-7f8c73faa22aaf2a381193d9f460857785e45023.tar.gz
uhd-7f8c73faa22aaf2a381193d9f460857785e45023.tar.bz2
uhd-7f8c73faa22aaf2a381193d9f460857785e45023.zip
usrp1: Handle degenerate managed send buffer cases
Handle degenerate usage of send buffer commits. If the buffer is destroyed without ever being submitted, submit a zero byte transfer to return control to the underlying structure. If a committed buffer is re-committed, then report an error message and return 0 bytes back.
-rw-r--r--host/lib/transport/libusb1_zero_copy.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp
index 2149625f9..4469991b8 100644
--- a/host/lib/transport/libusb1_zero_copy.cpp
+++ b/host/lib/transport/libusb1_zero_copy.cpp
@@ -555,7 +555,7 @@ public:
libusb_managed_send_buffer_impl(libusb_transfer *lut,
usb_endpoint *endpoint,
size_t buff_size)
- : _buff(lut->buffer, buff_size)
+ : _buff(lut->buffer, buff_size), _committed(false)
{
_lut = lut;
_endpoint = endpoint;
@@ -563,18 +563,32 @@ public:
~libusb_managed_send_buffer_impl()
{
- /* NOP */
+ if (!_committed) {
+ _lut->length = 0;
+ _lut->actual_length = 0;
+ _endpoint->submit(_lut);
+ }
}
ssize_t commit(size_t num_bytes)
{
+ if (_committed) {
+ std::cerr << "UHD: send buffer already committed" << std::endl;
+ return 0;
+ }
+
+ UHD_ASSERT_THROW(num_bytes <= boost::asio::buffer_size(_buff));
+
_lut->length = num_bytes;
_lut->actual_length = 0;
- if (_endpoint->submit(_lut))
+ if (_endpoint->submit(_lut)) {
+ _committed = true;
return num_bytes;
- else
+ }
+ else {
return 0;
+ }
}
private:
@@ -586,6 +600,7 @@ private:
libusb_transfer *_lut;
usb_endpoint *_endpoint;
const boost::asio::mutable_buffer _buff;
+ bool _committed;
};