[coll] Reduce the scope of lock in the event loop. (#9784)

This commit is contained in:
Jiaming Yuan
2023-11-15 14:16:19 +08:00
committed by GitHub
parent 36a552ac98
commit ada377c57e
7 changed files with 117 additions and 70 deletions

View File

@@ -412,19 +412,24 @@ class TCPSocket {
return Success();
}
void SetKeepAlive() {
[[nodiscard]] Result SetKeepAlive() {
std::int32_t keepalive = 1;
xgboost_CHECK_SYS_CALL(setsockopt(handle_, SOL_SOCKET, SO_KEEPALIVE,
reinterpret_cast<char *>(&keepalive), sizeof(keepalive)),
0);
auto rc = setsockopt(handle_, SOL_SOCKET, SO_KEEPALIVE, reinterpret_cast<char *>(&keepalive),
sizeof(keepalive));
if (rc != 0) {
return system::FailWithCode("Failed to set TCP keeaplive.");
}
return Success();
}
void SetNoDelay() {
[[nodiscard]] Result SetNoDelay() {
std::int32_t tcp_no_delay = 1;
xgboost_CHECK_SYS_CALL(
setsockopt(handle_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&tcp_no_delay),
sizeof(tcp_no_delay)),
0);
auto rc = setsockopt(handle_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&tcp_no_delay),
sizeof(tcp_no_delay));
if (rc != 0) {
return system::FailWithCode("Failed to set TCP no delay.");
}
return Success();
}
/**