adb: Have device usb_handle return io size
Previously, read and write would return 0
on success. Now it will return the number
of bytes read/write. This is more consistent
with other usb handles and is needed in order
to handle partial packets (for fastbootd).
Update usb_write in other usb handles
to return amount written.
Change transport_usb accordingly.
Test: adb works
Bug: 78793464
Change-Id: If07ff05fbc8120343f20661475d34f4e5ff805de
diff --git a/adb/daemon/usb.cpp b/adb/daemon/usb.cpp
index 8c14955..5242718 100644
--- a/adb/daemon/usb.cpp
+++ b/adb/daemon/usb.cpp
@@ -368,6 +368,7 @@
D("about to write (fd=%d, len=%d)", h->bulk_in, len);
const char* buf = static_cast<const char*>(data);
+ int orig_len = len;
while (len > 0) {
int write_len = std::min(USB_FFS_BULK_SIZE, len);
int n = adb_write(h->bulk_in, buf, write_len);
@@ -380,13 +381,14 @@
}
D("[ done fd=%d ]", h->bulk_in);
- return 0;
+ return orig_len;
}
static int usb_ffs_read(usb_handle* h, void* data, int len) {
D("about to read (fd=%d, len=%d)", h->bulk_out, len);
char* buf = static_cast<char*>(data);
+ int orig_len = len;
while (len > 0) {
int read_len = std::min(USB_FFS_BULK_SIZE, len);
int n = adb_read(h->bulk_out, buf, read_len);
@@ -399,7 +401,7 @@
}
D("[ done fd=%d ]", h->bulk_out);
- return 0;
+ return orig_len;
}
static int usb_ffs_do_aio(usb_handle* h, const void* data, int len, bool read) {
@@ -447,6 +449,7 @@
if (num_bufs == 1 && aiob->events[0].res == -EINTR) {
continue;
}
+ int ret = 0;
for (int i = 0; i < num_bufs; i++) {
if (aiob->events[i].res < 0) {
errno = -aiob->events[i].res;
@@ -454,8 +457,9 @@
<< " total bufs " << num_bufs;
return -1;
}
+ ret += aiob->events[i].res;
}
- return 0;
+ return ret;
}
}