]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-server/Acceptor.h
MFV r302218: file 5.28.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-server / Acceptor.h
1 //===-- Acceptor.h ----------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 #ifndef lldb_server_Acceptor_h_
10 #define lldb_server_Acceptor_h_
11
12 #include "lldb/Core/Connection.h"
13 #include "lldb/Core/Error.h"
14 #include "lldb/Host/Socket.h"
15
16 #include <functional>
17 #include <memory>
18 #include <string>
19
20 namespace llvm
21 {
22     class StringRef;
23 }
24
25 namespace lldb_private {
26 namespace lldb_server {
27
28 class Acceptor
29 {
30 public:
31     virtual ~Acceptor() = default;
32
33     Error
34     Listen(int backlog);
35
36     Error
37     Accept(const bool child_processes_inherit, Connection *&conn);
38
39     static std::unique_ptr<Acceptor>
40     Create(llvm::StringRef name, const bool child_processes_inherit, Error &error);
41
42     Socket::SocketProtocol
43     GetSocketProtocol() const;
44
45     const char*
46     GetSocketScheme() const;
47
48     // Returns either TCP port number as string or domain socket path.
49     // Empty string is returned in case of error.
50     std::string
51     GetLocalSocketId() const;
52
53 private:
54     typedef std::function<std::string()> LocalSocketIdFunc;
55
56     Acceptor(std::unique_ptr<Socket> &&listener_socket,
57              llvm::StringRef name,
58              const LocalSocketIdFunc &local_socket_id);
59
60     const std::unique_ptr<Socket> m_listener_socket_up;
61     const std::string m_name;
62     const LocalSocketIdFunc m_local_socket_id;
63 };
64
65 } // namespace lldb_server
66 } // namespace lldb_private
67
68 #endif  // lldb_server_Acceptor_h_