From 0f4c72144a1996be33ed1cd1e6ae3f921abc48b6 Mon Sep 17 00:00:00 2001 From: yu_xiaoyan Date: Wed, 3 Nov 2021 20:34:38 +0800 Subject: [PATCH] =?UTF-8?q?jdwp=EF=BC=9A=E4=BF=AE=E6=94=B9pid=E6=8E=A5?= =?UTF-8?q?=E6=94=B6=E5=A4=84=E7=90=86=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/daemon/jdwp.cpp | 43 ++++++++++++++++--------------------------- src/daemon/jdwp.h | 5 ++--- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/daemon/jdwp.cpp b/src/daemon/jdwp.cpp index 488a66ca..216e822d 100644 --- a/src/daemon/jdwp.cpp +++ b/src/daemon/jdwp.cpp @@ -83,37 +83,26 @@ void HdcJdwp::ReadStream(uv_stream_t *pipe, ssize_t nread, const uv_buf_t *buf) bool ret = false; HCtxJdwp ctxJdwp = (HCtxJdwp)pipe->data; HdcJdwp *thisClass = (HdcJdwp *)ctxJdwp->thisClass; - char temp[5]; + char *p = ctxJdwp->buf; uint32_t pid = 0; - int offset = 0; - if (nread > 0) { - ctxJdwp->bufIndex += nread; + + if (nread == UV_ENOBUFS) { // It is definite enough, usually only 4 bytes + WRITE_LOG(LOG_DEBUG, "HdcJdwp::ReadStream IOBuf max"); + goto free; + } else if (nread <= 0 ) { + WRITE_LOG(LOG_DEBUG, "HdcJdwp::ReadStream program exit pid:%d", ctxJdwp->pid); + return; } - // read the PID as a 4-hexchar string - while (offset < ctxJdwp->bufIndex) { - if (nread == UV_ENOBUFS) { // It is definite enough, usually only 4 bytes - WRITE_LOG(LOG_DEBUG, "HdcJdwp::ReadStream IOBuf max"); - break; - } else if (nread <= 0 || nread != 4) { // 4 : 4 bytes - WRITE_LOG(LOG_DEBUG, "HdcJdwp::ReadStream program exit pid:%d", ctxJdwp->pid); - break; - } - int errCode = memcpy_s(temp, sizeof(temp), ctxJdwp->buf + offset, 4); // 4 : 4 bytes - if (errCode != EOK) { - break; - } - temp[4] = 0; // 4 : pid length - if (sscanf_s(temp, "%04x", &pid) != 1) { - WRITE_LOG(LOG_WARN, "could not decode PID number: '%s'", temp); - break; - } - WRITE_LOG(LOG_DEBUG, "JDWP accept pid:%d", pid); + pid = atoi(p); + if(pid > 0) { + WRITE_LOG(LOG_DEBUG, "JDWP accept pid:%d", pid ); ctxJdwp->pid = pid; thisClass->AdminContext(OP_ADD, pid, ctxJdwp); - offset += 4; // 4 : 4 bytes + WRITE_LOG(LOG_DEBUG, "JDWP OP_ADD :%d", pid ); ret = true; - break; // just 4bytes, now finish } +free: + Base::ZeroArray(ctxJdwp->buf); if (!ret) { thisClass->FreeContext(ctxJdwp); } @@ -135,8 +124,8 @@ void HdcJdwp::AcceptClient(uv_stream_t *server, int status) } auto funAlloc = [](uv_handle_t *handle, size_t sizeSuggested, uv_buf_t *buf) -> void { HCtxJdwp ctxJdwp = (HCtxJdwp)handle->data; - buf->base = (char *)ctxJdwp->buf + ctxJdwp->bufIndex; - buf->len = sizeof(ctxJdwp->buf) - ctxJdwp->bufIndex; + buf->base = (char *)ctxJdwp->buf ; + buf->len = sizeof(ctxJdwp->buf); }; uv_read_start((uv_stream_t *)&ctxJdwp->pipe, funAlloc, ReadStream); } diff --git a/src/daemon/jdwp.h b/src/daemon/jdwp.h index d885f6bc..6463eb34 100644 --- a/src/daemon/jdwp.h +++ b/src/daemon/jdwp.h @@ -17,6 +17,7 @@ #include "daemon_common.h" namespace Hdc { +#define RECV_PID_SIZE sizeof(uint32_t) class HdcJdwp { public: HdcJdwp(uv_loop_t *loopIn); @@ -35,9 +36,7 @@ private: uv_pipe_t pipe; HdcJdwp *thisClass; bool finish; - uint8_t buf[16]; // read read 4 bytes ascii - uint8_t bufIndex; - + char buf[RECV_PID_SIZE]; uint8_t dummy; uv_tcp_t jvmTCP; }; -- Gitee