| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | IOCallback.h |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | Holds IO callback objects. |
| 12 | |
| 13 | --*/ |
| 14 | #pragma once |
| 15 | #include "WSLCCompat.h" |
| 16 | #include "relay.hpp" |
| 17 | #include <thread> |
| 18 | |
| 19 | struct WslcContainerProcessIOCallbackOptions; |
| 20 | struct WslcContainerProcessOptionsInternal; |
| 21 | |
| 22 | struct IOCallback |
| 23 | { |
| 24 | IOCallback(IWSLCCompatProcess* process, const WslcContainerProcessIOCallbackOptions& options); |
| 25 | ~IOCallback(); |
| 26 | |
| 27 | void Cancel(); |
| 28 | void Complete(); |
| 29 | |
| 30 | bool IsOnIOCallbackThread() const noexcept; |
| 31 | |
| 32 | static bool HasIOCallback(const WslcContainerProcessOptionsInternal* options); |
| 33 | static bool HasIOCallback(const WslcContainerProcessIOCallbackOptions& options); |
| 34 | |
| 35 | static wil::unique_handle GetIOHandle(IWSLCCompatProcess* process, WslcProcessIOHandle ioHandle); |
| 36 | |
| 37 | private: |
| 38 | wil::com_ptr<IWSLCCompatProcess> m_process; |
| 39 | std::unique_ptr<WslcContainerProcessIOCallbackOptions> m_callbackOptions; |
| 40 | std::thread m_thread; |
| 41 | wsl::windows::common::io::MultiHandleWait m_io; |
| 42 | wil::unique_event m_cancelEvent{wil::EventOptions::ManualReset}; |
| 43 | std::once_flag m_join; |
| 44 | }; |