From b7eac2d0849e0564fef1e589dfe0b953180444b8 Mon Sep 17 00:00:00 2001 From: Fernando Lugo Date: Wed, 29 May 2019 19:33:56 -0700 Subject: [PATCH] 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 --- fastboot/usb_windows.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/fastboot/usb_windows.cpp b/fastboot/usb_windows.cpp index b00edb3fd..5a3cefcac 100644 --- a/fastboot/usb_windows.cpp +++ b/fastboot/usb_windows.cpp @@ -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");