Archived
1
0

Get forked watcher & searcher working

This commit is contained in:
Asher
2019-01-23 13:43:20 -06:00
committed by Kyle Carberry
parent 4cd6bed8d2
commit 5cb657b415
6 changed files with 40 additions and 36 deletions

View File

@ -217,7 +217,7 @@ export class Client {
clientMsg.setNewSession(newSess);
this.connection.send(clientMsg.serializeBinary());
const serverProc = new ServerProcess(this.connection, id, options ? options.tty !== undefined : false);
const serverProc = new ServerProcess(this.connection, id, options ? options.tty !== undefined : false, isBootstrapFork);
serverProc.stdin.on("close", () => {
const c = new CloseSessionInputMessage();
c.setId(id);

View File

@ -38,14 +38,16 @@ export class ServerProcess extends events.EventEmitter implements ChildProcess {
public readonly stdin = new stream.Writable();
public readonly stdout = new stream.Readable({ read: (): boolean => true });
public readonly stderr = new stream.Readable({ read: (): boolean => true });
public pid: number | undefined;
private _pid: number | undefined;
private _killed: boolean = false;
private _connected: boolean = false;
public constructor(
private readonly connection: ReadWriteConnection,
private readonly id: number,
private readonly hasTty: boolean = false,
private readonly ipc: boolean = false,
) {
super();
if (!this.hasTty) {
@ -53,6 +55,19 @@ export class ServerProcess extends events.EventEmitter implements ChildProcess {
}
}
public get pid(): number | undefined {
return this._pid;
}
public set pid(pid: number | undefined) {
this._pid = pid;
this._connected = true;
}
public get connected(): boolean {
return this._connected;
}
public get killed(): boolean {
return this._killed;
}
@ -68,9 +83,10 @@ export class ServerProcess extends events.EventEmitter implements ChildProcess {
this.connection.send(client.serializeBinary());
this._killed = true;
this._connected = false;
}
public send(message: string | Uint8Array | any, ipc: boolean = false): void {
public send(message: string | Uint8Array | any, ipc: boolean = this.ipc): void {
const send = new WriteToSessionMessage();
send.setId(this.id);
send.setSource(ipc ? WriteToSessionMessage.Source.IPC : WriteToSessionMessage.Source.STDIN);

View File

@ -46,7 +46,7 @@ export class CP {
public fork = (modulePath: string, args?: ReadonlyArray<string> | cp.ForkOptions, options?: cp.ForkOptions): cp.ChildProcess => {
//@ts-ignore
return this.client.fork(options && options.env && options.env.AMD_ENTRYPOINT || modulePath, args, options);
return this.client.bootstrapFork(options && options.env && options.env.AMD_ENTRYPOINT || modulePath);
}
public spawn = (command: string, args?: ReadonlyArray<string> | cp.SpawnOptions, options?: cp.SpawnOptions): cp.ChildProcess => {

View File

@ -63,6 +63,7 @@ export const handleNewSession = (connection: SendableConnection, newSession: New
stdin: proc.stdin,
stderr: proc.stderr,
stdout: proc.stdout,
stdio: proc.stdio,
on: (...args: any[]) => (<any>proc.on)(...args),
write: (d) => proc.stdin.write(d),
kill: (s) => proc.kill(s || "SIGTERM"),