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

#include <ConnectionFileDescriptorPosix.h>

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

Public Types

typedef llvm::function_ref< void(llvm::StringRef local_socket_id)> socket_id_callback_type
 

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.
 
lldb::ConnectionStatus Connect (llvm::StringRef url, Status *error_ptr) override
 Connect using the connect string url.
 
lldb::ConnectionStatus Connect (llvm::StringRef url, socket_id_callback_type socket_id_callback, Status *error_ptr)
 
lldb::ConnectionStatus Disconnect (Status *error_ptr) override
 Disconnect the communications connection if one is currently connected.
 
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.
 
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.
 
std::string GetURI () override
 Returns a URI that describes this connection object.
 
lldb::ConnectionStatus BytesAvailable (const Timeout< std::micro > &timeout, Status *error_ptr)
 
bool InterruptRead () override
 Interrupts an ongoing Read() operation.
 
lldb::IOObjectSP GetReadObject () override
 Returns the underlying IOObject used by the Connection.
 
bool GetChildProcessesInherit () const
 
void SetChildProcessesInherit (bool child_processes_inherit)
 
- Public Member Functions inherited from lldb_private::Connection
 Connection ()=default
 Default constructor.
 
virtual ~Connection ()
 Virtual destructor since this class gets subclassed and handed to a Communication object.
 
virtual lldb::ConnectionStatus Connect (llvm::StringRef url, Status *error_ptr)=0
 Connect using the connect string url.
 
virtual lldb::ConnectionStatus Disconnect (Status *error_ptr)=0
 Disconnect the communications connection if one is currently connected.
 
virtual bool IsConnected () const =0
 Check if the connection is valid.
 
virtual size_t Read (void *dst, size_t dst_len, const Timeout< std::micro > &timeout, lldb::ConnectionStatus &status, Status *error_ptr)=0
 The read function that attempts to read from the connection.
 
virtual size_t Write (const void *dst, size_t dst_len, lldb::ConnectionStatus &status, Status *error_ptr)=0
 The actual write function that attempts to write to the communications protocol.
 
virtual std::string GetURI ()=0
 Returns a URI that describes this connection object.
 
virtual bool InterruptRead ()=0
 Interrupts an ongoing Read() operation.
 
virtual lldb::IOObjectSP GetReadObject ()
 Returns the underlying IOObject used by the Connection.
 

Protected Member Functions

void OpenCommandPipe ()
 
void CloseCommandPipe ()
 
lldb::ConnectionStatus AcceptSocket (Socket::SocketProtocol socket_protocol, llvm::StringRef socket_name, llvm::function_ref< void(Socket &)> post_listen_callback, Status *error_ptr)
 
lldb::ConnectionStatus ConnectSocket (Socket::SocketProtocol socket_protocol, llvm::StringRef socket_name, Status *error_ptr)
 
lldb::ConnectionStatus AcceptTCP (llvm::StringRef host_and_port, socket_id_callback_type socket_id_callback, Status *error_ptr)
 
lldb::ConnectionStatus ConnectTCP (llvm::StringRef host_and_port, socket_id_callback_type socket_id_callback, Status *error_ptr)
 
