Finn Williams | 2ed809c | 2020-04-20 21:21:07 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
Finn Williams | 2ed809c | 2020-04-20 21:21:07 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Finn Williams | 2ed809c | 2020-04-20 21:21:07 +0100 | [diff] [blame] | 8 | #include "BasePipeServer.hpp" |
| 9 | #include <string> |
| 10 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 11 | namespace arm |
| 12 | { |
| 13 | |
| 14 | namespace pipe |
Finn Williams | 2ed809c | 2020-04-20 21:21:07 +0100 | [diff] [blame] | 15 | { |
| 16 | |
| 17 | class ConnectionHandler |
| 18 | { |
| 19 | public: |
| 20 | /// Constructor establishes the Unix domain socket and sets it to listen for connections. |
| 21 | /// @param udsNamespace the namespace (socket address) associated with the listener. |
| 22 | /// @throws SocketConnectionException if the socket has been incorrectly setup. |
| 23 | ConnectionHandler(const std::string& udsNamespace, const bool setNonBlocking); |
| 24 | |
| 25 | ~ConnectionHandler() |
| 26 | { |
| 27 | // We have set SOCK_CLOEXEC on this socket but we'll close it to be good citizens. |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 28 | arm::pipe::Close(m_ListeningSocket); |
Finn Williams | 2ed809c | 2020-04-20 21:21:07 +0100 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | ConnectionHandler(const ConnectionHandler&) = delete; |
| 32 | ConnectionHandler& operator=(const ConnectionHandler&) = delete; |
| 33 | |
| 34 | ConnectionHandler(ConnectionHandler&&) = delete; |
| 35 | ConnectionHandler& operator=(ConnectionHandler&&) = delete; |
| 36 | |
| 37 | /// Attempt to open a new socket to the client and use it to construct a new basePipeServer |
| 38 | /// @param echoPackets if true the raw packets will be printed to stdout. |
| 39 | /// @return if successful a unique_ptr to a basePipeServer otherwise a nullptr |
| 40 | std::unique_ptr<BasePipeServer> GetNewBasePipeServer(const bool echoPackets); |
| 41 | |
| 42 | private: |
| 43 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 44 | arm::pipe::Socket m_ListeningSocket; |
Finn Williams | 2ed809c | 2020-04-20 21:21:07 +0100 | [diff] [blame] | 45 | }; |
| 46 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 47 | } // namespace pipe |
| 48 | } // namespace arm |