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

Method allocateRTTPorts

src/common.ts:412–457  ·  view source on GitHub ↗
(cfg: RTTConfiguration, startPort: number = 60000)

Source from the content-addressed store, hash-verified

410 // a multiple clients connect to the same channel. Perhaps in the future
411 // it wil
412 public allocateRTTPorts(cfg: RTTConfiguration, startPort: number = 60000): Promise<any> {
413 this.allocDone = true;
414 if (!cfg || !cfg.enabled || !cfg.decoders || cfg.decoders.length === 0) {
415 return Promise.resolve();
416 }
417
418 // Remember that you can have duplicate decoder ports. ie, multiple decoders looking at the same port
419 // while mostly not allowed, it could be in the future. Handle it here but disallow on a case by case
420 // basis depending on the gdb-server type
421 const dummy = '??';
422 for (const dec of cfg.decoders) {
423 if (dec.ports && (dec.ports.length > 0)) {
424 dec.tcpPorts = [];
425 for (const p of dec.ports) {
426 this.rttLocalPortMap[p] = dummy;
427 }
428 } else {
429 this.rttLocalPortMap[dec.port] = dummy;
430 }
431 }
432
433 const count = Object.keys(this.rttLocalPortMap).length;
434 const portFinderOpts = { min: startPort, max: startPort + 2000, retrieve: count, consecutive: false };
435 return TcpPortScanner.findFreePorts(portFinderOpts, GDBServer.LOCALHOST).then((ports) => {
436 for (const dec of cfg.decoders) {
437 if (dec.ports && (dec.ports.length > 0)) {
438 dec.tcpPorts = [];
439 for (const p of dec.ports) {
440 let str = this.rttLocalPortMap[p];
441 if (str === dummy) {
442 str = ports.shift().toString();
443 this.rttLocalPortMap[p] = str;
444 }
445 dec.tcpPorts.push(str);
446 }
447 } else {
448 let str = this.rttLocalPortMap[dec.port];
449 if (str === dummy) {
450 str = ports.shift().toString();
451 this.rttLocalPortMap[dec.port] = str;
452 }
453 dec.tcpPort = str;
454 }
455 }
456 });
457 }
458
459 public emitConfigures(cfg: RTTConfiguration, obj: EventEmitter): boolean {
460 let ret = false;

Callers

nothing calls this directly

Calls 2

toStringMethod · 0.80
findFreePortsMethod · 0.45

Tested by

no test coverage detected