adb: switch the jdwp control socket to SOCK_SEQPACKET.
Switch the jdwp control socket to SOCK_SEQPACKET so we don't have to
worry about short reads for the PID.
Bug: http://b/36411868
Test: adb jdwp
Change-Id: I908b88e93b1e0ca2895eb8e777d8438a7bbfa92a
diff --git a/adb/jdwp_service.cpp b/adb/jdwp_service.cpp
index af911bf..f0dff06 100644
--- a/adb/jdwp_service.cpp
+++ b/adb/jdwp_service.cpp
@@ -179,8 +179,6 @@
fdevent* fde = nullptr;
std::vector<unique_fd> out_fds;
- char in_buf[PID_LEN + 1];
- ssize_t in_len = 0;
};
static size_t jdwp_process_list(char* buffer, size_t bufferlen) {
@@ -224,29 +222,16 @@
if (events & FDE_READ) {
if (proc->pid < 0) {
/* read the PID as a 4-hexchar string */
- if (proc->in_len < 0) {
- fatal("attempting to read JDWP pid again?");
- }
-
- char* p = proc->in_buf + proc->in_len;
- size_t size = PID_LEN - proc->in_len;
-
- ssize_t rc = TEMP_FAILURE_RETRY(recv(socket, p, size, 0));
- if (rc <= 0) {
+ char buf[PID_LEN + 1];
+ ssize_t rc = TEMP_FAILURE_RETRY(recv(socket, buf, PID_LEN, 0));
+ if (rc != PID_LEN) {
D("failed to read jdwp pid: %s", strerror(errno));
goto CloseProcess;
}
+ buf[PID_LEN] = '\0';
- proc->in_len += rc;
- if (proc->in_len != PID_LEN) {
- return;
- }
-
- proc->in_buf[PID_LEN] = '\0';
- proc->in_len = -1;
-
- if (sscanf(proc->in_buf, "%04x", &proc->pid) != 1) {
- D("could not decode JDWP %p PID number: '%s'", proc, p);
+ if (sscanf(buf, "%04x", &proc->pid) != 1) {
+ D("could not decode JDWP %p PID number: '%s'", proc, buf);
goto CloseProcess;
}
@@ -401,7 +386,7 @@
addr.sun_family = AF_UNIX;
memcpy(addr.sun_path, sockname, socknamelen);
- s = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
+ s = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0);
if (s < 0) {
D("could not create vm debug control socket. %d: %s", errno, strerror(errno));
return -1;