LLDB mainline
lldb_private::Communication Class Reference

An abstract communications class. More...

#include "lldb/Core/Communication.h"

Inheritance diagram for lldb_private::Communication:
[legend]

Public Member Functions

 Communication ()
 Construct the Communication object.
virtual ~Communication ()
 Destructor.
virtual void Clear ()
lldb::ConnectionStatus Connect (const char *url, Status *error_ptr)
 Connect using the current connection by passing url to its connect function.
virtual lldb::ConnectionStatus Disconnect (Status *error_ptr=nullptr)
 Disconnect the communications connection if one is currently connected.
bool IsConnected () const
 Check if the connection is valid.
bool HasConnection () const
lldb_private::ConnectionGetConnection ()
virtual size_t Read (void *dst, size_t dst_len, const Timeout< std::micro > &timeout, lldb::ConnectionStatus &status, Status *error_ptr)
 Read bytes from the current connection.
size_t Write (const void *src, size_t src_len, lldb::ConnectionStatus &status, Status *error_ptr)
 The actual write function that attempts to write to the communications protocol.
size_t WriteAll (const void *src, size_t src_len, lldb::ConnectionStatus &status, Status *error_ptr)
 Repeatedly attempt writing until either src_len bytes are written or a permanent failure occurs.
virtual void SetConnection (std::unique_ptr< Connection > connection)
 Sets the connection that it to be used by this class.
bool GetCloseOnEOF () const
void SetCloseOnEOF (bool b)

Static Public Member Functions

static std::string ConnectionStatusAsString (lldb::ConnectionStatus status)

Protected Member Functions

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

Protected Attributes

lldb::ConnectionSP m_connection_sp
 The connection that is current in use by this communications class.
std::mutex m_write_mutex
 Don't let multiple threads write at the same time...
bool m_close_on_eof

Private Member Functions

 Communication (const Communication &)=delete
const Communicationoperator= (const Communication &)=delete

Detailed Description

An abstract communications class.

Communication is an class that handles data communication between two data sources. It uses a Connection class to do the real communication. This approach has a couple of advantages: it allows a single instance of this class to be used even though its connection can change. Connections could negotiate for different connections based on abilities like starting with Bluetooth and negotiating up to WiFi if available.

When using this class, all reads and writes happen synchronously on the calling thread. There is also a ThreadedCommunication class that supports multi-threaded mode.

Definition at line 39 of file Communication.h.

Constructor & Destructor Documentation

◆ Communication() [1/2]

◆ ~Communication()

Communication::~Communication ( )
virtual

Destructor.

The destructor is virtual since this class gets subclassed.

Definition at line 33 of file Communication.cpp.

References Clear().

◆ Communication() [2/2]

lldb_private::Communication::Communication ( const Communication & )
privatedelete

References Communication().

Member Function Documentation

◆ Clear()

void Communication::Clear ( )
virtual

Reimplemented in lldb_private::ThreadedCommunication.

Definition at line 37 of file Communication.cpp.

References Disconnect().

Referenced by lldb_private::ThreadedCommunication::Clear(), and ~Communication().

◆ Connect()

ConnectionStatus Communication::Connect ( const char * url,
Status * error_ptr )

Connect using the current connection by passing url to its connect function.

string.

Parameters
[in]urlA string that contains all information needed by the subclass to connect to another client.
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 ();
bool Connection::Connect (const char *url);

Definition at line 41 of file Communication.cpp.

◆ ConnectionStatusAsString()

◆ Disconnect()

ConnectionStatus Communication::Disconnect ( Status * error_ptr = nullptr)
virtual

◆ GetCloseOnEOF()

bool lldb_private::Communication::GetCloseOnEOF ( ) const
inline

◆ GetConnection()

lldb_private::Connection * lldb_private::Communication::GetConnection ( )
inline

Definition at line 87 of file Communication.h.

References m_connection_sp.

◆ HasConnection()

bool Communication::HasConnection ( ) const

Definition at line 82 of file Communication.cpp.

