summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAxel Fagerstedt <axel@Proteus.(none)>2012-11-15 12:37:47 +0100
committerKalle Vahlman <kalle.vahlman@movial.com>2012-11-22 08:37:10 +0200
commit90d6e62911b846544fe1a489529503ca67094d80 (patch)
treef17510e5da0dc6ad8835c36385b5d80f0cad846c
parentb681455cdf3040c39793b76478b73ef58170900d (diff)
Split large writes into 16k chunks.
On some hosts LibusbDevice::write fails when for large buffers. This is solved by splitting the write into 16k chunks.
-rw-r--r--CDAL/LibusbDevice.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/CDAL/LibusbDevice.cpp b/CDAL/LibusbDevice.cpp
index 6e2c670..9f7b3a2 100644
--- a/CDAL/LibusbDevice.cpp
+++ b/CDAL/LibusbDevice.cpp
@@ -20,6 +20,8 @@ using namespace std;
#define MIN(A, B) ((A) < (B) ? (A) : (B))
+#define CHUNKSIZE 16384 //16 kB
+
LibusbDevice::LibusbDevice(libusb_device* device): device_(device)
{
int status = libusb_open(device_, &handle_);
@@ -120,8 +122,10 @@ int LibusbDevice::write(void *buffer, size_t size)
while (size) {
int transfered;
+ int chunkSize = size > CHUNKSIZE ? CHUNKSIZE : size;
+
//Call with timeout to enable possible cancel
- int error = libusb_bulk_transfer(handle_, outEndpoint_, src, size, &transfered, 0);
+ int error = libusb_bulk_transfer(handle_, outEndpoint_, src, chunkSize, &transfered, 0);
if (error) {
if (error == LIBUSB_ERROR_TIMEOUT) {