Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/win/conpty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,9 @@ static Napi::Value PtyKill(const Napi::CallbackInfo& info) {
pfnClosePseudoConsole(handle->hpc);
}
}
TerminateProcess(handle->hShell, 1);
if (useConptyDll) {
TerminateProcess(handle->hShell, 1);
}
}

return env.Undefined();
Expand Down
11 changes: 9 additions & 2 deletions src/windowsConoutConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ export class ConoutConnection implements IDisposable {
public get onReady(): IEvent<void> { return this._onReady.event; }

constructor(
private _conoutPipeName: string
private _conoutPipeName: string,
private _useConptyDll: boolean
) {
const workerData: IWorkerData = { conoutPipeName: _conoutPipeName };
const workerData: IWorkerData = {
conoutPipeName: _conoutPipeName
};
const scriptPath = __dirname.replace('node_modules.asar', 'node_modules.asar.unpacked');
this._worker = new Worker(join(scriptPath, 'worker/conoutSocketWorker.js'), { workerData });
this._worker.on('message', (message: ConoutWorkerMessage) => {
Expand All @@ -54,6 +57,10 @@ export class ConoutConnection implements IDisposable {
}

dispose(): void {
if (!this._useConptyDll && this._isDisposed) {
return;
}
this._isDisposed = true;
// Drain all data from the socket before closing
this._drainDataAndClose();
}
Expand Down
2 changes: 1 addition & 1 deletion src/windowsPtyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class WindowsPtyAgent {
this._outSocket = new Socket();
this._outSocket.setEncoding('utf8');
// The conout socket must be ready out on another thread to avoid deadlocks
this._conoutSocketWorker = new ConoutConnection(term.conout);
this._conoutSocketWorker = new ConoutConnection(term.conout, this._useConptyDll);
this._conoutSocketWorker.onReady(() => {
this._conoutSocketWorker.connectSocket(this._outSocket);
});
Expand Down
27 changes: 12 additions & 15 deletions src/worker/conoutSocketWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@

import { parentPort, workerData } from 'worker_threads';
import { Socket, createServer } from 'net';
import * as fs from 'fs';
import { ConoutWorkerMessage, IWorkerData, getWorkerPipeName } from '../shared/conout';

const conoutPipeName = (workerData as IWorkerData).conoutPipeName;
const outSocketFD = fs.openSync(conoutPipeName, 'r');
const conoutSocket = new Socket({
fd: outSocketFD,
readable: true
});
const { conoutPipeName } = (workerData as IWorkerData);

const conoutSocket = new Socket();
conoutSocket.setEncoding('utf8');
const server = createServer(workerSocket => {
conoutSocket.pipe(workerSocket);
conoutSocket.connect(conoutPipeName, () => {
const server = createServer(workerSocket => {
conoutSocket.pipe(workerSocket);
});
server.listen(getWorkerPipeName(conoutPipeName));
if (!parentPort) {
throw new Error('worker_threads parentPort is null');
}
parentPort.postMessage(ConoutWorkerMessage.READY);
});
server.listen(getWorkerPipeName(conoutPipeName));

if (!parentPort) {
throw new Error('worker_threads parentPort is null');
}
parentPort.postMessage(ConoutWorkerMessage.READY);