diff options
author | JP Abgrall <jpa@google.com> | 2014-03-11 18:42:18 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-03-11 18:42:18 +0000 |
commit | a4a9e64668ce1980e7c39e476aee89b106f6517a (patch) | |
tree | 0412aba27e598adc47c235223117691812047392 /adb | |
parent | 1c297349d5322ae83529e229e5dff249da7b4878 (diff) | |
parent | 66e95d76c47a3a099931bbebe7f4a0af4d3f7fbb (diff) | |
download | system_core-a4a9e64668ce1980e7c39e476aee89b106f6517a.zip system_core-a4a9e64668ce1980e7c39e476aee89b106f6517a.tar.gz system_core-a4a9e64668ce1980e7c39e476aee89b106f6517a.tar.bz2 |
am 66e95d76: Merge "Fix adb forward --list when forwarding a lot"
* commit '66e95d76c47a3a099931bbebe7f4a0af4d3f7fbb':
Fix adb forward --list when forwarding a lot
Diffstat (limited to 'adb')
-rw-r--r-- | adb/adb.c | 34 | ||||
-rw-r--r-- | adb/adb_client.c | 5 | ||||
-rw-r--r-- | adb/transport.c | 4 |
3 files changed, 24 insertions, 19 deletions
@@ -318,6 +318,15 @@ static size_t fill_connect_data(char *buf, size_t bufsize) #endif } +static void send_msg_with_okay(int fd, char* msg, size_t msglen) { + char header[9]; + if (msglen > 0xffff) + msglen = 0xffff; + snprintf(header, sizeof(header), "OKAY%04x", (unsigned)msglen); + writex(fd, header, 8); + writex(fd, msg, msglen); +} + static void send_connect(atransport *t) { D("Calling send_connect \n"); @@ -1421,7 +1430,6 @@ int adb_main(int is_daemon, int server_port) int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s) { atransport *transport = NULL; - char buf[4096]; if(!strcmp(service, "kill")) { fprintf(stderr,"adb server killed by remote request\n"); @@ -1467,13 +1475,11 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r char buffer[4096]; int use_long = !strcmp(service+7, "-l"); if (use_long || service[7] == 0) { - memset(buf, 0, sizeof(buf)); memset(buffer, 0, sizeof(buffer)); D("Getting device list \n"); list_transports(buffer, sizeof(buffer), use_long); - snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer),buffer); D("Wrote device list \n"); - writex(reply_fd, buf, strlen(buf)); + send_msg_with_okay(reply_fd, buffer, strlen(buffer)); return 0; } } @@ -1502,8 +1508,7 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r } } - snprintf(buf, sizeof(buf), "OKAY%04x%s",(unsigned)strlen(buffer), buffer); - writex(reply_fd, buf, strlen(buf)); + send_msg_with_okay(reply_fd, buffer, strlen(buffer)); return 0; } @@ -1511,8 +1516,7 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r if (!strcmp(service, "version")) { char version[12]; snprintf(version, sizeof version, "%04x", ADB_SERVER_VERSION); - snprintf(buf, sizeof buf, "OKAY%04x%s", (unsigned)strlen(version), version); - writex(reply_fd, buf, strlen(buf)); + send_msg_with_okay(reply_fd, version, strlen(version)); return 0; } @@ -1522,8 +1526,7 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r if (transport && transport->serial) { out = transport->serial; } - snprintf(buf, sizeof buf, "OKAY%04x%s",(unsigned)strlen(out),out); - writex(reply_fd, buf, strlen(buf)); + send_msg_with_okay(reply_fd, out, strlen(out)); return 0; } if(!strncmp(service,"get-devpath",strlen("get-devpath"))) { @@ -1532,8 +1535,7 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r if (transport && transport->devpath) { out = transport->devpath; } - snprintf(buf, sizeof buf, "OKAY%04x%s",(unsigned)strlen(out),out); - writex(reply_fd, buf, strlen(buf)); + send_msg_with_okay(reply_fd, out, strlen(out)); return 0; } // indicates a new emulator instance has started @@ -1547,14 +1549,11 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r if(!strcmp(service,"list-forward")) { // Create the list of forward redirections. - char header[9]; int buffer_size = format_listeners(NULL, 0); // Add one byte for the trailing zero. char* buffer = malloc(buffer_size+1); (void) format_listeners(buffer, buffer_size+1); - snprintf(header, sizeof header, "OKAY%04x", buffer_size); - writex(reply_fd, header, 8); - writex(reply_fd, buffer, buffer_size); + send_msg_with_okay(reply_fd, buffer, buffer_size); free(buffer); return 0; } @@ -1643,8 +1642,7 @@ int handle_host_request(char *service, transport_type ttype, char* serial, int r if(!strncmp(service,"get-state",strlen("get-state"))) { transport = acquire_one_transport(CS_ANY, ttype, serial, NULL); char *state = connection_state_name(transport); - snprintf(buf, sizeof buf, "OKAY%04x%s",(unsigned)strlen(state),state); - writex(reply_fd, buf, strlen(buf)); + send_msg_with_okay(reply_fd, state, strlen(state)); return 0; } return -1; diff --git a/adb/adb_client.c b/adb/adb_client.c index 586cd7b..1e47486 100644 --- a/adb/adb_client.c +++ b/adb/adb_client.c @@ -324,7 +324,10 @@ char *adb_query(const char *service) buf[4] = 0; n = strtoul(buf, 0, 16); - if(n > 1024) goto oops; + if(n >= 0xffff) { + strcpy(__adb_error, "reply is too long (>= 64kB)"); + goto oops; + } tmp = malloc(n + 1); if(tmp == 0) goto oops; diff --git a/adb/transport.c b/adb/transport.c index 6002530..58f685c 100644 --- a/adb/transport.c +++ b/adb/transport.c @@ -1188,6 +1188,10 @@ int writex(int fd, const void *ptr, size_t len) D("writex: fd=%d error %d: %s\n", fd, errno, strerror(errno)); if (errno == EINTR) continue; + if (errno == EAGAIN || errno == EWOULDBLOCK) { + adb_sleep_ms(1); // just yield some cpu time + continue; + } } else { D("writex: fd=%d disconnected\n", fd); } |