Example #1
0
        /// <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();
            }
        }
Example #2
0
        /// <summary>
        /// Write our packet to "chan".  Consumes the packet as part of the
        /// write.
        ///
        /// The JDWP packet starts at offset 0 and ends at mBuffer.position().
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: void writeAndConsume(java.nio.channels.SocketChannel chan) throws java.io.IOException
        internal void writeAndConsume(SocketChannel chan)
        {
            int oldLimit;

            //Log.i("ddms", "writeAndConsume: pos=" + mBuffer.position()
            //    + ", limit=" + mBuffer.limit());

            Debug.Assert(mLength > 0);

            mBuffer.flip();             // limit<-posn, posn<-0
            oldLimit      = mBuffer.limit;
            mBuffer.limit = (mLength);
            while (mBuffer.position != mBuffer.limit)
            {
                chan.write(mBuffer);
            }
            // position should now be at end of packet
            Debug.Assert(mBuffer.position == mLength);

            mBuffer.limit = (oldLimit);
            mBuffer.compact();             // shift posn...limit, posn<-pending data

            //Log.i("ddms", "               : pos=" + mBuffer.position()
            //    + ", limit=" + mBuffer.limit());
        }
Example #3
0
        /// <summary>
        /// Write until all data in "data" is written, the optional length is reached,
        /// the timeout expires, or the connection fails. Returns "true" if all
        /// data was written. </summary>
        /// <param name="chan"> the opened socket to write to. </param>
        /// <param name="data"> the buffer to send. </param>
        /// <param name="length"> the length to write or -1 to send the whole buffer. </param>
        /// <param name="timeout"> The timeout value. A timeout of zero means "wait forever". </param>
        /// <exception cref="TimeoutException"> in case of timeout on the connection. </exception>
        /// <exception cref="IOException"> in case of I/O error on the connection. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static void write(java.nio.channels.SocketChannel chan, byte[] data, int length, int timeout) throws TimeoutException, java.io.IOException
        internal static void write(SocketChannel chan, byte[] data, int length, int timeout)
        {
            ByteBuffer buf      = ByteBuffer.wrap(data, 0, length != -1 ? length : data.Length);
            int        numWaits = 0;

            while (buf.position != buf.limit)
            {
                int count;

                count = chan.write(buf);
                if (count < 0)
                {
                    Log.d("ddms", "write: channel EOF");
                    throw new IOException("channel EOF");
                }
                else if (count == 0)
                {
                    // TODO: need more accurate timeout?
                    if (timeout != 0 && numWaits * WAIT_TIME > timeout)
                    {
                        Log.d("ddms", "write: timeout");
                        throw new TimeoutException();
                    }
                    // non-blocking spin
                    Thread.Sleep(WAIT_TIME);
                    numWaits++;
                }
                else
                {
                    numWaits = 0;
                }
            }
        }
Example #4
0
        /// <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);
        }
Example #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void write(byte[] buffer, int offset, int Length) throws java.io.IOException
            public virtual void write(sbyte[] buffer, int offset, int Length)
            {
                socketChannel.write(ByteBuffer.wrap(buffer, 0, Length));
            }