From 871fe2210d781bd5605182591adc9dd587916cb5 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 30 Jul 2020 23:39:10 +0300 Subject: [PATCH] Major new Client fixes. GitOrigin-RevId: 34c263a4adb3c312328530e1382108d98e9048a3 --- td/telegram/Client.cpp | 6 +++--- test/tdclient.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/td/telegram/Client.cpp b/td/telegram/Client.cpp index b09b8dbe0..8f7fc03ef 100644 --- a/td/telegram/Client.cpp +++ b/td/telegram/Client.cpp @@ -280,7 +280,7 @@ class TdReceiver { } if (timeout != 0) { output_queue_->reader_get_event_fd().wait(static_cast(timeout * 1000)); - return receive(0); + return receive_unlocked(0); } return {0, 0, nullptr}; } @@ -357,6 +357,8 @@ class MultiImplPool { std::shared_ptr get() { std::unique_lock lock(mutex_); if (impls_.empty()) { + init_openssl_threads(); + impls_.resize(clamp(thread::hardware_concurrency(), 8u, 1000u) * 5 / 4); } auto &impl = *std::min_element(impls_.begin(), impls_.end(), @@ -476,8 +478,6 @@ class Client::Impl final { #endif Client::Client() : impl_(std::make_unique()) { - // At least it should be enough for everybody who uses TDLib - init_openssl_threads(); } void Client::send(Request &&request) { diff --git a/test/tdclient.cpp b/test/tdclient.cpp index b3edcbfac..44d14baaf 100644 --- a/test/tdclient.cpp +++ b/test/tdclient.cpp @@ -915,7 +915,7 @@ TEST(Client, MultiNew) { } std::set ids; - while (ids.size() * threads_n * clients_n) { + while (ids.size() != static_cast(threads_n) * clients_n) { auto event = client.receive(10); if (event.client_id != 0 && event.id == 3) { ids.insert(event.client_id);