Utilities and cleanups for socket. (#9576)

- Use c++-17 nodiscard and nested ns.
- Add bind method to socket.
- Remove rabit parameters.
This commit is contained in:
Jiaming Yuan
2023-09-14 01:41:42 +08:00
committed by GitHub
parent 5abe50ff8c
commit b438d684d2
12 changed files with 187 additions and 75 deletions

View File

@@ -73,4 +73,15 @@ TEST(Socket, Basic) {
system::SocketFinalize();
}
TEST(Socket, Bind) {
system::SocketStartup();
auto any = SockAddrV4::InaddrAny().Addr();
auto sock = TCPSocket::Create(SockDomain::kV4);
std::int32_t port{0};
auto rc = sock.Bind(any, &port);
ASSERT_TRUE(rc.OK());
ASSERT_NE(port, 0);
system::SocketFinalize();
}
} // namespace xgboost::collective