MCPcopy Create free account
hub / github.com/Marus/cortex-debug / next

Method next

src/remote/src/tcpportscanner.ts:145–178  ·  view source on GitHub ↗
(port: number, host: string)

Source from the content-addressed store, hash-verified

143 return;
144 }
145 function next(port: number, host: string) {
146 ConsoleLog(`findFreePorts: ******** Next ${port}`);
147 const startTine = process.hrtime();
148 TcpPortScanner.isPortInUseEx(port, host).then((inUse) => {
149 const endTime = process.hrtime(startTine);
150 if (inUse) {
151 busyPorts.push(port);
152 ConsoleLog(`Busy ports = ${busyPorts}`);
153 } else {
154 if (consecutive && (freePorts.length > 0) &&
155 (port !== (1 + freePorts[freePorts.length - 1]))) {
156 ConsoleLog('TcpPortHelper.findFreePorts: Oops, reset for consecutive ports requirement');
157 freePorts = [];
158 }
159 freePorts.push(port);
160 ConsoleLog(`Free ports = ${freePorts}`);
161 }
162 if (logEnable) {
163 const ms = (endTime[1] / 1e6).toFixed(2);
164 const t = `${endTime[0]}s ${ms}ms`;
165 ConsoleLog(`TcpPortHelper.findFreePorts Port ${host}:${port} ` +
166 (inUse ? 'busy' : 'free') + `, Found: ${freePorts.length} of ${needed} needed ${t}`);
167 }
168 if (freePorts.length === needed) {
169 resolve(freePorts);
170 } else if (port < max) {
171 next(port + 1, host);
172 } else {
173 reject(new Error(`Only found ${freePorts.length} of ${needed} ports`));
174 }
175 }).catch((err) => {
176 reject(err);
177 });
178 }
179 next(min, host); // Start the hunt
180 });
181 }

Callers

nothing calls this directly

Calls 2

ConsoleLogFunction · 0.70
isPortInUseExMethod · 0.45

Tested by

no test coverage detected