private void DeviceClientMonitorLoop( ) { do { try { // This synchronized block stops us from doing the select() if a new // Device is being added. // @see startMonitoringDevice() lock ( Devices ) { } //int count = Selector.Select ( ); int count = 0; if (!IsRunning) { return; } lock ( ClientsToReopen ) { if (ClientsToReopen.Count > 0) { Dictionary <IClient, int> .KeyCollection clients = ClientsToReopen.Keys; MonitorThread monitorThread = MonitorThread.Instance; foreach (IClient client in clients) { Device device = client.DeviceImplementation; int pid = client.ClientData.Pid; monitorThread.DropClient(client, false /* notify */); // This is kinda bad, but if we don't wait a bit, the client // will never answer the second handshake! WaitBeforeContinue( ); int port = ClientsToReopen[client]; if (port == DebugPortManager.NO_STATIC_PORT) { port = GetNextDebuggerPort( ); } Log.d("DeviceMonitor", "Reopening " + client); OpenClient(device, pid, port, monitorThread); device.OnClientListChanged(EventArgs.Empty); } ClientsToReopen.Clear( ); } } if (count == 0) { continue; } /*List<SelectionKey> keys = Selector.selectedKeys(); * List<SelectionKey>.Enumerator iter = keys.GetEnumerator(); * * while (iter.MoveNext()) { * SelectionKey key = iter.next(); * iter.remove(); * * if (key.isValid() && key.isReadable()) { * Object attachment = key.attachment(); * * if (attachment instanceof Device) { * Device device = (Device)attachment; * * SocketChannel socket = device.getClientMonitoringSocket(); * * if (socket != null) { * try { * int length = readLength(socket, mLengthBuffer2); * * processIncomingJdwpData(device, socket, length); * } catch (IOException ioe) { * Log.d("DeviceMonitor", * "Error reading jdwp list: " + ioe.getMessage()); * socket.close(); * * // restart the monitoring of that device * synchronized (mDevices) { * if (mDevices.contains(device)) { * Log.d("DeviceMonitor", * "Restarting monitoring service for " + device); * startMonitoringDevice(device); * } * } * } * } * } * } * }*/ } catch (IOException e) { if (!IsRunning) { } } } while (IsRunning); }