LLDB  mainline
ConnectionFileDescriptorPosix.h
Go to the documentation of this file.
1 //===-- ConnectionFileDescriptorPosix.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 
9 #ifndef LLDB_HOST_POSIX_CONNECTIONFILEDESCRIPTORPOSIX_H
10 #define LLDB_HOST_POSIX_CONNECTIONFILEDESCRIPTORPOSIX_H
11 
12 #include <atomic>
13 #include <memory>
14 #include <mutex>
15 
16 #include "lldb/lldb-forward.h"
17 
18 #include "lldb/Host/Pipe.h"
20 #include "lldb/Utility/IOObject.h"
21 #include "lldb/Utility/Predicate.h"
22 
23 namespace lldb_private {
24 
25 class Status;
26 class Socket;
27 class SocketAddress;
28 
30 public:
31  ConnectionFileDescriptor(bool child_processes_inherit = false);
32 
33  ConnectionFileDescriptor(int fd, bool owns_fd);
34 
36 
37  ~ConnectionFileDescriptor() override;
38 
39  bool IsConnected() const override;
40 
41  lldb::ConnectionStatus Connect(llvm::StringRef s, Status *error_ptr) override;
42 
43  lldb::ConnectionStatus Disconnect(Status *error_ptr) override;
44 
45  size_t Read(void *dst, size_t dst_len, const Timeout<std::micro> &timeout,
46  lldb::ConnectionStatus &status, Status *error_ptr) override;
47 
48  size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status,
49  Status *error_ptr) override;
50 
51  std::string GetURI() override;
52 
54  Status *error_ptr);
55 
56  bool InterruptRead() override;
57 
58  lldb::IOObjectSP GetReadObject() override { return m_io_sp; }
59 
61 
62  bool GetChildProcessesInherit() const;
63  void SetChildProcessesInherit(bool child_processes_inherit);
64 
65 protected:
66  void OpenCommandPipe();
67 
68  void CloseCommandPipe();
69 
70  lldb::ConnectionStatus SocketListenAndAccept(llvm::StringRef host_and_port,
71  Status *error_ptr);
72 
73  lldb::ConnectionStatus ConnectTCP(llvm::StringRef host_and_port,
74  Status *error_ptr);
75 
76  lldb::ConnectionStatus ConnectUDP(llvm::StringRef args, Status *error_ptr);
77 
78  lldb::ConnectionStatus NamedSocketConnect(llvm::StringRef socket_name,
79  Status *error_ptr);
80 
81  lldb::ConnectionStatus NamedSocketAccept(llvm::StringRef socket_name,
82  Status *error_ptr);
83 
84  lldb::ConnectionStatus UnixAbstractSocketConnect(llvm::StringRef socket_name,
85  Status *error_ptr);
86 
87  lldb::ConnectionStatus ConnectFD(llvm::StringRef args, Status *error_ptr);
88 
89  lldb::ConnectionStatus ConnectFile(llvm::StringRef args, Status *error_ptr);
90 
91  lldb::ConnectionStatus ConnectSerialPort(llvm::StringRef args,
92  Status *error_ptr);
93 
94  lldb::IOObjectSP m_io_sp;
95 
97  m_port_predicate; // Used when binding to port zero to wait for the thread
98  // that creates the socket, binds and listens to
99  // resolve the port number.
100 
102  std::recursive_mutex m_mutex;
103  std::atomic<bool> m_shutting_down; // This marks that we are shutting down so
104  // if we get woken up from
105  // BytesAvailable to disconnect, we won't try to read again.
106  bool m_waiting_for_accept = false;
108 
110 
111 private:
112  void InitializeSocket(Socket *socket);
113 
116  operator=(const ConnectionFileDescriptor &) = delete;
117 };
118 
119 } // namespace lldb_private
120 
121 #endif // LLDB_HOST_POSIX_CONNECTIONFILEDESCRIPTORPOSIX_H
lldb_private::ConnectionFileDescriptor::GetURI
std::string GetURI() override
Returns a URI that describes this connection object.
Definition: ConnectionFileDescriptorPosix.cpp:413
lldb_private::Connection
Definition: Connection.h:41
lldb_private::Pipe
PipePosix Pipe
Definition: Pipe.h:20
lldb_private::ConnectionFileDescriptor::InitializeSocket
void InitializeSocket(Socket *socket)
Definition: ConnectionFileDescriptorPosix.cpp:803
lldb_private::Predicate< uint16_t >
lldb_private::ConnectionFileDescriptor::SetChildProcessesInherit
void SetChildProcessesInherit(bool child_processes_inherit)
Definition: ConnectionFileDescriptorPosix.cpp:798
lldb_private::ConnectionFileDescriptor::GetReadObject
lldb::IOObjectSP GetReadObject() override
Returns the underlying IOObject used by the Connection.
Definition: ConnectionFileDescriptorPosix.h:58
lldb_private::Socket
Definition: Socket.h:42
lldb_private::ConnectionFileDescriptor::operator=
const ConnectionFileDescriptor & operator=(const ConnectionFileDescriptor &)=delete
lldb_private::ConnectionFileDescriptor::BytesAvailable
lldb::ConnectionStatus BytesAvailable(const Timeout< std::micro > &timeout, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:431
lldb_private::ConnectionFileDescriptor::m_shutting_down
std::atomic< bool > m_shutting_down
Definition: ConnectionFileDescriptorPosix.h:103
lldb_private::ConnectionFileDescriptor::m_waiting_for_accept
bool m_waiting_for_accept
Definition: ConnectionFileDescriptorPosix.h:106
lldb_private::ConnectionFileDescriptor::OpenCommandPipe
void OpenCommandPipe()
Definition: ConnectionFileDescriptorPosix.cpp:93
Predicate.h
lldb_private::ConnectionFileDescriptor::NamedSocketConnect
lldb::ConnectionStatus NamedSocketConnect(llvm::StringRef socket_name, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:541
lldb_private::ConnectionFileDescriptor::m_pipe
Pipe m_pipe
Definition: ConnectionFileDescriptorPosix.h:101
lldb_private::ConnectionFileDescriptor::GetListeningPort
uint16_t GetListeningPort(const Timeout< std::micro > &timeout)
Definition: ConnectionFileDescriptorPosix.cpp:789
lldb_private::ConnectionFileDescriptor::m_uri
std::string m_uri
Definition: ConnectionFileDescriptorPosix.h:109
lldb_private::ConnectionFileDescriptor::m_mutex
std::recursive_mutex m_mutex
Definition: ConnectionFileDescriptorPosix.h:102
lldb::ConnectionStatus
ConnectionStatus
Connection Status Types.
Definition: lldb-enumerations.h:295
Pipe.h
lldb_private::ConnectionFileDescriptor::NamedSocketAccept
lldb::ConnectionStatus NamedSocketAccept(llvm::StringRef socket_name, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:526
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::ConnectionFileDescriptor::GetChildProcessesInherit
bool GetChildProcessesInherit() const
Definition: ConnectionFileDescriptorPosix.cpp:794
lldb_private::ConnectionFileDescriptor::m_io_sp
lldb::IOObjectSP m_io_sp
Definition: ConnectionFileDescriptorPosix.h:94
lldb_private::ConnectionFileDescriptor::UnixAbstractSocketConnect
lldb::ConnectionStatus UnixAbstractSocketConnect(llvm::StringRef socket_name, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:556
Connection.h
lldb_private::ConnectionFileDescriptor::Disconnect
lldb::ConnectionStatus Disconnect(Status *error_ptr) override
Disconnect the communications connection if one is currently connected.
Definition: ConnectionFileDescriptorPosix.cpp:179
lldb_private::ConnectionFileDescriptor::ConnectUDP
lldb::ConnectionStatus ConnectUDP(llvm::StringRef args, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:621
lldb_private::ConnectionFileDescriptor::IsConnected
bool IsConnected() const override
Check if the connection is valid.
Definition: ConnectionFileDescriptorPosix.cpp:121
lldb_private::ConnectionFileDescriptor::ConnectFD
lldb::ConnectionStatus ConnectFD(llvm::StringRef args, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:640
lldb_private::Status
Definition: Status.h:44
lldb_private::Timeout< std::micro >
lldb_private::ConnectionFileDescriptor::ConnectSerialPort
lldb::ConnectionStatus ConnectSerialPort(llvm::StringRef args, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:740
uint16_t
lldb_private::ConnectionFileDescriptor::m_child_processes_inherit
bool m_child_processes_inherit
Definition: ConnectionFileDescriptorPosix.h:107
lldb-forward.h
lldb_private::ConnectionFileDescriptor::ConnectFile
lldb::ConnectionStatus ConnectFile(llvm::StringRef args, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:694
lldb_private::ConnectionFileDescriptor::InterruptRead
bool InterruptRead() override
Interrupts an ongoing Read() operation.
Definition: ConnectionFileDescriptorPosix.cpp:173
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ConnectionFileDescriptor::Connect
lldb::ConnectionStatus Connect(llvm::StringRef s, Status *error_ptr) override
Connect using the connect string url.
Definition: ConnectionFileDescriptorPosix.cpp:125
lldb_private::ConnectionFileDescriptor::ConnectionFileDescriptor
ConnectionFileDescriptor(bool child_processes_inherit=false)
Definition: ConnectionFileDescriptorPosix.cpp:53
lldb_private::ConnectionFileDescriptor::Write
size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status, Status *error_ptr) override
The actual write function that attempts to write to the communications protocol.
Definition: ConnectionFileDescriptorPosix.cpp:346
lldb_private::ConnectionFileDescriptor::m_port_predicate
Predicate< uint16_t > m_port_predicate
Definition: ConnectionFileDescriptorPosix.h:97
lldb_private::ConnectionFileDescriptor::CloseCommandPipe
void CloseCommandPipe()
Definition: ConnectionFileDescriptorPosix.cpp:113
lldb_private::ConnectionFileDescriptor::ConnectTCP
lldb::ConnectionStatus ConnectTCP(llvm::StringRef host_and_port, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:601
IOObject.h
lldb_private::LineStatus::Status
@ Status
lldb_private::ConnectionFileDescriptor
Definition: ConnectionFileDescriptorPosix.h:29
lldb_private::ConnectionFileDescriptor::~ConnectionFileDescriptor
~ConnectionFileDescriptor() override
Definition: ConnectionFileDescriptorPosix.cpp:84
lldb_private::ConnectionFileDescriptor::SocketListenAndAccept
lldb::ConnectionStatus SocketListenAndAccept(llvm::StringRef host_and_port, Status *error_ptr)
Definition: ConnectionFileDescriptorPosix.cpp:571
lldb_private::ConnectionFileDescriptor::Read
size_t Read(void *dst, size_t dst_len, const Timeout< std::micro > &timeout, lldb::ConnectionStatus &status, Status *error_ptr) override
The read function that attempts to read from the connection.
Definition: ConnectionFileDescriptorPosix.cpp:237