summaryrefslogtreecommitdiffstats
path: root/runtime/jdwp/jdwp_main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/jdwp/jdwp_main.cc')
-rw-r--r--runtime/jdwp/jdwp_main.cc15
1 files changed, 8 insertions, 7 deletions
diff --git a/runtime/jdwp/jdwp_main.cc b/runtime/jdwp/jdwp_main.cc
index 500585d..77c963f 100644
--- a/runtime/jdwp/jdwp_main.cc
+++ b/runtime/jdwp/jdwp_main.cc
@@ -122,11 +122,12 @@ void JdwpNetStateBase::Close() {
}
/*
- * Write a packet. Grabs a mutex to assure atomicity.
+ * Write a packet of "length" bytes. Grabs a mutex to assure atomicity.
*/
-ssize_t JdwpNetStateBase::WritePacket(ExpandBuf* pReply) {
+ssize_t JdwpNetStateBase::WritePacket(ExpandBuf* pReply, size_t length) {
MutexLock mu(Thread::Current(), socket_lock_);
- return TEMP_FAILURE_RETRY(write(clientSock, expandBufGetBuffer(pReply), expandBufGetLength(pReply)));
+ DCHECK_LE(length, expandBufGetLength(pReply));
+ return TEMP_FAILURE_RETRY(write(clientSock, expandBufGetBuffer(pReply), length));
}
/*
@@ -173,7 +174,7 @@ void JdwpState::SendRequest(ExpandBuf* pReq) {
}
errno = 0;
- ssize_t actual = netState->WritePacket(pReq);
+ ssize_t actual = netState->WritePacket(pReq, expandBufGetLength(pReq));
if (static_cast<size_t>(actual) != expandBufGetLength(pReq)) {
PLOG(ERROR) << StringPrintf("Failed to send JDWP packet to debugger (%zd of %zu)",
actual, expandBufGetLength(pReq));
@@ -387,8 +388,8 @@ bool JdwpState::HandlePacket() {
JDWP::Request request(netStateBase->input_buffer_, netStateBase->input_count_);
ExpandBuf* pReply = expandBufAlloc();
- ProcessRequest(request, pReply);
- ssize_t cc = netStateBase->WritePacket(pReply);
+ size_t replyLength = ProcessRequest(request, pReply);
+ ssize_t cc = netStateBase->WritePacket(pReply, replyLength);
/*
* We processed this request and sent its reply. Notify other threads waiting for us they can now
@@ -396,7 +397,7 @@ bool JdwpState::HandlePacket() {
*/
EndProcessingRequest();
- if (cc != (ssize_t) expandBufGetLength(pReply)) {
+ if (cc != static_cast<ssize_t>(replyLength)) {
PLOG(ERROR) << "Failed sending reply to debugger";
expandBufFree(pReply);
return false;