fastboot: windows: fix Read function

Read function exits before reading all requested bytes. Fix that by
looping until the len requested is completed.

This will fix the issue execting get_staged command for a staged image
bigger than 1MB

Test: fastboot get_staged file.txt
Change-Id: Ic70ab48f3a8c8d78c225db638892501d4dc20b13
Signed-off-by: Fernando Lugo <flugo@google.com>
This commit is contained in:
Fernando Lugo 2019-05-29 19:33:56 -07:00
parent c76078e4b6
commit b7eac2d084
1 changed files with 9 additions and 6 deletions

View File

@ -195,25 +195,28 @@ ssize_t WindowsUsbTransport::Write(const void* data, size_t len) {
ssize_t WindowsUsbTransport::Read(void* data, size_t len) {
unsigned long time_out = 0;
unsigned long read = 0;
size_t count = 0;
int ret;
DBG("usb_read %zu\n", len);
if (nullptr != handle_) {
while (1) {
int xfer = (len > MAX_USBFS_BULK_SIZE) ? MAX_USBFS_BULK_SIZE : len;
while (len > 0) {
size_t xfer = (len > MAX_USBFS_BULK_SIZE) ? MAX_USBFS_BULK_SIZE : len;
ret = AdbReadEndpointSync(handle_->adb_read_pipe, data, xfer, &read, time_out);
errno = GetLastError();
DBG("usb_read got: %ld, expected: %d, errno: %d\n", read, xfer, errno);
if (ret) {
return read;
} else {
if (ret == 0) {
// assume ERROR_INVALID_HANDLE indicates we are disconnected
if (errno == ERROR_INVALID_HANDLE)
usb_kick(handle_.get());
break;
}
// else we timed out - try again
count += read;
len -= read;
data = (char*)data + read;
if (xfer != read || len == 0) return count;
}
} else {
DBG("usb_read NULL handle\n");