Minor fixes to ConhostConnection and VTPipeTerm (#1218)

* Cascadia/TerminalConnection: Close the output thread on exit.
It seems that TerminateThread() is available in the code...

* VtPipeTerm: Don't crash when closing the app.

- Gracefully handle ReadFile returning false (usually because of ERROR_BROKEN_PIPE on exit).
- Minor whitespace formatting.

* Cascadia/TerminalConnection: Finish to implement the ConhostConnection::Close() 'TODO' block.
This commit is contained in:
Hermès BÉLUSCA - MAÏTO 2019-06-13 02:10:13 +02:00 committed by Dustin L. Howett (MSFT)
parent e20dfb8633
commit d82eab44d0
2 changed files with 13 additions and 8 deletions

View File

@ -144,16 +144,17 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
return;
}
_closing = true;
// TODO:
// terminate the output thread
// Close our handles
// Close the Pseudoconsole
// terminate our processes
_connected = false;
// Terminate the output thread
_outputThreadId = 0;
TerminateThread(_hOutputThread, 0);
// Close our pipes and the pseudoconsole
CloseHandle(_signalPipe);
CloseHandle(_inPipe);
CloseHandle(_outPipe);
// What? CreateThread is in app partition but TerminateThread isn't?
//TerminateThread(_hOutputThread, 0);
TerminateProcess(_piConhost.hProcess, 0);
CloseHandle(_piConhost.hProcess);
}

View File

@ -345,8 +345,12 @@ DWORD VtConsole::_OutputThread()
bool fSuccess = false;
fSuccess = !!ReadFile(this->outPipe(), buffer, ARRAYSIZE(buffer), &dwRead, nullptr);
if (!fSuccess)
{
HRESULT hr = GetLastError();
exit(hr);
}
THROW_LAST_ERROR_IF(!fSuccess);
if (this->_active)
{
_pfnReadCallback(buffer, dwRead);