357e835f5d
This commit deletes ConhostConnection and replaces it with ConptyConnection. The ConptyConnection uses CreatePseudoConsole and depends on winconpty to override the one from kernel32. * winconpty must be packageable, so I've added GetPackagingOutputs. * To validate this, I added conpty.dll to the MSIX regression script. * I moved the code from conpty-universal that deals with environment strings into the types library. This puts us in a way better place to implement #2563, as we can now separately detect a failure to launch a pseudoconsole, a failure to CreateProcess, and an unexpected termination of the launched process. Fixes #1131.
67 lines
2.5 KiB
C++
67 lines
2.5 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#pragma once
|
|
|
|
#include "ConptyConnection.g.h"
|
|
|
|
namespace wil
|
|
{
|
|
// These belong in WIL upstream, so when we reingest the change that has them we'll get rid of ours.
|
|
using unique_pseudoconsole_handle = wil::unique_any<HPCON, decltype(&::ClosePseudoConsole), ::ClosePseudoConsole>;
|
|
}
|
|
|
|
namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
|
|
{
|
|
struct ConptyConnection : ConptyConnectionT<ConptyConnection>
|
|
{
|
|
ConptyConnection(const hstring& cmdline, const hstring& startingDirectory, const hstring& startingTitle, const uint32_t rows, const uint32_t cols, const guid& guid);
|
|
|
|
winrt::event_token TerminalOutput(TerminalConnection::TerminalOutputEventArgs const& handler);
|
|
void TerminalOutput(winrt::event_token const& token) noexcept;
|
|
winrt::event_token TerminalDisconnected(TerminalConnection::TerminalDisconnectedEventArgs const& handler);
|
|
void TerminalDisconnected(winrt::event_token const& token) noexcept;
|
|
void Start();
|
|
void WriteInput(hstring const& data);
|
|
void Resize(uint32_t rows, uint32_t columns);
|
|
void Close();
|
|
|
|
winrt::guid Guid() const noexcept;
|
|
|
|
private:
|
|
HRESULT _LaunchAttachedClient() noexcept;
|
|
void _ClientTerminated() noexcept;
|
|
|
|
winrt::event<TerminalConnection::TerminalOutputEventArgs> _outputHandlers;
|
|
winrt::event<TerminalConnection::TerminalDisconnectedEventArgs> _disconnectHandlers;
|
|
|
|
uint32_t _initialRows{};
|
|
uint32_t _initialCols{};
|
|
hstring _commandline;
|
|
hstring _startingDirectory;
|
|
hstring _startingTitle;
|
|
guid _guid{}; // A unique session identifier for connected client
|
|
|
|
bool _connected{};
|
|
std::atomic<bool> _closing{ false };
|
|
bool _recievedFirstByte{ false };
|
|
std::chrono::high_resolution_clock::time_point _startTime{};
|
|
|
|
wil::unique_hfile _inPipe; // The pipe for writing input to
|
|
wil::unique_hfile _outPipe; // The pipe for reading output from
|
|
wil::unique_handle _hOutputThread;
|
|
wil::unique_process_information _piClient;
|
|
wil::unique_pseudoconsole_handle _hPC;
|
|
wil::unique_threadpool_wait _clientExitWait;
|
|
|
|
DWORD _OutputThread();
|
|
};
|
|
}
|
|
|
|
namespace winrt::Microsoft::Terminal::TerminalConnection::factory_implementation
|
|
{
|
|
struct ConptyConnection : ConptyConnectionT<ConptyConnection, implementation::ConptyConnection>
|
|
{
|
|
};
|
|
}
|