Tidy up the end-of-data handling in backup
* Increase transfer buffer size to 32K
* Add logging about error conditions and fd teardown
* Pass the fd number as a command line option to the 'bu' subprocess
* Properly harvest the 'bu' subprocess after it's done
Change-Id: Id44dde25778ecf43c5604fd9d01d726ba58861e5
diff --git a/adb/commandline.c b/adb/commandline.c
index 2dc86f2..28bae98 100644
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -239,18 +239,23 @@
}
static void copy_to_file(int inFd, int outFd) {
- char buf[4096];
+ const size_t BUFSIZE = 32 * 1024;
+ char* buf = (char*) malloc(BUFSIZE);
int len;
long total = 0;
D("copy_to_file(%d -> %d)\n", inFd, outFd);
for (;;) {
- len = adb_read(inFd, buf, sizeof(buf));
+ len = adb_read(inFd, buf, BUFSIZE);
if (len == 0) {
+ D("copy_to_file() : read 0 bytes; exiting\n");
break;
}
if (len < 0) {
- if (errno == EINTR) continue;
+ if (errno == EINTR) {
+ D("copy_to_file() : EINTR, retrying\n");
+ continue;
+ }
D("copy_to_file() : error %d\n", errno);
break;
}
@@ -258,6 +263,7 @@
total += len;
}
D("copy_to_file() finished after %lu bytes\n", total);
+ free(buf);
}
static void *stdin_read_thread(void *x)