1
0
mirror of https://github.com/mik3y/usb-serial-for-android synced 2025-06-07 16:06:10 +00:00

cdc: Special case read timout == Integer.MAX_VALUE.

Some systems return 0 from read() when the device has been disconnected.
The only way to detect this is to 'never' expect a timeout.
This commit is contained in:
mike wakerly 2014-03-31 22:59:46 -07:00
parent 8e8ded4a9c
commit 6ef85d04c1

View File

@ -30,8 +30,6 @@ import android.hardware.usb.UsbRequest;
import android.os.Build;
import android.util.Log;
import com.hoho.android.usbserial.util.HexDump;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Collections;
@ -197,6 +195,10 @@ public class CdcAcmSerialDriver implements UsbSerialDriver {
// We *should* use UsbRequest, except it has a bug/api oversight
// where there is no way to determine the number of bytes read
// in response :\ -- http://b.android.com/28023
if (timeoutMillis == Integer.MAX_VALUE) {
// Hack: Special case "~infinite timeout" as an error.
return -1;
}
return 0;
}
System.arraycopy(mReadBuffer, 0, dest, 0, numBytesRead);