/// <summary> /// Adds the port to available list. /// </summary> /// <param name="port">The port.</param> public void AddPortToAvailableList(int port) { if (port > 0) { lock ( DebuggerPorts ) { // because there could be case where clients are closed twice, we have to make // sure the port number is not already in the list. if (DebuggerPorts.IndexOf(port) == -1) { // add the port to the list while keeping it sorted. It's not like there's // going to be tons of objects so we do it linearly. int count = DebuggerPorts.Count; for (int i = 0; i < count; i++) { if (port < DebuggerPorts[i]) { DebuggerPorts.Insert(i, port); break; } } // TODO: check if we can compact the end of the list. } } } }
/// <summary> /// Gets the next debugger port. /// </summary> /// <returns></returns> private int GetNextDebuggerPort( ) { // get the first port and remove it lock ( DebuggerPorts ) { if (DebuggerPorts.Count > 0) { int port = DebuggerPorts[0]; // remove it. DebuggerPorts.RemoveAt(0); // if there's nothing left, add the next port to the list if (DebuggerPorts.Count == 0) { DebuggerPorts.Add(port + 1); } return(port); } } return(-1); }