refactor
This commit is contained in:
parent
f85d0bd333
commit
3cee38bf92
@ -85,7 +85,7 @@ void packet_client::connect(client &cli) {
|
||||
cli.socket.set_option(boost::asio::socket_base::linger(false, 0));
|
||||
|
||||
packet response;
|
||||
const auto res = read_packet(cli, response);
|
||||
auto res = read_packet(cli, response);
|
||||
if (res != 0) {
|
||||
throw std::runtime_error(std::to_string(res));
|
||||
}
|
||||
@ -98,18 +98,20 @@ auto packet_client::get_client() -> std::shared_ptr<packet_client::client> {
|
||||
std::shared_ptr<client> ret;
|
||||
|
||||
unique_mutex_lock clients_lock(clients_mutex_);
|
||||
if (allow_connections_) {
|
||||
if (clients_.empty()) {
|
||||
clients_lock.unlock();
|
||||
ret = std::make_shared<client>(io_context_);
|
||||
connect(*ret);
|
||||
} else {
|
||||
ret = clients_[0U];
|
||||
utils::collection::remove_element(clients_, ret);
|
||||
clients_lock.unlock();
|
||||
}
|
||||
if (not allow_connections_) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (clients_.empty()) {
|
||||
clients_lock.unlock();
|
||||
|
||||
ret = std::make_shared<client>(io_context_);
|
||||
connect(*ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = clients_.at(0U);
|
||||
utils::collection::remove_element(clients_, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user