lldb::ConnectionStatus ConnectUDP (llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
 
lldb::ConnectionStatus ConnectNamedSocket (llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
 
lldb::ConnectionStatus AcceptNamedSocket (llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
 
lldb::ConnectionStatus AcceptAbstractSocket (llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
 
lldb::ConnectionStatus ConnectAbstractSocket (llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
 
lldb::ConnectionStatus ConnectFD (llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
 
lldb::ConnectionStatus ConnectFile (llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
 
lldb::ConnectionStatus ConnectSerialPort (llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
 

Protected Attributes

lldb::IOObjectSP m_io_sp
 
Pipe m_pipe
 
std::recursive_mutex m_mutex
 
std::atomic< bool > m_shutting_down
 
bool m_child_processes_inherit
 
std::string m_uri
 

Private Member Functions

void InitializeSocket (Socket *socket)
 
 ConnectionFileDescriptor (const ConnectionFileDescriptor &)=delete
 
const ConnectionFileDescriptoroperator= (const ConnectionFileDescriptor &)=delete
 

Detailed Description

Definition at line 29 of file ConnectionFileDescriptorPosix.h.

Member Typedef Documentation

◆ socket_id_callback_type

typedef llvm::function_ref<void(llvm::StringRef local_socket_id)> lldb_private::ConnectionFileDescriptor::socket_id_callback_type

Definition at line 32 of file ConnectionFileDescriptorPosix.h.

Constructor & Destructor Documentation

◆ ConnectionFileDescriptor() [1/4]

ConnectionFileDescriptor::ConnectionFileDescriptor ( bool  child_processes_inherit = false)

◆ ConnectionFileDescriptor() [2/4]

ConnectionFileDescriptor::ConnectionFileDescriptor ( int  fd,
bool  owns_fd 
)

◆ ConnectionFileDescriptor() [3/4]

ConnectionFileDescriptor::ConnectionFileDescriptor ( Socket socket)

Definition at line 78 of file ConnectionFileDescriptorPosix.cpp.

References InitializeSocket().

◆ ~ConnectionFileDescriptor()

ConnectionFileDescriptor::~ConnectionFileDescriptor ( )
override

◆ ConnectionFileDescriptor() [4/4]

lldb_private::ConnectionFileDescriptor::ConnectionFileDescriptor ( const ConnectionFileDescriptor )
privatedelete

Member Function Documentation

◆ AcceptAbstractSocket()

ConnectionStatus ConnectionFileDescriptor::AcceptAbstractSocket ( llvm::StringRef  socket_name,
socket_id_callback_type  socket_id_callback,
Status error_ptr 
)
protected

◆ AcceptNamedSocket()

ConnectionStatus ConnectionFileDescriptor::AcceptNamedSocket ( llvm::StringRef  socket_name,
socket_id_callback_type  socket_id_callback,
Status error_ptr 
)
protected

Definition at line 585 of file ConnectionFileDescriptorPosix.cpp.

References AcceptSocket(), and lldb_private::Socket::ProtocolUnixDomain.

Referenced by Connect().

◆ AcceptSocket()

lldb::ConnectionStatus ConnectionFileDescriptor::AcceptSocket ( Socket::SocketProtocol  socket_protocol,
llvm::StringRef  socket_name,
llvm::function_ref< void(Socket &)>  post_listen_callback,
Status error_ptr 
)
protected

◆ AcceptTCP()

ConnectionStatus ConnectionFileDescriptor::AcceptTCP ( llvm::StringRef  host_and_port,
socket_id_callback_type  socket_id_callback,
Status error_ptr 
)
protected

◆ BytesAvailable()

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

◆ CloseCommandPipe()

void ConnectionFileDescriptor::CloseCommandPipe ( )
protected

◆ Connect() [1/2]

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

◆ Connect() [2/2]

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 124 of file ConnectionFileDescriptorPosix.cpp.

References Connect().

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

◆ ConnectAbstractSocket()

lldb::ConnectionStatus ConnectionFileDescriptor::ConnectAbstractSocket ( llvm::StringRef  socket_name,
socket_id_callback_type  socket_id_callback,
Status error_ptr 
)
protected

◆ ConnectFD()

ConnectionStatus ConnectionFileDescriptor::ConnectFD ( llvm::StringRef  args,
socket_id_callback_type  socket_id_callback,
Status error_ptr 
)
protected

◆ ConnectFile()

ConnectionStatus ConnectionFileDescriptor::ConnectFile ( llvm::StringRef  args,
socket_id_callback_type  socket_id_callback,
Status error_ptr 
)
protected

◆ ConnectNamedSocket()

ConnectionStatus ConnectionFileDescriptor::ConnectNamedSocket ( llvm::StringRef  socket_name,
socket_id_callback_type  socket_id_callback,
Status error_ptr 
)
protected

◆ ConnectSerialPort()

ConnectionStatus ConnectionFileDescriptor::ConnectSerialPort ( llvm::StringRef  args,
socket_id_callback_type  socket_id_callback,
Status error_ptr 
)
protected

◆ ConnectSocket()

lldb::ConnectionStatus ConnectionFileDescriptor::ConnectSocket ( Socket::SocketProtocol  socket_protocol,
llvm::StringRef  socket_name,
Status error_ptr 
)
protected

◆ ConnectTCP()

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

Definition at line 638 of file ConnectionFileDescriptorPosix.cpp.

References ConnectSocket(), and lldb_private::Socket::ProtocolTcp.

Referenced by Connect().

◆ ConnectUDP()

ConnectionStatus ConnectionFileDescriptor::ConnectUDP ( llvm::StringRef  args,
socket_id_callback_type  socket_id_callback,
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 191 of file ConnectionFileDescriptorPosix.cpp.

References lldb_private::Status::AsCString(), lldb_private::PipePosix::CanWrite(), lldb_private::PipePosix::Close(), lldb_private::Connection, lldb::eConnectionStatusError, lldb::eConnectionStatusSuccess, error(), lldb_private::GetLog(), lldb_private::PipePosix::GetWriteFileDescriptor(), IsConnected(), LLDB_LOGF, m_io_sp, m_mutex, m_pipe, m_shutting_down, m_uri, and lldb_private::PipeBase::Write().

Referenced by ~ConnectionFileDescriptor().

◆ GetChildProcessesInherit()

bool ConnectionFileDescriptor::GetChildProcessesInherit ( ) const

Definition at line 800 of file ConnectionFileDescriptorPosix.cpp.

References m_child_processes_inherit.

◆ 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 66 of file ConnectionFileDescriptorPosix.h.

References m_io_sp.

◆ 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 422 of file ConnectionFileDescriptorPosix.cpp.

References m_uri.

◆ InitializeSocket()

void ConnectionFileDescriptor::InitializeSocket ( Socket socket)
private

◆ 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 185 of file ConnectionFileDescriptorPosix.cpp.

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

Referenced by lldb_private::Editline::Cancel(), and lldb_private::Editline::Interrupt().

◆ 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 120 of file ConnectionFileDescriptorPosix.cpp.

References m_io_sp.

Referenced by Disconnect(), and Write().

◆ OpenCommandPipe()

void ConnectionFileDescriptor::OpenCommandPipe ( )
protected

◆ operator=()

const ConnectionFileDescriptor & lldb_private::ConnectionFileDescriptor::operator= ( const ConnectionFileDescriptor )
privatedelete

◆ 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 246 of file ConnectionFileDescriptorPosix.cpp.

References BytesAvailable(), lldb_private::Connection, lldb::eConnectionStatusEndOfFile, lldb::eConnectionStatusError, lldb::eConnectionStatusLostConnection, lldb::eConnectionStatusSuccess, lldb::eConnectionStatusTimedOut, lldb_private::IOObject::eFDTypeSocket, error(), lldb_private::GetLog(), LLDB_LOG, LLDB_LOGF, m_io_sp, m_mutex, m_shutting_down, and lldb_private::Status::SetErrorString().

Referenced by lldb_private::Editline::CompleteCharacter(), and lldb_private::Editline::GetCharacter().

◆ SetChildProcessesInherit()

void ConnectionFileDescriptor::SetChildProcessesInherit ( bool  child_processes_inherit)

Definition at line 804 of file ConnectionFileDescriptorPosix.cpp.

References m_child_processes_inherit.

◆ 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 destination 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 355 of file ConnectionFileDescriptorPosix.cpp.

References lldb_private::Connection, lldb::eConnectionStatusError, lldb::eConnectionStatusLostConnection, lldb::eConnectionStatusNoConnection, lldb::eConnectionStatusSuccess, error(), lldb_private::GetLog(), IsConnected(), LLDB_LOGF, m_io_sp, m_shutting_down, and lldb_private::Status::SetErrorString().

Member Data Documentation

◆ m_child_processes_inherit

bool lldb_private::ConnectionFileDescriptor::m_child_processes_inherit
protected

◆ m_io_sp

lldb::IOObjectSP lldb_private::ConnectionFileDescriptor::m_io_sp
protected

◆ m_mutex

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

Definition at line 134 of file ConnectionFileDescriptorPosix.h.

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

◆ m_pipe

Pipe lldb_private::ConnectionFileDescriptor::m_pipe
protected

◆ m_shutting_down

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

Definition at line 135 of file ConnectionFileDescriptorPosix.h.

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

◆ m_uri

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

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