Try to use the remote port number locally (microsoft/vscode-remote-release#1115)

上级 361cf8ed
......@@ -16,6 +16,7 @@ import { nodeSocketFactory } from 'vs/platform/remote/node/nodeSocketFactory';
import { ISignService } from 'vs/platform/sign/common/sign';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { ILogService } from 'vs/platform/log/common/log';
import { findFreePort } from 'vs/base/node/ports';
export async function createRemoteTunnel(options: IConnectionOptions, tunnelRemotePort: number): Promise<RemoteTunnel> {
const tunnel = new NodeRemoteTunnel(options, tunnelRemotePort);
......@@ -25,7 +26,7 @@ export async function createRemoteTunnel(options: IConnectionOptions, tunnelRemo
class NodeRemoteTunnel extends Disposable implements RemoteTunnel {
public readonly tunnelRemotePort: number;
public readonly tunnelLocalPort: number;
public tunnelLocalPort: number;
private readonly _options: IConnectionOptions;
private readonly _server: net.Server;
......@@ -47,7 +48,7 @@ class NodeRemoteTunnel extends Disposable implements RemoteTunnel {
this._server.on('connection', this._connectionListener);
this.tunnelRemotePort = tunnelRemotePort;
this.tunnelLocalPort = (<net.AddressInfo>this._server.listen(0).address()).port;
}
public dispose(): void {
......@@ -58,6 +59,13 @@ class NodeRemoteTunnel extends Disposable implements RemoteTunnel {
}
public async waitForReady(): Promise<this> {
// try to get the same port number as the remote port number...
const localPort = await findFreePort(this.tunnelRemotePort, 1, 1000);
// if that fails, the method above returns 0, which works out fine below...
this.tunnelLocalPort = (<net.AddressInfo>this._server.listen(localPort).address()).port;
await this._barrier.wait();
return this;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册