Medial Code Documentation
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions
xgboost::collective::TCPSocket Class Reference

TCP socket for simple communication. More...

#include <socket.h>

Public Types

using HandleT = system::SocketT
 

Public Member Functions

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

Static Public Member Functions

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

Detailed Description

TCP socket for simple communication.

Member Function Documentation

◆ Listen()

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

Listen to incoming requests.

Should be called after bind.

◆ Recv()

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

◆ Send()

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

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