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

Method next

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

Source from the content-addressed store, hash-verified

163 return;
164 }
165 function next(port: number, host: string) {
166 ConsoleLog(`findFreePorts: ******** Next ${port}`);
167 const startTine = process.hrtime();
168 TcpPortScanner.isPortInUseEx(port, host, TcpPortScanner.AvoidPorts).then((inUse) => {
169 const endTime = process.hrtime(startTine);
170 if (inUse) {
171 busyPorts.push(port);
172 ConsoleLog(`Busy ports = ${busyPorts}`);
173 } else {
174 if (consecutive && (freePorts.length > 0) &&
175 (port !== (1 + freePorts[freePorts.length - 1]))) {
176 ConsoleLog('TcpPortHelper.findFreePorts: Oops, reset for consecutive ports requirement');
177 freePorts = [];
178 }
179 freePorts.push(port);
180 ConsoleLog(`Free ports = ${freePorts}`);
181 }
182 if (logEnable) {
183 const ms = (endTime[1] / 1e6).toFixed(2);
184 const t = `${endTime[0]}s ${ms}ms`;
185 ConsoleLog(`TcpPortHelper.findFreePorts Port ${host}:${port} ` +
186 (inUse ? 'busy' : 'free') + `, Found: ${freePorts.length} of ${needed} needed ${t}`);
187 }
188 if (freePorts.length === needed) {
189 doResolve(freePorts);
190 } else if (port < max) {
191 next(port + 1, host);
192 } else {
193 reject(new Error(`Only found ${freePorts.length} of ${needed} ports`));
194 }
195 }).catch((err) => {
196 reject(err);
197 });
198 }
199 next(min, host); // Start the hunt
200 });
201 }

Callers

nothing calls this directly

Calls 2

ConsoleLogFunction · 0.70
isPortInUseExMethod · 0.45

Tested by

no test coverage detected