am e8e272c5: Merge "EINTR is handled by adb_read/unix_read and friends."

* commit 'e8e272c525fdfe73e646ff94f8b4d1913016919f':
  EINTR is handled by adb_read/unix_read and friends.
This commit is contained in:
Elliott Hughes 2015-08-25 19:57:12 +00:00 committed by Android Git Automerger
commit 12d762e176
6 changed files with 23 additions and 56 deletions

View File

@ -276,10 +276,7 @@ static void read_status_line(int fd, char* buf, size_t count)
count--;
while (count > 0) {
int len = adb_read(fd, buf, count);
if (len == 0) {
break;
} else if (len < 0) {
if (errno == EINTR) continue;
if (len <= 0) {
break;
}
@ -332,11 +329,7 @@ static void copy_to_file(int inFd, int outFd) {
break;
}
if (len < 0) {
if (errno == EINTR) {
D("copy_to_file() : EINTR, retrying\n");
continue;
}
D("copy_to_file() : error %d\n", errno);
D("copy_to_file(): read failed: %s\n", strerror(errno));
break;
}
if (outFd == STDOUT_FILENO) {
@ -386,12 +379,8 @@ static void *stdin_read_thread(void *x)
D("stdin_read_thread(): pre unix_read(fdi=%d,...)\n", fdi);
r = unix_read(fdi, buf, 1024);
D("stdin_read_thread(): post unix_read(fdi=%d,...)\n", fdi);
if(r == 0) break;
if(r < 0) {
if(errno == EINTR) continue;
break;
}
for(n = 0; n < r; n++){
if (r <= 0) break;
for (n = 0; n < r; n++){
switch(buf[n]) {
case '\n':
state = 1;

View File

@ -205,8 +205,8 @@ static void fdevent_process()
n = epoll_wait(epoll_fd, events, 256, -1);
if(n < 0) {
if(errno == EINTR) return;
if (n < 0) {
if (errno == EINTR) return;
perror("epoll_wait");
exit(1);
}

View File

@ -203,13 +203,8 @@ static int write_data_file(SyncConnection& sc, const char* path, syncsendbuf* sb
sbuf->id = ID_DATA;
while (true) {
int ret = adb_read(lfd, sbuf->data, sc.max);
if (!ret)
break;
if (ret < 0) {
if(errno == EINTR)
continue;
fprintf(stderr, "cannot read '%s': %s\n", path, strerror(errno));
if (ret <= 0) {
if (ret < 0) fprintf(stderr, "cannot read '%s': %s\n", path, strerror(errno));
break;
}

View File

@ -325,7 +325,6 @@ static bool do_recv(int s, const char* path, std::vector<char>& buffer) {
int r = adb_read(fd, &buffer[0], buffer.size());
if (r <= 0) {
if (r == 0) break;
if (errno == EINTR) continue;
SendSyncFailErrno(s, "read failed");
adb_close(fd);
return false;

View File

@ -140,8 +140,7 @@ read_packet(int fd, const char* name, apacket** ppacket)
len -= r;
p += r;
} else {
D("%s: read_packet (fd=%d), error ret=%d errno=%d: %s\n", name, fd, r, errno, strerror(errno));
if((r < 0) && (errno == EINTR)) continue;
D("%s: read_packet (fd=%d), error ret=%d: %s\n", name, fd, r, strerror(errno));
return -1;
}
}
@ -171,8 +170,7 @@ write_packet(int fd, const char* name, apacket** ppacket)
len -= r;
p += r;
} else {
D("%s: write_packet (fd=%d) error ret=%d errno=%d: %s\n", name, fd, r, errno, strerror(errno));
if((r < 0) && (errno == EINTR)) continue;
D("%s: write_packet (fd=%d) error ret=%d: %s\n", name, fd, r, strerror(errno));
return -1;
}
}
@ -489,9 +487,7 @@ transport_read_action(int fd, struct tmsg* m)
len -= r;
p += r;
} else {
if((r < 0) && (errno == EINTR)) continue;
D("transport_read_action: on fd %d, error %d: %s\n",
fd, errno, strerror(errno));
D("transport_read_action: on fd %d: %s\n", fd, strerror(errno));
return -1;
}
}
@ -511,9 +507,7 @@ transport_write_action(int fd, struct tmsg* m)
len -= r;
p += r;
} else {
if((r < 0) && (errno == EINTR)) continue;
D("transport_write_action: on fd %d, error %d: %s\n",
fd, errno, strerror(errno));
D("transport_write_action: on fd %d: %s\n", fd, strerror(errno));
return -1;
}
}

View File

@ -431,17 +431,12 @@ static void *usb_ffs_open_thread(void *x)
static int bulk_write(int bulk_in, const uint8_t* buf, size_t length)
{
size_t count = 0;
int ret;
do {
ret = adb_write(bulk_in, buf + count, length - count);
if (ret < 0) {
if (errno != EINTR)
return ret;
} else {
count += ret;
}
} while (count < length);
while (count < length) {
int ret = adb_write(bulk_in, buf + count, length - count);
if (ret < 0) return -1;
count += ret;
}
D("[ bulk_write done fd=%d ]\n", bulk_in);
return count;
@ -462,20 +457,15 @@ static int usb_ffs_write(usb_handle* h, const void* data, int len)
static int bulk_read(int bulk_out, uint8_t* buf, size_t length)
{
size_t count = 0;
int ret;
do {
ret = adb_read(bulk_out, buf + count, length - count);
while (count < length) {
int ret = adb_read(bulk_out, buf + count, length - count);
if (ret < 0) {
if (errno != EINTR) {
D("[ bulk_read failed fd=%d length=%zu count=%zu ]\n",
bulk_out, length, count);
return ret;
}
} else {
count += ret;
D("[ bulk_read failed fd=%d length=%zu count=%zu ]\n", bulk_out, length, count);
return -1;
}
} while (count < length);
count += ret;
}
return count;
}