refactor
This commit is contained in:
@@ -34,7 +34,7 @@ non_blocking_guard::~non_blocking_guard() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boost::system::error_code err;
|
boost::system::error_code err;
|
||||||
[[maybe_unused]] auto ret = sock.non_blocking(non_blocking, err);
|
[[maybe_unused]] auto res = sock.non_blocking(non_blocking, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto is_socket_still_alive(boost::asio::ip::tcp::socket &sock) -> bool {
|
auto is_socket_still_alive(boost::asio::ip::tcp::socket &sock) -> bool {
|
||||||
|
@@ -308,6 +308,12 @@ auto packet_client::send(std::string_view method, packet &request,
|
|||||||
for (std::uint8_t retry = 1U;
|
for (std::uint8_t retry = 1U;
|
||||||
allow_connections_ && not success && (retry <= max_read_attempts);
|
allow_connections_ && not success && (retry <= max_read_attempts);
|
||||||
++retry) {
|
++retry) {
|
||||||
|
const auto retry_after_sleep = [&]() {
|
||||||
|
if (allow_connections_ && (retry < max_read_attempts)) {
|
||||||
|
std::this_thread::sleep_for(1s);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
auto current_client = get_client();
|
auto current_client = get_client();
|
||||||
if (current_client) {
|
if (current_client) {
|
||||||
try {
|
try {
|
||||||
@@ -333,16 +339,17 @@ auto packet_client::send(std::string_view method, packet &request,
|
|||||||
ret = res;
|
ret = res;
|
||||||
success = true;
|
success = true;
|
||||||
put_client(current_client);
|
put_client(current_client);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
utils::error::raise_error(function_name, e, "send failed");
|
utils::error::raise_error(function_name, e, "send failed");
|
||||||
close(*current_client);
|
close(*current_client);
|
||||||
if (allow_connections_ && (retry < max_read_attempts)) {
|
retry_after_sleep();
|
||||||
std::this_thread::sleep_for(1s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
retry_after_sleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not allow_connections_) {
|
if (not allow_connections_) {
|
||||||
|
Reference in New Issue
Block a user