Example #1
0
        /*
         * We have some activity on the "debug selected" port. Handle it.
         */
        private void processDebugSelectedActivity(SelectionKey key)
        {
            Debug.Assert(key.acceptable);

            ServerSocketChannel acceptChan = (ServerSocketChannel)key.channel();

            /*
             * Find the debugger associated with the currently-selected client.
             */
            if (mSelectedClient != null)
            {
                Debugger dbg = mSelectedClient.debugger;

                if (dbg != null)
                {
                    Log.d("ddms", "Accepting connection on 'debug selected' port");
                    try
                    {
                        acceptNewDebugger(dbg, acceptChan);
                    }
                    catch (IOException)
                    {
                        // client should be gone, keep going
                    }

                    return;
                }
            }

            Log.w("ddms", "Connection on 'debug selected' port, but none selected");
            try
            {
                SocketChannel chan = acceptChan.accept();
                chan.close();
            }
            catch (IOException)
            {
                // not expected; client should be gone, keep going
            }
            catch (NotYetBoundException)
            {
                displayDebugSelectedBindError(mDebugSelectedPort);
            }
        }
Example #2
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);
        }