Beispiel #1
0
        /*
         * Something happened. Figure out what.
         */
        private void processClientActivity(SelectionKey key)
        {
            Client client = (Client)key.attachment();

            try
            {
                if (key.readable == false || key.valid == false)
                {
                    Log.d("ddms", "Invalid key from " + client + ". Dropping client.");
                    dropClient(client, true);                     // notify
                    return;
                }

                client.read();

                /*
                 * See if we have a full packet in the buffer. It's possible we have
                 * more than one packet, so we have to loop.
                 */
                JdwpPacket packet = client.jdwpPacket;
                while (packet != null)
                {
                    if (packet.ddmPacket)
                    {
                        // unsolicited DDM request - hand it off
                        Debug.Assert(!packet.reply);
                        callHandler(client, packet, null);
                        packet.consume();
                    }
                    else if (packet.reply && client.isResponseToUs(packet.id) != null)
                    {
                        // reply to earlier DDM request
                        ChunkHandler handler = client.isResponseToUs(packet.id);
                        if (packet.error)
                        {
                            client.packetFailed(packet);
                        }
                        else if (packet.empty)
                        {
                            Log.d("ddms", "Got empty reply for 0x" + packet.id.toHexString() + " from " + client);
                        }
                        else
                        {
                            callHandler(client, packet, handler);
                        }
                        packet.consume();
                        client.removeRequestId(packet.id);
                    }
                    else
                    {
                        Log.v("ddms", "Forwarding client " + (packet.reply ? "reply" : "event") + " 0x" + packet.id.toHexString() + " to " + client.debugger);
                        client.forwardPacketToDebugger(packet);
                    }

                    // find next
                    packet = client.jdwpPacket;
                }
            }
            catch (CancelledKeyException)
            {
                // key was canceled probably due to a disconnected client before we could
                // read stuff coming from the client, so we drop it.
                dropClient(client, true);                 // notify
            }
            catch (IOException)
            {
                // something closed down, no need to print anything. The client is simply dropped.
                dropClient(client, true);                 // notify
            }
            catch (Exception ex)
            {
                Log.e("ddms", ex);

                /* close the client; automatically un-registers from selector */
                dropClient(client, true);                 // notify

                if (ex is OverflowException)
                {
                    Log.w("ddms", "Client data packet exceeded maximum buffer size " + client);
                }
                else
                {
                    // don't know what this is, display it
                    Log.e("ddms", ex);
                }
            }
        }