diff --git a/src/daemon/jdwp.cpp b/src/daemon/jdwp.cpp index 488a66ca51fcf1c4965c1c6554270c33d2a267c6..216e822d2896da2f7b84880e71798f60f92f9974 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 d885f6bc78a38c98b56d3d30c77419fe5c268cce..6463eb349ed46d4269051314e398d2c99930bbe2 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; };