Limit read buffer chunksize to 16384 on Linux.
authorJie Zhang <jzhang918@gmail.com>
Sun, 14 Feb 2010 00:44:23 +0000 (08:44 +0800)
committerJie Zhang <jzhang918@gmail.com>
Sun, 14 Feb 2010 00:44:23 +0000 (08:44 +0800)
src/ftdi.c

index 22e746d..afcf897 100644 (file)
@@ -1621,6 +1621,14 @@ int ftdi_read_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksi
     // Invalidate all remaining data
     ftdi->readbuffer_offset = 0;
     ftdi->readbuffer_remaining = 0;
+#ifdef __linux__
+    /* We can't set readbuffer_chunksize larger than MAX_BULK_BUFFER_LENGTH,
+       which is defined in libusb-1.0.  Otherwise, each USB read request will
+       be devided into multiple URBs.  This will cause issues on Linux kernel
+       older than 2.6.32.  */
+    if (chunksize > 16384)
+        chunksize = 16384;
+#endif
 
     if ((new_buf = (unsigned char *)realloc(ftdi->readbuffer, chunksize)) == NULL)
         ftdi_error_return(-1, "out of memory for readbuffer");