LLDB  mainline
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
lldb_private::ConnectionFileDescriptor Class Reference

#include <ConnectionFileDescriptorPosix.h>

Inheritance diagram for lldb_private::ConnectionFileDescriptor:
Inheritance graph
[legend]
Collaboration diagram for lldb_private::ConnectionFileDescriptor:
Collaboration graph
[legend]

Public Member Functions

 ConnectionFileDescriptor (bool child_processes_inherit=false)
 
 ConnectionFileDescriptor (int fd, bool owns_fd)
 
 ConnectionFileDescriptor (Socket *socket)
 
 ~ConnectionFileDescriptor () override
 
bool IsConnected () const override
 Check if the connection is valid. More...
 
lldb::ConnectionStatus Connect (llvm::StringRef s, Status *error_ptr) override
 Connect using the connect string url. More...
 
lldb::ConnectionStatus Disconnect (Status *error_ptr) override
 Disconnect the communications connection if one is currently connected. More...
 
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. More...
 
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. More...
 
std::string GetURI () override
 Returns a URI that describes this connection object. More...
 
lldb::ConnectionStatus BytesAvailable (const Timeout< std::micro > &timeout, Status *error_ptr)
 
bool InterruptRead () override
 Interrupts an ongoing Read() operation. More...
 
lldb::IOObjectSP GetReadObject () override
 Returns the underlying IOObject used by the Connection. More...
 
uint16_t GetListeningPort (const Timeout< std::micro > &timeout)
 
bool GetChildProcessesInherit () const
 
void SetChildProcessesInherit (bool child_processes_inherit)
 
- Public Member Functions inherited from lldb_private::Connection
 Connection ()=default
 Default constructor. More...
 
virtual ~Connection ()
 Virtual destructor since this class gets subclassed and handed to a Communication object. More...
 

Static Public Attributes

static const char * LISTEN_SCHEME = "listen"
 
static const char * ACCEPT_SCHEME = "accept"
 
static const char * UNIX_ACCEPT_SCHEME = "unix-accept"
 
static const char * CONNECT_SCHEME = "connect"
 
static const char * TCP_CONNECT_SCHEME = "tcp-connect"
 
static const char * UDP_SCHEME = "udp"
 
static const char * UNIX_CONNECT_SCHEME = "unix-connect"
 
static const char * UNIX_ABSTRACT_CONNECT_SCHEME
 
static const char * FD_SCHEME = "fd"
 
static const char * FILE_SCHEME = "file"
 

Protected Member Functions

void OpenCommandPipe ()
 
void CloseCommandPipe ()
 
lldb::ConnectionStatus SocketListenAndAccept (llvm::StringRef host_and_port, Status *error_ptr)
 
lldb::ConnectionStatus ConnectTCP (llvm::StringRef host_and_port, Status *error_ptr)
 
lldb::ConnectionStatus ConnectUDP (llvm::StringRef args, Status *error_ptr)
 
lldb::ConnectionStatus NamedSocketConnect (llvm::StringRef socket_name, Status *error_ptr)
 
lldb::ConnectionStatus NamedSocketAccept (llvm::StringRef socket_name, Status *error_ptr)
 
lldb::ConnectionStatus UnixAbstractSocketConnect (llvm::StringRef socket_name, Status *error_ptr)
 

Protected Attributes

lldb::IOObjectSP m_read_sp
 
lldb::IOObjectSP m_write_sp
 
Predicate< uint16_tm_port_predicate
 
Pipe m_pipe
 
std::recursive_mutex m_mutex
 
std::atomic< bool > m_shutting_down
 
bool m_waiting_for_accept
 
bool m_child_processes_inherit
 
std::string m_uri
 

Detailed Description

Definition at line 29 of file ConnectionFileDescriptorPosix.h.

Constructor & Destructor Documentation

◆ ConnectionFileDescriptor() [1/3]

ConnectionFileDescriptor::ConnectionFileDescriptor ( bool  child_processes_inherit = false)

◆ ConnectionFileDescriptor() [2/3]

ConnectionFileDescriptor::ConnectionFileDescriptor ( int  fd,
bool  owns_fd 
)

◆ ConnectionFileDescriptor() [3/3]

ConnectionFileDescriptor::ConnectionFileDescriptor ( Socket socket)

Definition at line 102 of file ConnectionFileDescriptorPosix.cpp.

◆ ~ConnectionFileDescriptor()

ConnectionFileDescriptor::~ConnectionFileDescriptor ( )
override

Member Function Documentation

◆ BytesAvailable()

ConnectionStatus ConnectionFileDescriptor::BytesAvailable ( const Timeout< std::micro > &  timeout,
Status error_ptr 
)

