mirror of
https://github.com/coder/code-server.git
synced 2026-05-11 23:07:27 +02:00
Convert fully to protobuf (was partially JSON) (#402)
* Convert fully to protobuf (was partially JSON) * Handle all floating promises * Remove stringified proto from trace logging It wasn't proving to be very useful.
This commit is contained in:
@@ -3,6 +3,8 @@ import { ServerProxy } from "../../common/proxy";
|
||||
import { preserveEnv } from "../../common/util";
|
||||
import { WritableProxy, ReadableProxy } from "./stream";
|
||||
|
||||
// tslint:disable completed-docs
|
||||
|
||||
export type ForkProvider = (modulePath: string, args?: string[], options?: cp.ForkOptions) => cp.ChildProcess;
|
||||
|
||||
export class ChildProcessProxy implements ServerProxy {
|
||||
@@ -26,7 +28,7 @@ export class ChildProcessProxy implements ServerProxy {
|
||||
|
||||
// tslint:disable-next-line no-any
|
||||
public async send(message: any): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise((resolve, reject): void => {
|
||||
this.process.send(message, (error) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
@@ -46,8 +48,8 @@ export class ChildProcessProxy implements ServerProxy {
|
||||
}
|
||||
|
||||
public async dispose(): Promise<void> {
|
||||
this.kill();
|
||||
setTimeout(() => this.kill("SIGKILL"), 5000); // Double tap.
|
||||
this.process.kill();
|
||||
setTimeout(() => this.process.kill("SIGKILL"), 5000); // Double tap.
|
||||
}
|
||||
|
||||
// tslint:disable-next-line no-any
|
||||
@@ -62,9 +64,9 @@ export class ChildProcessProxy implements ServerProxy {
|
||||
|
||||
export interface ChildProcessProxies {
|
||||
childProcess: ChildProcessProxy;
|
||||
stdin?: WritableProxy;
|
||||
stdout?: ReadableProxy;
|
||||
stderr?: ReadableProxy;
|
||||
stdin?: WritableProxy | null;
|
||||
stdout?: ReadableProxy | null;
|
||||
stderr?: ReadableProxy | null;
|
||||
}
|
||||
|
||||
export class ChildProcessModuleProxy {
|
||||
|
||||
@@ -4,6 +4,8 @@ import { ServerProxy } from "../../common/proxy";
|
||||
import { IEncodingOptions } from "../../common/util";
|
||||
import { WritableProxy } from "./stream";
|
||||
|
||||
// tslint:disable completed-docs
|
||||
|
||||
/**
|
||||
* A serializable version of fs.Stats.
|
||||
*/
|
||||
@@ -41,13 +43,13 @@ export class WriteStreamProxy extends WritableProxy<fs.WriteStream> {
|
||||
}
|
||||
|
||||
public async dispose(): Promise<void> {
|
||||
super.dispose();
|
||||
await super.dispose();
|
||||
this.stream.close();
|
||||
}
|
||||
|
||||
// tslint:disable-next-line no-any
|
||||
public async onEvent(cb: (event: string, ...args: any[]) => void): Promise<void> {
|
||||
super.onEvent(cb);
|
||||
await super.onEvent(cb);
|
||||
this.stream.on("open", (fd) => cb("open", fd));
|
||||
}
|
||||
}
|
||||
@@ -109,7 +111,7 @@ export class FsModuleProxy {
|
||||
}
|
||||
|
||||
public exists(path: fs.PathLike): Promise<boolean> {
|
||||
return promisify(fs.exists)(path);
|
||||
return promisify(fs.exists)(path); // tslint:disable-line deprecation
|
||||
}
|
||||
|
||||
public fchmod(fd: number, mode: string | number): Promise<void> {
|
||||
@@ -173,7 +175,7 @@ export class FsModuleProxy {
|
||||
}
|
||||
|
||||
public read(fd: number, length: number, position: number | null): Promise<{ bytesRead: number, buffer: Buffer }> {
|
||||
const buffer = new Buffer(length);
|
||||
const buffer = Buffer.alloc(length);
|
||||
|
||||
return promisify(fs.read)(fd, buffer, 0, length, position);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import * as net from "net";
|
||||
import { ServerProxy } from "../../common/proxy";
|
||||
import { DuplexProxy } from "./stream";
|
||||
|
||||
// tslint:disable completed-docs
|
||||
|
||||
export class NetSocketProxy extends DuplexProxy<net.Socket> {
|
||||
public async connect(options: number | string | net.SocketConnectOpts, host?: string): Promise<void> {
|
||||
this.stream.connect(options as any, host as any); // tslint:disable-line no-any this works fine
|
||||
@@ -28,7 +30,7 @@ export class NetSocketProxy extends DuplexProxy<net.Socket> {
|
||||
|
||||
// tslint:disable-next-line no-any
|
||||
public async onEvent(cb: (event: string, ...args: any[]) => void): Promise<void> {
|
||||
super.onEvent(cb);
|
||||
await super.onEvent(cb);
|
||||
this.stream.on("connect", () => cb("connect"));
|
||||
this.stream.on("lookup", (error, address, family, host) => cb("lookup", error, address, family, host));
|
||||
this.stream.on("timeout", () => cb("timeout"));
|
||||
|
||||
@@ -4,6 +4,8 @@ import * as pty from "node-pty";
|
||||
import { ServerProxy } from "../../common/proxy";
|
||||
import { preserveEnv } from "../../common/util";
|
||||
|
||||
// tslint:disable completed-docs
|
||||
|
||||
/**
|
||||
* Server-side IPty proxy.
|
||||
*/
|
||||
@@ -22,7 +24,7 @@ export class NodePtyProcessProxy implements ServerProxy {
|
||||
}
|
||||
}, 200);
|
||||
|
||||
this.onDone(() => clearInterval(timer));
|
||||
this.process.on("exit", () => clearInterval(timer));
|
||||
}
|
||||
|
||||
public async getPid(): Promise<number> {
|
||||
@@ -50,8 +52,8 @@ export class NodePtyProcessProxy implements ServerProxy {
|
||||
}
|
||||
|
||||
public async dispose(): Promise<void> {
|
||||
this.kill();
|
||||
setTimeout(() => this.kill("SIGKILL"), 5000); // Double tap.
|
||||
this.process.kill();
|
||||
setTimeout(() => this.process.kill("SIGKILL"), 5000); // Double tap.
|
||||
this.emitter.removeAllListeners();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ import { EventEmitter } from "events";
|
||||
import * as spdlog from "spdlog";
|
||||
import { ServerProxy } from "../../common/proxy";
|
||||
|
||||
// tslint:disable completed-docs
|
||||
|
||||
export class RotatingLoggerProxy implements ServerProxy {
|
||||
private readonly emitter = new EventEmitter();
|
||||
|
||||
@@ -24,7 +26,7 @@ export class RotatingLoggerProxy implements ServerProxy {
|
||||
}
|
||||
|
||||
public async dispose(): Promise<void> {
|
||||
this.flush();
|
||||
await this.flush();
|
||||
this.emitter.emit("dispose");
|
||||
this.emitter.removeAllListeners();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import * as stream from "stream";
|
||||
import { ServerProxy } from "../../common/proxy";
|
||||
|
||||
// tslint:disable completed-docs
|
||||
|
||||
export class WritableProxy<T extends stream.Writable = stream.Writable> implements ServerProxy {
|
||||
public constructor(protected readonly stream: T) {}
|
||||
|
||||
@@ -100,7 +102,7 @@ export class DuplexProxy<T extends stream.Duplex = stream.Duplex> extends Writab
|
||||
|
||||
// tslint:disable-next-line no-any
|
||||
public async onEvent(cb: (event: string, ...args: any[]) => void): Promise<void> {
|
||||
super.onEvent(cb);
|
||||
await super.onEvent(cb);
|
||||
this.stream.on("data", (chunk) => cb("data", chunk));
|
||||
this.stream.on("end", () => cb("end"));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import * as trash from "trash";
|
||||
|
||||
// tslint:disable completed-docs
|
||||
|
||||
export class TrashModuleProxy {
|
||||
public async trash(path: string, options?: trash.Options): Promise<void> {
|
||||
return trash(path, options);
|
||||
|
||||
Reference in New Issue
Block a user