LLDB mainline
lldb_private::Socket Class Referenceabstract

#include <Socket.h>

Inheritance diagram for lldb_private::Socket:
[legend]

Classes

struct  HostAndPort

Public Types

enum  SocketProtocol { ProtocolTcp , ProtocolUdp , ProtocolUnixDomain , ProtocolUnixAbstract }
enum  SocketMode { ModeAccept , ModeConnect }
using ProtocolModePair = std::pair<SocketProtocol, SocketMode>
using Pair = std::pair<std::unique_ptr<Socket>, std::unique_ptr<Socket>>
Public Types inherited from lldb_private::IOObject
enum  FDType { eFDTypeFile , eFDTypeSocket }
using WaitableHandle = lldb::file_t

Public Member Functions

 ~Socket () override
virtual Status Connect (llvm::StringRef name)=0
virtual Status Listen (llvm::StringRef name, int backlog)=0
virtual llvm::Expected< std::vector< MainLoopBase::ReadHandleUP > > Accept (MainLoopBase &loop, std::function< void(std::unique_ptr< Socket > socket)> sock_cb)=0
virtual Status Accept (const Timeout< std::micro > &timeout, Socket *&socket)
int GetOption (int level, int option_name, int &option_value)
int SetOption (int level, int option_name, int option_value)
NativeSocket GetNativeSocket () const
SocketProtocol GetSocketProtocol () const
Status Read (void *buf, size_t &num_bytes) override
Status Write (const void *buf, size_t &num_bytes) override
Status Close () override
bool IsValid () const override
WaitableHandle GetWaitableHandle () override
virtual std::string GetRemoteConnectionURI () const
virtual std::vector< std::string > GetListeningConnectionURI () const
Public Member Functions inherited from lldb_private::IOObject
 IOObject (FDType type)
virtual ~IOObject ()
FDType GetFdType () const

Static Public Member Functions

static std::optional< ProtocolModePairGetProtocolAndMode (llvm::StringRef scheme)
static const char * FindSchemeByProtocol (const SocketProtocol protocol)
static bool FindProtocolByScheme (const char *scheme, SocketProtocol &protocol)
static llvm::Error Initialize ()
static void Terminate ()
static std::unique_ptr< SocketCreate (const SocketProtocol protocol, Status &error)
static llvm::Expected< PairCreatePair (std::optional< SocketProtocol > protocol=std::nullopt)
static llvm::Expected< std::unique_ptr< TCPSocket > > TcpListen (llvm::StringRef host_and_port, int backlog=5)
static llvm::Expected< std::unique_ptr< Socket > > TcpConnect (llvm::StringRef host_and_port)
static llvm::Expected< std::unique_ptr< UDPSocket > > UdpConnect (llvm::StringRef host_and_port)
static int GetOption (NativeSocket sockfd, int level, int option_name, int &option_value)
static int SetOption (NativeSocket sockfd, int level, int option_name, int option_value)
static llvm::Expected< HostAndPortDecodeHostAndPort (llvm::StringRef host_and_port)

Static Public Attributes

static const NativeSocket kInvalidSocketValue = -1
Static Public Attributes inherited from lldb_private::IOObject
static const WaitableHandle kInvalidHandleValue = -1

Protected Member Functions

 Socket (SocketProtocol protocol, bool should_close)
virtual size_t Send (const void *buf, const size_t num_bytes)

Static Protected Member Functions

static int CloseSocket (NativeSocket sockfd)
static Status GetLastError ()
static void SetLastError (Status &error)
static NativeSocket CreateSocket (const int domain, const int type, const int protocol, Status &error)
static NativeSocket AcceptSocket (NativeSocket sockfd, struct sockaddr *addr, socklen_t *addrlen, Status &error)

Protected Attributes

SocketProtocol m_protocol
NativeSocket m_socket
bool m_should_close_fd
Protected Attributes inherited from lldb_private::IOObject
FDType m_fd_type

Detailed Description

Definition at line 68 of file Socket.h.

Member Typedef Documentation

◆ Pair

using lldb_private::Socket::Pair = std::pair<std::unique_ptr<Socket>, std::unique_ptr<Socket>>

Definition at line 109 of file Socket.h.

◆ ProtocolModePair

Definition at line 91 of file Socket.h.

Member Enumeration Documentation

◆ SocketMode

Enumerator
ModeAccept 
ModeConnect 

Definition at line 77 of file Socket.h.

◆ SocketProtocol

Enumerator
ProtocolTcp 
ProtocolUdp 
ProtocolUnixDomain 
ProtocolUnixAbstract 

Definition at line 70 of file Socket.h.

Constructor & Destructor Documentation

◆ ~Socket()

Socket::~Socket ( )
override

Definition at line 174 of file Socket.cpp.

References Close().

◆ Socket()

Member Function Documentation

◆ Accept() [1/2]

◆ Accept() [2/2]

virtual llvm::Expected< std::vector< MainLoopBase::ReadHandleUP > > lldb_private::Socket::Accept ( MainLoopBase & loop,
std::function< void(std::unique_ptr< Socket > socket)> sock_cb )
pure virtual

◆ AcceptSocket()

NativeSocket Socket::AcceptSocket ( NativeSocket sockfd,
struct sockaddr * addr,
socklen_t * addrlen,
Status & error )
staticprotected

