xgboost
公共类型 | 公共成员函数 | 静态公共成员函数 | 所有成员列表
xgboost::collective::TCPSocket 类参考

用于简单通信的 TCP socket。更多...

#include <socket.h>

xgboost::collective::TCPSocket 协作图
Collaboration graph

公共类型

using HandleT = system::SocketT
 

公共成员函数

 TCPSocket ()=default
 
auto Domain () const -> SockDomain
 返回 socket 域。更多...
 
bool IsClosed () const
 
Result GetSockError () const
 获取上次的错误码(如有)。更多...
 
bool BadSocket () const
 检查是否发生了错误。更多...
 
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 ()
 接受新连接,返回用于此新连接的 TCP socket。更多...
 
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
 返回原生 socket 文件描述符。更多...
 
Result Listen (std::int32_t backlog=256)
 监听传入请求。应在 bind 后调用。更多...
 
Result BindHost (std::int32_t *p_out)
 将 socket 绑定到 INADDR_ANY,返回 OS 选择的端口。更多...
 
auto Port () const
 
Result Bind (StringView ip, std::int32_t *port)
 将 socket 绑定到指定地址。更多...
 
Result SendAll (void const *buf, std::size_t len, std::size_t *n_sent)
 发送数据,如果无错误则应发送所有数据。更多...
 
Result RecvAll (void *buf, std::size_t len, std::size_t *n_recv)
 接收数据,如果无错误则应接收所有数据。更多...
 
auto Send (const void *buf_, std::size_t len, std::int32_t flags=0)
 使用 socket 发送数据。更多...
 
auto Recv (void *buf, std::size_t len, std::int32_t flags=0)
 使用 socket 接收数据。更多...
 
std::size_t Send (StringView str)
 发送字符串,格式与 RABIT 中的 Python socket 包装器匹配。更多...
 
Result Recv (std::string *p_str)
 接收字符串,格式与 RABIT 中的 Python socket 包装器匹配。更多...
 
Result Close ()
 关闭 socket,如果 socket 未关闭,则在析构函数中自动调用。更多...
 
Result Shutdown ()
 对 socket 执行 shutdown 操作。更多...
 

静态公共成员函数

static TCPSocket Create (SockDomain domain)
 在指定域上创建一个 TCP socket。更多...
 
static TCPSocketCreatePtr (SockDomain domain)
 

详细说明

用于简单通信的 TCP socket。

成员 Typedef 文档

◆ HandleT

构造函数与析构函数文档

◆ 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

成员函数文档

◆ Accept() [1/2]

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

接受新连接,返回用于此新连接的 TCP socket。

◆ Accept() [2/2]

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

◆ BadSocket()

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

检查是否发生了错误

◆ Bind()

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

将 socket 绑定到指定地址。

参数
ip[输入]IP 地址。
port[输入, 输出] 如果此参数设置为 0,则由系统选择端口。

◆ BindHost()

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

将 socket 绑定到 INADDR_ANY,返回 OS 选择的端口。

◆ Close()

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

关闭 socket,如果 socket 未关闭,则在析构函数中自动调用。

◆ Create()

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

在指定域上创建一个 TCP socket。

◆ CreatePtr()

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

◆ Domain()

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

返回 socket 域。

◆ GetSockError()

Result xgboost::collective::TCPSocket::GetSockError ( ) const
inline

获取上次的错误码(如有)

◆ Handle()

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

返回原生 socket 文件描述符。

◆ IsClosed()

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

◆ Listen()

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

监听传入请求。应在 bind 后调用。

默认和最小 backlog 值都设置为 256。

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

接收字符串,格式与 RABIT 中的 Python socket 包装器匹配。

◆ Recv() [2/2]

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

使用 socket 接收数据

参数
buf缓冲区的指针
len缓冲区大小
flags额外标志
返回值
实际接收到的数据大小,如果发生错误则返回 -1

◆ RecvAll()

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

接收数据,如果无错误则应接收所有数据。

◆ 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

使用 socket 发送数据。

参数
buf缓冲区的指针
len缓冲区大小
flags额外标志
返回值
实际发送的数据大小,如果发生错误则返回 -1

◆ Send() [2/2]

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

发送字符串,格式与 RABIT 中的 Python socket 包装器匹配。

◆ SendAll()

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

发送数据,如果无错误则应发送所有数据。

◆ 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

对 socket 执行 shutdown 操作。


本类的文档生成自以下文件