References m_connection_sp.

◆ IsConnected()

◆ operator=()

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

References Communication().

◆ Read()

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

Read bytes from the current connection.

If no read thread is running, this function call the connection's Connection::Read(...) function to get any available.

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]timeoutA timeout value or std::nullopt for no timeout.
Returns
The number of bytes actually read.
See also
size_t Connection::Read (void *, size_t);

Reimplemented in lldb_private::ThreadedCommunication.

Definition at line 86 of file Communication.cpp.

References lldb_private::Communication, lldb_private::GetLog(), LLDB_LOG, m_connection_sp, and ReadFromConnection().

Referenced by lldb_private::ThreadedCommunication::Read(), lldb_private::process_gdb_remote::GDBRemoteCommunication::WaitForPacketNoLock(), and CommunicationKDP::WaitForPacketWithTimeoutMicroSecondsNoLock().

◆ ReadFromConnection()

size_t Communication::ReadFromConnection ( void * dst,
size_t dst_len,
const Timeout< std::micro > & timeout,
lldb::ConnectionStatus & status,
Status * error_ptr )
protected

◆ SetCloseOnEOF()

void lldb_private::Communication::SetCloseOnEOF ( bool b)
inline

Definition at line 165 of file Communication.h.

References m_close_on_eof.

◆ SetConnection()

void Communication::SetConnection ( std::unique_ptr< Connection > connection)
virtual

Sets the connection that it to be used by this class.

By making a communication class that uses different connections it allows a single communication interface to negotiate and change its connection without any interruption to the client. It also allows the Communication class to be subclassed for packet based communication.

Parameters
[in]connectionA connection that this class will own and destroy.
See also
class Connection

Reimplemented in lldb_private::ThreadedCommunication.

Definition at line 141 of file Communication.cpp.

References Disconnect(), and m_connection_sp.

Referenced by lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::InitializeConnection(), and lldb_private::ThreadedCommunication::SetConnection().

◆ Write()

size_t Communication::Write ( const void * src,
size_t src_len,
lldb::ConnectionStatus & status,
Status * error_ptr )

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

Subclasses must override this function.

Parameters
[in]srcA source buffer that must be at least src_len bytes long.
[in]src_lenThe number of bytes to attempt to write, and also the number of bytes are currently available in src.
Returns
The number of bytes actually Written.

Definition at line 98 of file Communication.cpp.

References lldb_private::Communication, lldb::eConnectionStatusNoConnection, lldb_private::Status::FromErrorString(), lldb_private::GetLog(), LLDB_LOG, m_connection_sp, and m_write_mutex.

Referenced by CommunicationKDP::SendRequestPacketNoLock(), and WriteAll().

◆ WriteAll()

size_t Communication::WriteAll ( const void * src,
size_t src_len,
lldb::ConnectionStatus & status,
Status * error_ptr )

Repeatedly attempt writing until either src_len bytes are written or a permanent failure occurs.

Parameters
[in]srcA source buffer that must be at least src_len bytes long.
[in]src_lenThe number of bytes to attempt to write, and also the number of bytes are currently available in src.
Returns
The number of bytes actually Written.

Definition at line 117 of file Communication.cpp.

References lldb::eConnectionStatusSuccess, and Write().

Referenced by lldb_private::process_gdb_remote::GDBRemoteCommunication::SendAck(), lldb_private::process_gdb_remote::GDBRemoteCommunication::SendNack(), and lldb_private::process_gdb_remote::GDBRemoteCommunication::SendRawPacketNoLock().

Member Data Documentation

◆ m_close_on_eof

bool lldb_private::Communication::m_close_on_eof
protected

Definition at line 172 of file Communication.h.

Referenced by Communication(), GetCloseOnEOF(), and SetCloseOnEOF().

◆ m_connection_sp

◆ m_write_mutex

std::mutex lldb_private::Communication::m_write_mutex
protected

Don't let multiple threads write at the same time...

Definition at line 171 of file Communication.h.

Referenced by Communication(), and Write().


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