master
cpp 60 lines 1.55 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 WSLCProcessIO.cpp
8
9 Abstract:
10
11 Contains the different WSLCProcessIO implementations for process IO handling.
12
13 --*/
14
15 #include "precomp.h"
16
17 #include "WSLCProcessIO.h"
18
19 using wsl::windows::service::wslc::RelayedProcessIO;
20 using wsl::windows::service::wslc::TTYProcessIO;
21 using wsl::windows::service::wslc::TypedHandle;
22 using wsl::windows::service::wslc::VMProcessIO;
23 using namespace wsl::windows::common::io;
24
25 RelayedProcessIO::RelayedProcessIO(std::map<ULONG, TypedHandle>&& fds) : m_relayedHandles(std::move(fds))
26 {
27 }
28
29 TypedHandle RelayedProcessIO::OpenFd(ULONG Fd)
30 {
31 auto it = m_relayedHandles.find(Fd);
32
33 THROW_HR_IF_MSG(E_INVALIDARG, it == m_relayedHandles.end(), "Fd not found in relayed handles: %i", static_cast<int>(Fd));
34 THROW_WIN32_IF_MSG(ERROR_INVALID_STATE, !it->second.is_valid(), "Fd already consumed: %i", static_cast<int>(Fd));
35
36 return std::move(it->second);
37 }
38
39 TTYProcessIO::TTYProcessIO(TypedHandle&& IoStream) : m_ioStream(std::move(IoStream))
40 {
41 }
42
43 TypedHandle TTYProcessIO::OpenFd(ULONG Fd)
44 {
45 THROW_HR_IF_MSG(E_INVALIDARG, Fd != WSLCFDTty, "Invalid fd type for TTY process: %i", static_cast<int>(Fd));
46
47 return std::move(m_ioStream);
48 }
49
50 VMProcessIO::VMProcessIO(std::map<ULONG, TypedHandle>&& handles) : m_handles(std::move(handles))
51 {
52 }
53
54 TypedHandle VMProcessIO::OpenFd(ULONG Fd)
55 {
56 auto it = m_handles.find(Fd);
57 THROW_HR_IF_MSG(E_INVALIDARG, it == m_handles.end(), "Invalid fd type for VM process: %i", static_cast<int>(Fd));
58
59 return std::move(it->second);
60 }