From e6c4bc6ca4b0a0a67c08d16aeffb348cd1aa615b Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 25 Oct 2021 08:03:18 +0300 Subject: [PATCH] Fix ClientManager without EventFd. --- td/telegram/Client.cpp | 6 ++++-- test/tdclient.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/td/telegram/Client.cpp b/td/telegram/Client.cpp index d670854c6..66dd60507 100644 --- a/td/telegram/Client.cpp +++ b/td/telegram/Client.cpp @@ -129,7 +129,7 @@ class ClientManager::Impl final { } auto response = receiver_.receive(0); - if (response.client_id == 0 && concurrent_scheduler_ != nullptr) { + if (response.client_id == 0 && response.request_id == 0 && concurrent_scheduler_ != nullptr) { concurrent_scheduler_->run_main(0); response = receiver_.receive(0); } else { @@ -188,7 +188,9 @@ class ClientManager::Impl final { while (!tds_.empty() && !ExitGuard::is_exited()) { receive(0.1); } - concurrent_scheduler_->finish(); + if (concurrent_scheduler_ != nullptr) { + concurrent_scheduler_->finish(); + } } private: diff --git a/test/tdclient.cpp b/test/tdclient.cpp index 72363bc84..c351e7358 100644 --- a/test/tdclient.cpp +++ b/test/tdclient.cpp @@ -936,7 +936,11 @@ TEST(Client, Multi) { TEST(Client, Manager) { td::vector threads; td::ClientManager client; +#if !TD_EVENTFD_UNSUPPORTED // Client must be used from a single thread if there is no EventFd int threads_n = 4; +#else + int threads_n = 1; +#endif int clients_n = 1000; client.send(0, 3, td::make_tl_object(3)); client.send(-1, 3, td::make_tl_object(3)); @@ -969,6 +973,7 @@ TEST(Client, Manager) { } } +#if !TD_EVENTFD_UNSUPPORTED // Client must be used from a single thread if there is no EventFd TEST(Client, Close) { std::atomic stop_send{false}; std::atomic can_stop_receive{false}; @@ -1093,6 +1098,7 @@ TEST(Client, ManagerClose) { ASSERT_TRUE(request_ids.empty()); } #endif +#endif TEST(Client, ManagerCloseOneThread) { td::ClientManager client_manager;