1 // 2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #pragma once 7 8 #include "BasePipeServer.hpp" 9 #include <string> 10 11 namespace arm 12 { 13 14 namespace pipe 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 ~ConnectionHandler()25 ~ConnectionHandler() 26 { 27 // We have set SOCK_CLOEXEC on this socket but we'll close it to be good citizens. 28 arm::pipe::Close(m_ListeningSocket); 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 44 arm::pipe::Socket m_ListeningSocket; 45 }; 46 47 } // namespace pipe 48 } // namespace arm 49