From bbfe603e5ae42317a2b67d713d00882bea341c88 Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Mon, 20 Jul 2020 16:57:44 +0100 Subject: IVGCVSW-5166 Pull out the common and server side code into standalone libraries Change-Id: I180f84c493a9b2be4b93b25d312ebdd9e71b1735 Signed-off-by: Jim Flynn --- .../include/basePipeServer/ConnectionHandler.hpp | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 profiling/server/include/basePipeServer/ConnectionHandler.hpp (limited to 'profiling/server/include/basePipeServer/ConnectionHandler.hpp') diff --git a/profiling/server/include/basePipeServer/ConnectionHandler.hpp b/profiling/server/include/basePipeServer/ConnectionHandler.hpp new file mode 100644 index 0000000000..4859fced0d --- /dev/null +++ b/profiling/server/include/basePipeServer/ConnectionHandler.hpp @@ -0,0 +1,48 @@ +// +// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include "BasePipeServer.hpp" +#include + +namespace arm +{ + +namespace pipe +{ + +class ConnectionHandler +{ +public: + /// Constructor establishes the Unix domain socket and sets it to listen for connections. + /// @param udsNamespace the namespace (socket address) associated with the listener. + /// @throws SocketConnectionException if the socket has been incorrectly setup. + ConnectionHandler(const std::string& udsNamespace, const bool setNonBlocking); + + ~ConnectionHandler() + { + // We have set SOCK_CLOEXEC on this socket but we'll close it to be good citizens. + arm::pipe::Close(m_ListeningSocket); + } + + ConnectionHandler(const ConnectionHandler&) = delete; + ConnectionHandler& operator=(const ConnectionHandler&) = delete; + + ConnectionHandler(ConnectionHandler&&) = delete; + ConnectionHandler& operator=(ConnectionHandler&&) = delete; + + /// Attempt to open a new socket to the client and use it to construct a new basePipeServer + /// @param echoPackets if true the raw packets will be printed to stdout. + /// @return if successful a unique_ptr to a basePipeServer otherwise a nullptr + std::unique_ptr GetNewBasePipeServer(const bool echoPackets); + +private: + + arm::pipe::Socket m_ListeningSocket; +}; + +} // namespace pipe +} // namespace arm -- cgit v1.2.1