◆ Close()

◆ CloseSocket()

int Socket::CloseSocket ( NativeSocket sockfd)
staticprotected

◆ Connect()

virtual Status lldb_private::Socket::Connect ( llvm::StringRef name)
pure virtual

◆ Create()

◆ CreatePair()

◆ CreateSocket()

NativeSocket Socket::CreateSocket ( const int domain,
const int type,
const int protocol,
Status & error )
staticprotected

◆ DecodeHostAndPort()

◆ FindProtocolByScheme()

bool Socket::FindProtocolByScheme ( const char * scheme,
Socket::SocketProtocol & protocol )
static

Definition at line 159 of file Socket.cpp.

References socket_schemes.

◆ FindSchemeByProtocol()

const char * Socket::FindSchemeByProtocol ( const SocketProtocol protocol)
static

◆ GetLastError()

Status Socket::GetLastError ( )
staticprotected

Definition at line 422 of file Socket.cpp.

Referenced by lldb_private::TCPSocket::Listen().

◆ GetListeningConnectionURI()

virtual std::vector< std::string > lldb_private::Socket::GetListeningConnectionURI ( ) const
inlinevirtual

Reimplemented in lldb_private::DomainSocket, and lldb_private::TCPSocket.

Definition at line 169 of file Socket.h.

◆ GetNativeSocket()

◆ GetOption() [1/2]

int lldb_private::Socket::GetOption ( int level,
int option_name,
int & option_value )
inline

Definition at line 141 of file Socket.h.

References GetOption(), and m_socket.

◆ GetOption() [2/2]

int Socket::GetOption ( NativeSocket sockfd,
int level,
int option_name,
int & option_value )
static

Definition at line 393 of file Socket.cpp.

Referenced by GetOption().

◆ GetProtocolAndMode()

std::optional< Socket::ProtocolModePair > Socket::GetProtocolAndMode ( llvm::StringRef scheme)
static

◆ GetRemoteConnectionURI()

virtual std::string lldb_private::Socket::GetRemoteConnectionURI ( ) const
inlinevirtual

Reimplemented in lldb_private::DomainSocket, lldb_private::TCPSocket, and lldb_private::UDPSocket.

Definition at line 166 of file Socket.h.

◆ GetSocketProtocol()

SocketProtocol lldb_private::Socket::GetSocketProtocol ( ) const
inline

Definition at line 152 of file Socket.h.

References m_protocol.

◆ GetWaitableHandle()

IOObject::WaitableHandle Socket::GetWaitableHandle ( )
overridevirtual

Implements lldb_private::IOObject.

Definition at line 315 of file Socket.cpp.

References m_socket.

◆ Initialize()

llvm::Error Socket::Initialize ( )
static

Definition at line 176 of file Socket.cpp.

Referenced by lldb_private::SystemInitializerCommon::Initialize().

◆ IsValid()

bool lldb_private::Socket::IsValid ( ) const
inlineoverridevirtual

Implements lldb_private::IOObject.

Reimplemented in lldb_private::TCPSocket.

Definition at line 159 of file Socket.h.

References kInvalidSocketValue, and m_socket.

Referenced by Close().

◆ Listen()

virtual Status lldb_private::Socket::Listen ( llvm::StringRef name,
int backlog )
pure virtual

◆ Read()

Status Socket::Read ( void * buf,
size_t & num_bytes )
overridevirtual

◆ Send()

size_t Socket::Send ( const void * buf,
const size_t num_bytes )
protectedvirtual

Reimplemented in lldb_private::UDPSocket.

Definition at line 410 of file Socket.cpp.

References m_socket.

Referenced by Write().

◆ SetLastError()

◆ SetOption() [1/2]

int lldb_private::Socket::SetOption ( int level,
int option_name,
int option_value )
inline

Definition at line 147 of file Socket.h.

References m_socket, and SetOption().

◆ SetOption() [2/2]

int Socket::SetOption ( NativeSocket sockfd,
int level,
int option_name,
int option_value )
static

◆ TcpConnect()

llvm::Expected< std::unique_ptr< Socket > > Socket::TcpConnect ( llvm::StringRef host_and_port)
static

◆ TcpListen()

llvm::Expected< std::unique_ptr< TCPSocket > > Socket::TcpListen ( llvm::StringRef host_and_port,
int backlog = 5 )
static

Definition at line 272 of file Socket.cpp.

References lldb_private::Connection, error(), lldb_private::GetLog(), and LLDB_LOG.

◆ Terminate()

void Socket::Terminate ( )
static

Definition at line 194 of file Socket.cpp.

Referenced by lldb_private::SystemInitializerCommon::Terminate().

◆ UdpConnect()

llvm::Expected< std::unique_ptr< UDPSocket > > Socket::UdpConnect ( llvm::StringRef host_and_port)
static

◆ Write()

Status Socket::Write ( const void * buf,
size_t & num_bytes )
overridevirtual

Member Data Documentation

◆ kInvalidSocketValue

◆ m_protocol

SocketProtocol lldb_private::Socket::m_protocol
protected

Definition at line 186 of file Socket.h.

Referenced by GetSocketProtocol(), and Socket().

◆ m_should_close_fd

bool lldb_private::Socket::m_should_close_fd
protected

◆ m_socket


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