blob: 4859fced0d753514e47a2b4b9d5681bc2a36d764 [file] [log] [blame]
Finn Williams2ed809c2020-04-20 21:21:07 +01001//
Jim Flynnbbfe6032020-07-20 16:57:44 +01002// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
Finn Williams2ed809c2020-04-20 21:21:07 +01003// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
Finn Williams2ed809c2020-04-20 21:21:07 +01008#include "BasePipeServer.hpp"
9#include <string>
10
Jim Flynnbbfe6032020-07-20 16:57:44 +010011namespace arm
12{
13
14namespace pipe
Finn Williams2ed809c2020-04-20 21:21:07 +010015{
16
17class ConnectionHandler
18{
19public:
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 Flynnbbfe6032020-07-20 16:57:44 +010028 arm::pipe::Close(m_ListeningSocket);
Finn Williams2ed809c2020-04-20 21:21:07 +010029 }
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
42private:
43
Jim Flynnbbfe6032020-07-20 16:57:44 +010044 arm::pipe::Socket m_ListeningSocket;
Finn Williams2ed809c2020-04-20 21:21:07 +010045};
46
Jim Flynnbbfe6032020-07-20 16:57:44 +010047} // namespace pipe
48} // namespace arm