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