/// <summary> /// Add a new Client to the list of things we monitor. Also adds the client's /// channel and the client's debugger listener to the selection list. This /// should only be called from one thread (the VMWatcherThread) to avoid a /// race between "alreadyOpen" and Client creation. /// </summary> internal void addClient(Client client) { lock (this) { if (mInstance == null) { return; } Log.d("ddms", "Adding new client " + client); lock (mClientList) { mClientList.Add(client); /* * Register the Client's socket channel with the selector. We attach * the Client to the SelectionKey. If you try to register a new * channel with the Selector while it is waiting for I/O, you will * block. The solution is to call wakeup() and then hold a lock to * ensure that the registration happens before the Selector goes * back to sleep. */ try { wakeup(); client.register(mSelector); Debugger dbg = client.debugger; if (dbg != null) { dbg.registerListener(mSelector); } } catch (IOException ioe) { // not really expecting this to happen Console.WriteLine(ioe.ToString()); Console.Write(ioe.StackTrace); } } } }