Handle error case for candidate ports

Part of microsoft/vscode-remote-release#2776
This commit is contained in:
Alex Ross
2020-11-13 17:14:51 +01:00
parent c6efea07b0
commit 9d389f0364

View File

@@ -192,15 +192,19 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe
return ports;
}
private getSockets(stdout: string) {
private getSockets(stdout: string): { pid: number, socket: number }[] {
const lines = stdout.trim().split('\n');
return lines.map(line => {
const mapped: { pid: number, socket: number }[] = [];
lines.forEach(line => {
const match = /\/proc\/(\d+)\/fd\/\d+ -> socket:\[(\d+)\]/.exec(line)!;
return {
pid: parseInt(match[1], 10),
socket: parseInt(match[2], 10)
};
if (match && match.length >= 3) {
mapped.push({
pid: parseInt(match[1], 10),
socket: parseInt(match[2], 10)
});
}
});
return mapped;
}
private loadListeningPorts(...stdouts: string[]): { socket: number, ip: string, port: number }[] {