◆ CloseCommandPipe()

void ConnectionFileDescriptor::CloseCommandPipe ( )
protected

◆ Connect()

ConnectionStatus ConnectionFileDescriptor::Connect ( llvm::StringRef  url,
Status error_ptr 
)
overridevirtual

Connect using the connect string url.

Parameters
[in]urlA string that contains all information needed by the subclass to connect to another client.
[out]error_ptrA pointer to an error object that should be given an appropriate error value if this method returns false. This value can be NULL if the error value should be ignored.
Returns
True if the connect succeeded, false otherwise. The internal error object should be filled in with an appropriate value based on the result of this function.
See also
Status& Communication::GetError ();

Implements lldb_private::Connection.

Definition at line 152 of file ConnectionFileDescriptorPosix.cpp.

References ACCEPT_SCHEME, CONNECT_SCHEME, ConnectTCP(), ConnectUDP(), lldb::eConnectionStatusError, lldb::eConnectionStatusSuccess, FD_SCHEME, FILE_SCHEME, lldb_private::GetLogIfAnyCategoriesSet(), LIBLLDB_LOG_CONNECTION, LISTEN_SCHEME, m_mutex, m_read_sp, m_uri, m_write_sp, NamedSocketAccept(), NamedSocketConnect(), O_NONBLOCK, OpenCommandPipe(), lldb_private::Log::Printf(), lldb_private::Status::SetErrorString(), lldb_private::Status::SetErrorStringWithFormat(), lldb_private::Status::SetErrorToErrno(), SocketListenAndAccept(), TCP_CONNECT_SCHEME, UDP_SCHEME, UNIX_ABSTRACT_CONNECT_SCHEME, UNIX_ACCEPT_SCHEME, UNIX_CONNECT_SCHEME, and UnixAbstractSocketConnect().

Referenced by AcceptPIDFromInferior(), and lldb_private::process_gdb_remote::GDBRemoteCommunication::ListenThread().

◆ ConnectTCP()

ConnectionStatus ConnectionFileDescriptor::ConnectTCP ( llvm::StringRef  host_and_port,
Status error_ptr 
)
protected

◆ ConnectUDP()

ConnectionStatus ConnectionFileDescriptor::ConnectUDP ( llvm::StringRef  args,
Status error_ptr 
)
protected

◆ Disconnect()

ConnectionStatus ConnectionFileDescriptor::Disconnect ( Status error_ptr)
overridevirtual

Disconnect the communications connection if one is currently connected.

Parameters
[out]error_ptrA pointer to an error object that should be given an appropriate error value if this method returns false. This value can be NULL if the error value should be ignored.
Returns
True if the disconnect succeeded, false otherwise. The internal error object should be filled in with an appropriate value based on the result of this function.
See also
Status& Communication::GetError ();

Implements lldb_private::Connection.

Definition at line 296 of file ConnectionFileDescriptorPosix.cpp.

References lldb_private::Status::AsCString(), lldb::eConnectionStatusError, lldb::eConnectionStatusSuccess, lldb_private::IOObject::eFDTypeSocket, lldb_private::Status::Fail(), lldb_private::GetLogIfAnyCategoriesSet(), IsConnected(), LIBLLDB_LOG_CONNECTION, m_mutex, m_pipe, m_read_sp, m_shutting_down, m_uri, m_write_sp, and lldb_private::Log::Printf().

Referenced by ~ConnectionFileDescriptor().

◆ GetChildProcessesInherit()

bool ConnectionFileDescriptor::GetChildProcessesInherit ( ) const

Definition at line 751 of file ConnectionFileDescriptorPosix.cpp.

References m_child_processes_inherit.

Referenced by GetReadObject().

◆ GetListeningPort()

uint16_t ConnectionFileDescriptor::GetListeningPort ( const Timeout< std::micro > &  timeout)

◆ GetReadObject()

lldb::IOObjectSP lldb_private::ConnectionFileDescriptor::GetReadObject ( )
inlineoverridevirtual

Returns the underlying IOObject used by the Connection.

The IOObject can be used to wait for data to become available on the connection. If the Connection does not use IOObjects (and hence does not support waiting) this function should return a null pointer.

Returns
The underlying IOObject used for reading.

Reimplemented from lldb_private::Connection.

Definition at line 69 of file ConnectionFileDescriptorPosix.h.

References CloseCommandPipe(), ConnectTCP(), ConnectUDP(), GetChildProcessesInherit(), GetListeningPort(), m_read_sp, NamedSocketAccept(), NamedSocketConnect(), OpenCommandPipe(), SetChildProcessesInherit(), SocketListenAndAccept(), and UnixAbstractSocketConnect().

◆ GetURI()

