| 1 | // Copyright (C) Microsoft Corporation. All rights reserved. |
| 2 | |
| 3 | #pragma once |
| 4 | |
| 5 | #include <thread> |
| 6 | #include <functional> |
| 7 | #include <wil/resource.h> |
| 8 | #include <lxinitshared.h> |
| 9 | #include "SocketChannel.h" |
| 10 | |
| 11 | namespace wsl::core { |
| 12 | class GnsPortTrackerChannel |
| 13 | { |
| 14 | public: |
| 15 | GnsPortTrackerChannel( |
| 16 | wil::unique_socket&& Socket, |
| 17 | const std::function<int(const SOCKADDR_INET&, int, bool)>& Callback, |
| 18 | const std::function<void(const std::string&, bool)>& InterfaceStateCallback); |
| 19 | |
| 20 | ~GnsPortTrackerChannel(); |
| 21 | |
| 22 | GnsPortTrackerChannel(const GnsPortTrackerChannel&) = delete; |
| 23 | GnsPortTrackerChannel(GnsPortTrackerChannel&&) = delete; |
| 24 | |
| 25 | GnsPortTrackerChannel& operator=(const GnsPortTrackerChannel&) = delete; |
| 26 | GnsPortTrackerChannel& operator=(GnsPortTrackerChannel&&) = delete; |
| 27 | |
| 28 | void Run(); |
| 29 | |
| 30 | private: |
| 31 | static SOCKADDR_INET ConvertPortRequestToSockAddr(_In_ const LX_GNS_PORT_ALLOCATION_REQUEST* portAllocationRequest); |
| 32 | |
| 33 | const std::function<int(const SOCKADDR_INET&, int, bool)> m_callback; |
| 34 | const std::function<void(const std::string&, bool)> m_interfaceStateCallback; |
| 35 | wil::unique_event m_stopEvent = wil::unique_event{wil::EventOptions::ManualReset}; |
| 36 | wsl::shared::SocketChannel m_channel; |
| 37 | std::thread m_thread; |
| 38 | }; |
| 39 | } // namespace wsl::core |