forked from microsoft/vscode-gradle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildServerConnector.ts
47 lines (42 loc) · 1.47 KB
/
BuildServerConnector.ts
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
import * as net from "net";
import * as rpc from "vscode-jsonrpc/node";
import { getRandomPipeName } from "../util/generateRandomPipeName";
/**
* Creates a named pipe file and sets up a pipe server
* for communication with the build server.
*/
export class BuildServerConnector {
private serverConnection: rpc.MessageConnection | null = null;
private serverPipeServer: net.Server;
private serverPipePath: string;
/**
* Generates a random pipe name, creates a pipe server and
* waiting for the connection from the Java build server.
*/
public setupBuildServerPipeStream(): boolean {
this.serverPipePath = getRandomPipeName();
if (this.serverPipePath === "") {
return false;
}
this.serverPipeServer = net.createServer((socket: net.Socket) => {
this.serverConnection = rpc.createMessageConnection(
new rpc.StreamMessageReader(socket),
new rpc.StreamMessageWriter(socket)
);
this.serverConnection.listen();
});
this.serverPipeServer.listen(this.serverPipePath);
return true;
}
public getServerConnection(): rpc.MessageConnection | null {
return this.serverConnection;
}
public getServerPipePath(): string {
return this.serverPipePath;
}
public close(): void {
this.serverConnection?.end();
this.serverConnection?.dispose();
this.serverPipeServer.close();
}
}