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/Host/Socket.h" 13 #include "lldb/Utility/Connection.h" 14 #include "lldb/Utility/Status.h" 15 16 #include <functional> 17 #include <memory> 18 #include <string> 19 20 namespace llvm { 21 class StringRef; 22 } 23 24 namespace lldb_private { 25 namespace lldb_server { 26 27 class Acceptor { 28 public: 29 virtual ~Acceptor() = default; 30 31 Status Listen(int backlog); 32 33 Status Accept(const bool child_processes_inherit, Connection *&conn); 34 35 static std::unique_ptr<Acceptor> Create(llvm::StringRef name, 36 const bool child_processes_inherit, 37 Status &error); 38 39 Socket::SocketProtocol GetSocketProtocol() const; 40 41 const char *GetSocketScheme() const; 42 43 // Returns either TCP port number as string or domain socket path. 44 // Empty string is returned in case of error. 45 std::string GetLocalSocketId() const; 46 47 private: 48 typedef std::function<std::string()> LocalSocketIdFunc; 49 50 Acceptor(std::unique_ptr<Socket> &&listener_socket, llvm::StringRef name, 51 const LocalSocketIdFunc &local_socket_id); 52 53 const std::unique_ptr<Socket> m_listener_socket_up; 54 const std::string m_name; 55 const LocalSocketIdFunc m_local_socket_id; 56 }; 57 58 } // namespace lldb_server 59 } // namespace lldb_private 60 61 #endif // lldb_server_Acceptor_h_ 62