std::string ConnectionFileDescriptor::GetURI ( )
overridevirtual

Returns a URI that describes this connection object.

Subclasses may override this function.

Returns
Returns URI or an empty string if disconnecteds

Implements lldb_private::Connection.

Definition at line 523 of file ConnectionFileDescriptorPosix.cpp.

References m_uri.

◆ InterruptRead()

bool ConnectionFileDescriptor::InterruptRead ( )
overridevirtual

Interrupts an ongoing Read() operation.

If there is an ongoing read operation in another thread, this operation return with status == eConnectionStatusInterrupted. Note that if there data waiting to be read and an interrupt request is issued, the Read() function will return the data immediately without processing the interrupt request (which will remain queued for the next Read() operation).

Returns
Returns true is the interrupt request was successful.

Implements lldb_private::Connection.

Definition at line 290 of file ConnectionFileDescriptorPosix.cpp.

References m_pipe, and lldb_private::Status::Success().

◆ IsConnected()

bool ConnectionFileDescriptor::IsConnected ( ) const
overridevirtual

Check if the connection is valid.

Returns
True if this object is currently connected, false otherwise.

Implements lldb_private::Connection.

Definition at line 147 of file ConnectionFileDescriptorPosix.cpp.

References m_read_sp, and m_write_sp.

Referenced by Disconnect(), and Write().

◆ NamedSocketAccept()

ConnectionStatus ConnectionFileDescriptor::NamedSocketAccept ( llvm::StringRef  socket_name,
Status error_ptr 
)
protected

◆ NamedSocketConnect()

ConnectionStatus ConnectionFileDescriptor::NamedSocketConnect ( llvm::StringRef  socket_name,
Status error_ptr 
)
protected

◆ OpenCommandPipe()

void ConnectionFileDescriptor::OpenCommandPipe ( )
protected

◆ Read()

size_t ConnectionFileDescriptor::Read ( void *  dst,
size_t  dst_len,
const Timeout< std::micro > &  timeout,
lldb::ConnectionStatus status,
Status error_ptr 
)
overridevirtual

The read function that attempts to read from the connection.

Parameters
[in]dstA destination buffer that must be at least dst_len bytes long.
[in]dst_lenThe number of bytes to attempt to read, and also the max number of bytes that can be placed into dst.
[in]timeoutThe number of microseconds to wait for the data.
[out]statusOn return, indicates whether the call was successful or terminated due to some error condition.
[out]error_ptrA pointer to an error object that should be given an appropriate error value if this method returns zero. This value can be NULL if the error value should be ignored.
Returns
The number of bytes actually read.
See also
size_t Communication::Read (void *, size_t, uint32_t);

Implements lldb_private::Connection.

Definition at line 357 of file ConnectionFileDescriptorPosix.cpp.

References lldb_private::Status::AsCString(), BytesAvailable(), lldb_private::Status::Clear(), lldb::eConnectionStatusEndOfFile, lldb::eConnectionStatusError, lldb::eConnectionStatusLostConnection, lldb::eConnectionStatusSuccess, lldb::eConnectionStatusTimedOut, lldb_private::IOObject::eFDTypeSocket, lldb_private::Status::Fail(), lldb_private::Status::GetError(), lldb_private::GetLogIfAnyCategoriesSet(), LIBLLDB_LOG_CONNECTION, LLDB_LOG, m_mutex, m_read_sp, m_shutting_down, lldb_private::Log::Printf(), and lldb_private::Status::SetErrorString().

Referenced by AcceptPIDFromInferior().

◆ SetChildProcessesInherit()

void ConnectionFileDescriptor::SetChildProcessesInherit ( bool  child_processes_inherit)

◆ SocketListenAndAccept()

ConnectionStatus ConnectionFileDescriptor::SocketListenAndAccept ( llvm::StringRef  host_and_port,
Status error_ptr 
)
protected

◆ UnixAbstractSocketConnect()

lldb::ConnectionStatus ConnectionFileDescriptor::UnixAbstractSocketConnect ( llvm::StringRef  socket_name,
Status error_ptr 
)
protected

◆ Write()

size_t ConnectionFileDescriptor::Write ( const void *  dst,
size_t  dst_len,
lldb::ConnectionStatus status,
Status error_ptr 
)
overridevirtual

The actual write function that attempts to write to the communications protocol.

Subclasses must override this function.

Parameters
[in]dstA desination buffer that must be at least dst_len bytes long.
[in]dst_lenThe number of bytes to attempt to write, and also the number of bytes are currently available in dst.
[out]error_ptrA pointer to an error object that should be given an appropriate error value if this method returns zero. This value can be NULL if the error value should be ignored.
Returns
The number of bytes actually Written.

