xgboost
Public Types | Public Member Functions | Static Public Member Functions | List of all members
xgboost::collective::TCPSocket Class Reference

TCP socket for simple communication. More...

#include <socket.h>

Collaboration diagram for xgboost::collective::TCPSocket:
Collaboration graph

Public Types

using HandleT = system::SocketT
 

Public Member Functions

 TCPSocket ()=default
 
auto Domain () const -> SockDomain
 Return the socket domain. More...
 
bool IsClosed () const
 
std::int32_t GetSockError () const
 get last error code if any More...
 
bool BadSocket () const
 check if anything bad happens More...
 
void SetNonBlock ()
 
void SetKeepAlive ()
 
void SetNoDelay ()
 
TCPSocket Accept ()
 Accept new connection, returns a new TCP socket for the new connection. More...
 
 ~TCPSocket ()
 
 TCPSocket (TCPSocket const &that)=delete
 
 TCPSocket (TCPSocket &&that) noexcept(true)
 
TCPSocketoperator= (TCPSocket const &that)=delete
 
TCPSocketoperator= (TCPSocket &&that)
 
HandleT const & Handle () const
 Return the native socket file descriptor. More...
 
void Listen (std::int32_t backlog=16)
 Listen to incoming requests. Should be called after bind. More...
 
in_port_t BindHost ()
 Bind socket to INADDR_ANY, return the port selected by the OS. More...
 
auto SendAll (void const *buf, std::size_t len)
 Send data, without error then all data should be sent. More...
 
auto RecvAll (void *buf, std::size_t len)
 Receive data, without error then all data should be received. More...
 
auto Send (const void *buf_, std::size_t len, std::int32_t flags=0)
 Send data using the socket. More...
 
auto Recv (void *buf, std::size_t len, std::int32_t flags=0)
 receive data using the socket More...
 
std::size_t Send (StringView str)
 Send string, format is matched with the Python socket wrapper in RABIT. More...
 
std::size_t Recv (std::string *p_str)
 Receive string, format is matched with the Python socket wrapper in RABIT. More...
 
void Close ()
 Close the socket, called automatically in destructor if the socket is not closed. More...
 

Static Public Member Functions

static TCPSocket Create (SockDomain domain)
 Create a TCP socket on specified domain. More...
 

Detailed Description

TCP socket for simple communication.

Member Typedef Documentation

◆ HandleT

Constructor & Destructor Documentation

◆ TCPSocket() [1/3]

xgboost::collective::TCPSocket::TCPSocket ( )
default

◆ ~TCPSocket()

xgboost::collective::TCPSocket::~TCPSocket ( )
inline

◆ TCPSocket() [2/3]

xgboost::collective::TCPSocket::TCPSocket ( TCPSocket const &  that)
delete

◆ TCPSocket() [3/3]

xgboost::collective::TCPSocket::TCPSocket ( TCPSocket &&  that)
inlinenoexcept

Member Function Documentation

◆ Accept()

TCPSocket xgboost::collective::TCPSocket::Accept ( )
inline

Accept new connection, returns a new TCP socket for the new connection.

◆ BadSocket()

bool xgboost::collective::TCPSocket::BadSocket ( ) const
inline

check if anything bad happens

◆ BindHost()

in_port_t xgboost::collective::TCPSocket::BindHost ( )
inline

Bind socket to INADDR_ANY, return the port selected by the OS.

◆ Close()

void xgboost::collective::TCPSocket::Close ( )
inline

Close the socket, called automatically in destructor if the socket is not closed.

◆ Create()

static TCPSocket xgboost::collective::TCPSocket::Create ( SockDomain  domain)
inlinestatic

Create a TCP socket on specified domain.

◆ Domain()

auto xgboost::collective::TCPSocket::Domain ( ) const -> SockDomain
inline

Return the socket domain.

◆ GetSockError()

std::int32_t xgboost::collective::TCPSocket::GetSockError ( ) const
inline

get last error code if any

◆ Handle()

HandleT const& xgboost::collective::TCPSocket::Handle ( ) const
inline

Return the native socket file descriptor.

◆ IsClosed()

bool xgboost::collective::TCPSocket::IsClosed ( ) const
inline

◆ Listen()

void xgboost::collective::TCPSocket::Listen ( std::int32_t  backlog = 16)
inline

Listen to incoming requests. Should be called after bind.

◆ operator=() [1/2]

TCPSocket& xgboost::collective::TCPSocket::operator= ( TCPSocket &&  that)
inline

◆ operator=() [2/2]

TCPSocket& xgboost::collective::TCPSocket::operator= ( TCPSocket const &  that)
delete

◆ Recv() [1/2]

std::size_t xgboost::collective::TCPSocket::Recv ( std::string *  p_str)

Receive string, format is matched with the Python socket wrapper in RABIT.

◆ Recv() [2/2]

auto xgboost::collective::TCPSocket::Recv ( void *  buf,
std::size_t  len,
std::int32_t  flags = 0 
)
inline

receive data using the socket

Parameters
bufthe pointer to the buffer
lenthe size of the buffer
flagsextra flags
Returns
size of data actually received return -1 if error occurs

◆ RecvAll()

auto xgboost::collective::TCPSocket::RecvAll ( void *  buf,
std::size_t  len 
)
inline

Receive data, without error then all data should be received.

◆ Send() [1/2]

auto xgboost::collective::TCPSocket::Send ( const void *  buf_,
std::size_t  len,
std::int32_t  flags = 0 
)
inline

Send data using the socket.

Parameters
bufthe pointer to the buffer
lenthe size of the buffer
flagsextra flags
Returns
size of data actually sent return -1 if error occurs

◆ Send() [2/2]

std::size_t xgboost::collective::TCPSocket::Send ( StringView  str)

Send string, format is matched with the Python socket wrapper in RABIT.

◆ SendAll()

auto xgboost::collective::TCPSocket::SendAll ( void const *  buf,
std::size_t  len 
)
inline

Send data, without error then all data should be sent.

◆ SetKeepAlive()

void xgboost::collective::TCPSocket::SetKeepAlive ( )
inline

◆ SetNoDelay()

void xgboost::collective::TCPSocket::SetNoDelay ( )
inline

◆ SetNonBlock()

void xgboost::collective::TCPSocket::SetNonBlock ( )
inline

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