/// <summary> /// Send the handshake to the debugger. We also send along any packets /// we already received from the client (usually just a VM_START event, /// if anything at all). /// </summary> private /*synchronized*/ void sendHandshake() { ByteBuffer tempBuffer = ByteBuffer.allocate(JdwpPacket.HANDSHAKE_LEN); JdwpPacket.putHandshake(tempBuffer); int expectedLength = tempBuffer.position; tempBuffer.flip(); if (mChannel.write(tempBuffer) != expectedLength) { throw new IOException("partial handshake write"); } expectedLength = mPreDataBuffer.position; if (expectedLength > 0) { Log.d("ddms", "Sending " + mPreDataBuffer.position + " bytes of saved data"); mPreDataBuffer.flip(); if (mChannel.write(mPreDataBuffer) != expectedLength) { throw new IOException("partial pre-data write"); } mPreDataBuffer.clear(); } }
/// <summary> /// Initiate the JDWP handshake. /// /// On failure, closes the socket and returns false. /// </summary> internal virtual bool sendHandshake() { Debug.Assert(mWriteBuffer.position == 0); try { // assume write buffer can hold 14 bytes JdwpPacket.putHandshake(mWriteBuffer); int expectedLen = mWriteBuffer.position; mWriteBuffer.flip(); if (mChan.write(mWriteBuffer) != expectedLen) { throw new IOException("partial handshake write"); } } catch (IOException ioe) { Log.e("ddms-client", "IO error during handshake: " + ioe.Message); mConnState = ST_ERROR; close(true); // notify return(false); } finally { mWriteBuffer.clear(); } mConnState = ST_AWAIT_SHAKE; return(true); }