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
 
Result GetSockError () const
 get last error code if any More...
 
bool BadSocket () const
 check if anything bad happens More...
 
Result NonBlocking (bool non_block)
 
bool NonBlocking () const
 
Result RecvTimeout (std::chrono::seconds timeout)
 
Result SetBufSize (std::int32_t n_bytes)
 
Result SendBufSize (std::int32_t *n_bytes)
 
Result RecvBufSize (std::int32_t *n_bytes)
 
Result SetKeepAlive ()
 
Result SetNoDelay (std::int32_t no_delay=1)
 
TCPSocket Accept ()
 Accept new connection, returns a new TCP socket for the new connection. More...
 
Result Accept (TCPSocket *out, SockAddress *addr)
 
 ~TCPSocket ()
 
 TCPSocket (TCPSocket const &that)=delete
 
 TCPSocket (TCPSocket &&that) noexcept(true)
 
TCPSocketoperator= (TCPSocket const &that)=delete
 
TCPSocketoperator= (TCPSocket &&that) noexcept(true)
 
HandleT const & Handle () const
 Return the native socket file descriptor. More...
 
Result Listen (std::int32_t backlog=16)
 Listen to incoming requests. Should be called after bind. More...
 
Result BindHost (std::int32_t *p_out)
 Bind socket to INADDR_ANY, return the port selected by the OS. More...
 
auto Port () const
 
Result Bind (StringView ip, std::int32_t *port)
 
Result SendAll (void const *buf, std::size_t len, std::size_t *n_sent)
 Send data, without error then all data should be sent. More...
 
Result RecvAll (void *buf, std::size_t len, std::size_t *n_recv)
 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...
 
Result Recv (std::string *p_str)
 Receive string, format is matched with the Python socket wrapper in RABIT. More...
 
Result Close ()
 Close the socket, called automatically in destructor if the socket is not closed. More...
 
Result Shutdown ()
 Call shutdown on the socket. More...
 

Static Public Member Functions

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

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() [1/2]

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

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

◆ Accept() [2/2]

Result xgboost::collective::TCPSocket::Accept ( TCPSocket out,
SockAddress addr 
)
inline

◆ BadSocket()

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

check if anything bad happens

◆ Bind()

Result xgboost::collective::TCPSocket::Bind ( StringView  ip,
std::int32_t *  port 
)
inline

◆ BindHost()

Result xgboost::collective::TCPSocket::BindHost ( std::int32_t *  p_out)
inline

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

◆ Close()

Result 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.

◆ CreatePtr()

static TCPSocket* xgboost::collective::TCPSocket::CreatePtr ( SockDomain  domain)
inlinestatic

◆ Domain()

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

Return the socket domain.

◆ GetSockError()

Result 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()

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

Listen to incoming requests. Should be called after bind.

◆ NonBlocking() [1/2]

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

◆ NonBlocking() [2/2]

Result xgboost::collective::TCPSocket::NonBlocking ( bool  non_block)
inline

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ Port()

auto xgboost::collective::TCPSocket::Port ( ) const
inline

◆ Recv() [1/2]

Result 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()

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

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

◆ RecvBufSize()

Result xgboost::collective::TCPSocket::RecvBufSize ( std::int32_t *  n_bytes)
inline

◆ RecvTimeout()

Result xgboost::collective::TCPSocket::RecvTimeout ( std::chrono::seconds  timeout)
inline

◆ 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()

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

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

◆ SendBufSize()

Result xgboost::collective::TCPSocket::SendBufSize ( std::int32_t *  n_bytes)
inline

◆ SetBufSize()

Result xgboost::collective::TCPSocket::SetBufSize ( std::int32_t  n_bytes)
inline

◆ SetKeepAlive()

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

◆ SetNoDelay()

Result xgboost::collective::TCPSocket::SetNoDelay ( std::int32_t  no_delay = 1)
inline

◆ Shutdown()

Result xgboost::collective::TCPSocket::Shutdown ( )
inline

Call shutdown on the socket.


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