Exemplo n.º 1
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;
				}
			}
		}
Exemplo n.º 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());
        }