Beispiel #1
0
		/// <summary>
		/// Accept a new connection from the specified listen channel.  This
		/// is so we can listen on a dedicated port for the "current" client,
		/// where "current" is constantly in flux.
		/// 
		/// Must be synchronized with other uses of mChannel and mPreBuffer.
		/// 
		/// Returns "null" if we're already talking to somebody.
		/// </summary>
		internal SocketChannel accept(ServerSocketChannel listenChan)
		{

		    if(listenChan != null)
		    {
		        SocketChannel newChan;

		        newChan = listenChan.accept();
		        if(mChannel != null)
		        {
		            Log.w("ddms", "debugger already talking to " + mClient + " on " + mListenPort);
		            newChan.close();
		            return null;
		        }
		        mChannel = newChan;
		        mChannel.configureBlocking(false); // required for Selector
		        mConnState = ST_AWAIT_SHAKE;
		        return mChannel;

		    }
            return null;
        }
Beispiel #2
0
        /// <summary>
        /// Opens the sync connection. This must be called before any calls to push[File] / pull[File]. </summary>
        /// <returns> true if the connection opened, false if adb refuse the connection. This can happen
        /// if the <seealso cref="Device"/> is invalid. </returns>
        /// <exception cref="TimeoutException"> in case of timeout on the connection. </exception>
        /// <exception cref="AdbCommandRejectedException"> if adb rejects the command </exception>
        /// <exception cref="IOException"> If the connection to adb failed. </exception>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: boolean openSync() throws TimeoutException, AdbCommandRejectedException, java.io.IOException
        internal bool openSync()
        {
            try
            {
                mChannel = SocketChannel.open(mAddress);
                mChannel.configureBlocking(false);

                // target a specific device
                AdbHelper.setDevice(mChannel, mDevice);

                var request = AdbHelper.formAdbRequest("sync:"); //$NON-NLS-1$
                AdbHelper.write(mChannel, request, -1, DdmPreferences.timeOut);

                AdbHelper.AdbResponse resp = AdbHelper.readAdbResponse(mChannel, false); // readDiagString

                if (resp.okay == false)
                {
                    Log.w("ddms", "Got unhappy response from ADB sync req: " + resp.message);
                    mChannel.close();
                    mChannel = null;
                    return false;
                }
            }
            catch (TimeoutException e)
            {
                if (mChannel != null)
                {
                    try
                    {
                        mChannel.close();
                    }
                    catch (IOException)
                    {
                        // we want to throw the original exception, so we ignore this one.
                    }
                    mChannel = null;
                }

                throw e;
            }
            catch (IOException e)
            {
                if (mChannel != null)
                {
                    try
                    {
                        mChannel.close();
                    }
                    catch (IOException)
                    {
                        // we want to throw the original exception, so we ignore this one.
                    }
                    mChannel = null;
                }

                throw e;
            }

            return true;
        }