JDWP: attempt to fix failure on closed connection

Don't send packet if JDWP connection has been closed while
processing a JDWP command.

We used to DCHECK(IsConnected()) in JdwpNetStateBase::WritePacket
but this is wrong when the connection has been closed by the debugger
(client) before we sent the packet. It seems to happen more during
JDWP tests due to how debugger and debuggee are synchronizing with
each other.

Bug: 22907762
Change-Id: I1c886382268697b4c50755b6009cceac7b8d656e
diff --git a/runtime/jdwp/jdwp_main.cc b/runtime/jdwp/jdwp_main.cc
index 5a9a0f5..1139a1e 100644
--- a/runtime/jdwp/jdwp_main.cc
+++ b/runtime/jdwp/jdwp_main.cc
@@ -126,9 +126,12 @@
  * Write a packet of "length" bytes. Grabs a mutex to assure atomicity.
 ssize_t JdwpNetStateBase::WritePacket(ExpandBuf* pReply, size_t length) {
-  MutexLock mu(Thread::Current(), socket_lock_);
-  DCHECK(IsConnected()) << "Connection with debugger is closed";
   DCHECK_LE(length, expandBufGetLength(pReply));
+  if (!IsConnected()) {
+    LOG(WARNING) << "Connection with debugger is closed";
+    return -1;
+  }
+  MutexLock mu(Thread::Current(), socket_lock_);
   return TEMP_FAILURE_RETRY(write(clientSock, expandBufGetBuffer(pReply), length));