refactor
This commit is contained in:
parent
6fc0085292
commit
5fcb182cb8
@ -109,7 +109,7 @@ auto packet_client::get_client() -> std::shared_ptr<packet_client::client> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto cli = clients_.at(0U);
|
auto cli = clients_.at(0U);
|
||||||
utils::collection::remove_element(clients_, cli);
|
utils::collection::remove_element(clients_, ret);
|
||||||
return cli;
|
return cli;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ auto packet_client::read_packet(client &cli, packet &response)
|
|||||||
const auto read_buffer = [&]() {
|
const auto read_buffer = [&]() {
|
||||||
std::uint32_t offset{};
|
std::uint32_t offset{};
|
||||||
while (offset < buffer.size()) {
|
while (offset < buffer.size()) {
|
||||||
const auto bytes_read = boost::asio::read(
|
auto bytes_read = boost::asio::read(
|
||||||
cli.socket,
|
cli.socket,
|
||||||
boost::asio::buffer(&buffer[offset], buffer.size() - offset));
|
boost::asio::buffer(&buffer[offset], buffer.size() - offset));
|
||||||
if (bytes_read <= 0) {
|
if (bytes_read <= 0) {
|
||||||
@ -137,7 +137,7 @@ auto packet_client::read_packet(client &cli, packet &response)
|
|||||||
};
|
};
|
||||||
read_buffer();
|
read_buffer();
|
||||||
|
|
||||||
const auto size = boost::endian::big_to_native(
|
auto size = boost::endian::big_to_native(
|
||||||
*reinterpret_cast<std::uint32_t *>(buffer.data()));
|
*reinterpret_cast<std::uint32_t *>(buffer.data()));
|
||||||
buffer.resize(size);
|
buffer.resize(size);
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ auto packet_client::send(std::string_view method, packet &request,
|
|||||||
request.encode_top(PACKET_SERVICE_FLAGS);
|
request.encode_top(PACKET_SERVICE_FLAGS);
|
||||||
request.encode_top(std::string{project_get_version()});
|
request.encode_top(std::string{project_get_version()});
|
||||||
|
|
||||||
static const std::uint8_t max_attempts{5U};
|
static contexpr const std::uint8_t max_attempts{5U};
|
||||||
for (std::uint8_t i = 1U;
|
for (std::uint8_t i = 1U;
|
||||||
allow_connections_ && not success && (i <= max_attempts); i++) {
|
allow_connections_ && not success && (i <= max_attempts); i++) {
|
||||||
auto current_client = get_client();
|
auto current_client = get_client();
|
||||||
@ -205,7 +205,7 @@ auto packet_client::send(std::string_view method, packet &request,
|
|||||||
|
|
||||||
std::uint32_t offset{};
|
std::uint32_t offset{};
|
||||||
while (offset < request.get_size()) {
|
while (offset < request.get_size()) {
|
||||||
const auto bytes_written = boost::asio::write(
|
auto bytes_written = boost::asio::write(
|
||||||
current_client->socket,
|
current_client->socket,
|
||||||
boost::asio::buffer(&request[offset],
|
boost::asio::buffer(&request[offset],
|
||||||
request.get_size() - offset));
|
request.get_size() - offset));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user