Implements lldb_private::Connection.

Definition at line 463 of file ConnectionFileDescriptorPosix.cpp.

References lldb_private::Status::AsCString(), lldb::eConnectionStatusError, lldb::eConnectionStatusLostConnection, lldb::eConnectionStatusNoConnection, lldb::eConnectionStatusSuccess, lldb_private::Status::Fail(), lldb_private::Status::GetError(), lldb_private::GetLogIfAnyCategoriesSet(), IsConnected(), LIBLLDB_LOG_CONNECTION, m_write_sp, lldb_private::Log::Printf(), and lldb_private::Status::SetErrorString().

Member Data Documentation

◆ ACCEPT_SCHEME

const char * ConnectionFileDescriptor::ACCEPT_SCHEME = "accept"
static

Definition at line 32 of file ConnectionFileDescriptorPosix.h.

Referenced by Connect().

◆ CONNECT_SCHEME

const char * ConnectionFileDescriptor::CONNECT_SCHEME = "connect"
static

Definition at line 34 of file ConnectionFileDescriptorPosix.h.

Referenced by Connect().

◆ FD_SCHEME

const char * ConnectionFileDescriptor::FD_SCHEME = "fd"
static

Definition at line 39 of file ConnectionFileDescriptorPosix.h.

Referenced by Connect().

◆ FILE_SCHEME

const char * ConnectionFileDescriptor::FILE_SCHEME = "file"
static

Definition at line 40 of file ConnectionFileDescriptorPosix.h.

Referenced by Connect().

◆ LISTEN_SCHEME

const char * ConnectionFileDescriptor::LISTEN_SCHEME = "listen"
static

Definition at line 31 of file ConnectionFileDescriptorPosix.h.

Referenced by Connect().

◆ m_child_processes_inherit

bool lldb_private::ConnectionFileDescriptor::m_child_processes_inherit
protected

◆ m_mutex

std::recursive_mutex lldb_private::ConnectionFileDescriptor::m_mutex
protected

Definition at line 107 of file ConnectionFileDescriptorPosix.h.

Referenced by Connect(), Disconnect(), and Read().

◆ m_pipe

Pipe lldb_private::ConnectionFileDescriptor::m_pipe
protected

◆ m_port_predicate

Predicate<uint16_t> lldb_private::ConnectionFileDescriptor::m_port_predicate
protected

Definition at line 102 of file ConnectionFileDescriptorPosix.h.

Referenced by GetListeningPort(), and SocketListenAndAccept().

◆ m_read_sp

lldb::IOObjectSP lldb_private::ConnectionFileDescriptor::m_read_sp
protected

◆ m_shutting_down

std::atomic<bool> lldb_private::ConnectionFileDescriptor::m_shutting_down
protected

Definition at line 108 of file ConnectionFileDescriptorPosix.h.

Referenced by Disconnect(), and Read().

◆ m_uri

std::string lldb_private::ConnectionFileDescriptor::m_uri
protected

◆ m_waiting_for_accept

bool lldb_private::ConnectionFileDescriptor::m_waiting_for_accept
protected

Definition at line 111 of file ConnectionFileDescriptorPosix.h.

Referenced by SocketListenAndAccept().

◆ m_write_sp

lldb::IOObjectSP lldb_private::ConnectionFileDescriptor::m_write_sp
protected

◆ TCP_CONNECT_SCHEME

const char * ConnectionFileDescriptor::TCP_CONNECT_SCHEME = "tcp-connect"
static

Definition at line 35 of file ConnectionFileDescriptorPosix.h.

Referenced by Connect().

◆ UDP_SCHEME

const char * ConnectionFileDescriptor::UDP_SCHEME = "udp"
static

Definition at line 36 of file ConnectionFileDescriptorPosix.h.

Referenced by Connect().

◆ UNIX_ABSTRACT_CONNECT_SCHEME

const char * ConnectionFileDescriptor::UNIX_ABSTRACT_CONNECT_SCHEME
static
Initial value:
=
"unix-abstract-connect"

Definition at line 38 of file ConnectionFileDescriptorPosix.h.

Referenced by Connect().

◆ UNIX_ACCEPT_SCHEME

const char * ConnectionFileDescriptor::UNIX_ACCEPT_SCHEME = "unix-accept"
static

Definition at line 33 of file ConnectionFileDescriptorPosix.h.

Referenced by Connect().

◆ UNIX_CONNECT_SCHEME

const char * ConnectionFileDescriptor::UNIX_CONNECT_SCHEME = "unix-connect"
static

Definition at line 37 of file ConnectionFileDescriptorPosix.h.

Referenced by Connect().


The documentation for this class was generated from the following files: