forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteDebugServerv2.ts
More file actions
52 lines (48 loc) · 1.72 KB
/
Copy pathRemoteDebugServerv2.ts
File metadata and controls
52 lines (48 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { Socket } from 'net';
import { DebugSession } from 'vscode-debugadapter';
import { AttachRequestArguments, IDebugServer, IPythonProcess } from '../Common/Contracts';
import { BaseDebugServer } from './BaseDebugServer';
export class RemoteDebugServerV2 extends BaseDebugServer {
private args: AttachRequestArguments;
private socket?: Socket;
constructor(debugSession: DebugSession, pythonProcess: IPythonProcess, args: AttachRequestArguments) {
super(debugSession, pythonProcess);
this.args = args;
}
public Stop() {
if (this.socket) {
this.socket.destroy();
}
}
public Start(): Promise<IDebugServer> {
return new Promise<IDebugServer>((resolve, reject) => {
const port = this.args.port!;
const options = { port };
if (typeof this.args.host === 'string' && this.args.host.length > 0) {
// tslint:disable-next-line:no-any
(<any>options).host = this.args.host;
}
try {
let connected = false;
const socket = new Socket();
socket.on('error', ex => {
if (connected) {
return;
}
reject(ex);
});
socket.connect(options, () => {
connected = true;
this.socket = socket;
this.clientSocket.resolve(socket);
resolve(options);
});
} catch (ex) {
reject(ex);
}
});
}
}