mirror of
https://github.com/mik3y/usb-serial-for-android.git
synced 2026-08-14 09:52:58 +00:00
check read buffer size
This commit is contained in:
+3
@@ -134,6 +134,9 @@ public abstract class CommonUsbSerialPort implements UsbSerialPort {
|
||||
if(mConnection == null) {
|
||||
throw new IOException("Connection closed");
|
||||
}
|
||||
if(dest.length <= 0) {
|
||||
throw new IllegalArgumentException("read buffer to small");
|
||||
}
|
||||
final int nread;
|
||||
if (timeout != 0) {
|
||||
// bulkTransfer will cause data loss with short timeout + high baud rates + continuous transfer
|
||||
|
||||
+6
@@ -137,6 +137,12 @@ public class FtdiSerialDriver implements UsbSerialDriver {
|
||||
|
||||
@Override
|
||||
public int read(final byte[] dest, final int timeout) throws IOException {
|
||||
if(dest.length <= READ_HEADER_LENGTH) {
|
||||
throw new IllegalArgumentException("read buffer to small");
|
||||
// could allocate larger buffer, including space for 2 header bytes, but this would
|
||||
// result in buffers not being 64 byte aligned any more, causing data loss at continuous
|
||||
// data transfer at high baud rates when buffers are fully filled.
|
||||
}
|
||||
int nread;
|
||||
if (timeout != 0) {
|
||||
long endTime = System.currentTimeMillis() + timeout;
|
||||
|
||||
Reference in New Issue
Block a user