1 //===-- Acceptor.h ----------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef lldb_server_Acceptor_h_
9 #define lldb_server_Acceptor_h_
10 
11 #include "lldb/Host/Socket.h"
12 #include "lldb/Utility/Connection.h"
13 #include "lldb/Utility/Status.h"
14 
15 #include <functional>
16 #include <memory>
17 #include <string>
18 
19 namespace llvm {
20 class StringRef;
21 }
22 
23 namespace lldb_private {
24 namespace lldb_server {
25 
26 class Acceptor {
27 public:
28   virtual ~Acceptor() = default;
29 
30   Status Listen(int backlog);
31 
32   Status Accept(const bool child_processes_inherit, Connection *&conn);
33 
34   static std::unique_ptr<Acceptor> Create(llvm::StringRef name,
35                                           const bool child_processes_inherit,
36                                           Status &error);
37 
38   Socket::SocketProtocol GetSocketProtocol() const;
39 
40   const char *GetSocketScheme() const;
41 
42   // Returns either TCP port number as string or domain socket path.
43   // Empty string is returned in case of error.
44   std::string GetLocalSocketId() const;
45 
46 private:
47   typedef std::function<std::string()> LocalSocketIdFunc;
48 
49   Acceptor(std::unique_ptr<Socket> &&listener_socket, llvm::StringRef name,
50            const LocalSocketIdFunc &local_socket_id);
51 
52   const std::unique_ptr<Socket> m_listener_socket_up;
53   const std::string m_name;
54   const LocalSocketIdFunc m_local_socket_id;
55 };
56 
57 } // namespace lldb_server
58 } // namespace lldb_private
59 
60 #endif // lldb_server_Acceptor_h_
61