Example #1
0
        /// <summary>
        /// Create a new Debugger object, configured to listen for connections
        /// on a specific port.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: Debugger(Client client, int listenPort) throws java.io.IOException
        internal Debugger(Client client, int listenPort)
        {
            mClient     = client;
            mListenPort = listenPort;

            mListenChannel = ServerSocketChannel.open();
            mListenChannel.configureBlocking(false);             // required for Selector

            var addr = new DnsEndPoint("localhost", listenPort); //$NON-NLS-1$

            mListenChannel.socket().ExclusiveAddressUse = false; // .reuseAddress = true; // enable SO_REUSEADDR
            mListenChannel.socket().Bind(addr);

            mReadBuffer    = ByteBuffer.allocate(INITIAL_BUF_SIZE);
            mPreDataBuffer = ByteBuffer.allocate(PRE_DATA_BUF_SIZE);
            mConnState     = ST_NOT_CONNECTED;

            Log.d("ddms", "Created: " + this.ToString());
        }
Example #2
0
        /// <summary>
        /// Opens (or reopens) the "debug selected" port and listen for connections. </summary>
        /// <returns> true if the port was opened successfully. </returns>
        /// <exception cref="IOException"> </exception>
        private bool reopenDebugSelectedPort()
        {
            Log.d("ddms", "reopen debug-selected port: " + mNewDebugSelectedPort);
            if (mDebugSelectedChan != null)
            {
                mDebugSelectedChan.close();
            }

            mDebugSelectedChan = ServerSocketChannel.open();
            mDebugSelectedChan.configureBlocking(false);                    // required for Selector

            var addr = new DnsEndPoint("localhost", mNewDebugSelectedPort); //$NON-NLS-1$

            mDebugSelectedChan.socket().ExclusiveAddressUse = false;        // enable SO_REUSEADDR

            try
            {
                mDebugSelectedChan.socket().Bind(addr);
                if (mSelectedClient != null)
                {
                    mSelectedClient.update(Client.CHANGE_PORT);
                }

                mDebugSelectedChan.register(mSelector, SelectionKey.OP_ACCEPT, this);

                return(true);
            }
            catch (Exception)
            {
                displayDebugSelectedBindError(mNewDebugSelectedPort);

                // do not attempt to reopen it.
                mDebugSelectedChan    = null;
                mNewDebugSelectedPort = -1;

                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// Tell the thread to stop. Called from UI thread.
        /// </summary>
        internal void quit()
        {
            lock (this)
            {
                mQuit = true;
                wakeup();
                Log.d("ddms", "Waiting for Monitor thread");
                try
                {
                    thread.Join();
                    // since we're quitting, lets drop all the client and disconnect
                    // the DebugSelectedPort
                    lock (mClientList)
                    {
                        foreach (Client c in mClientList)
                        {
                            c.close(false); // notify
                            broadcast(CLIENT_DISCONNECTED, c);
                        }
                        mClientList.Clear();
                    }

                    if (mDebugSelectedChan != null)
                    {
                        mDebugSelectedChan.close();
                        mDebugSelectedChan.socket().Close();
                        mDebugSelectedChan = null;
                    }
                    mSelector.close();
                }
                catch (ThreadInterruptedException ie)
                {
                    Console.WriteLine(ie.ToString());
                    Console.Write(ie.StackTrace);
                }
                catch (IOException e)
                {
                    // TODO Auto-generated catch block
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                }

                mInstance = null;
            }
        }