Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/git/src/ipc/ipcClient.ts
3320 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as http from 'http';
7
8
export class IPCClient {
9
10
private ipcHandlePath: string;
11
12
constructor(private handlerName: string) {
13
const ipcHandlePath = process.env['VSCODE_GIT_IPC_HANDLE'];
14
15
if (!ipcHandlePath) {
16
throw new Error('Missing VSCODE_GIT_IPC_HANDLE');
17
}
18
19
this.ipcHandlePath = ipcHandlePath;
20
}
21
22
call(request: any): Promise<any> {
23
const opts: http.RequestOptions = {
24
socketPath: this.ipcHandlePath,
25
path: `/${this.handlerName}`,
26
method: 'POST'
27
};
28
29
return new Promise((c, e) => {
30
const req = http.request(opts, res => {
31
if (res.statusCode !== 200) {
32
return e(new Error(`Bad status code: ${res.statusCode}`));
33
}
34
35
const chunks: Buffer[] = [];
36
res.on('data', d => chunks.push(d));
37
res.on('end', () => c(JSON.parse(Buffer.concat(chunks).toString('utf8'))));
38
});
39
40
req.on('error', err => e(err));
41
req.write(JSON.stringify(request));
42
req.end();
43
});
44
}
45
}
46
47