Fix ClientManager without EventFd.

This commit is contained in:
levlam 2021-10-25 08:03:18 +03:00
parent d9607b4a46
commit e6c4bc6ca4
2 changed files with 10 additions and 2 deletions

View File

@ -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:

View File

@ -936,7 +936,11 @@ TEST(Client, Multi) {
TEST(Client, Manager) {
td::vector<td::thread> 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<td::td_api::testSquareInt>(3));
client.send(-1, 3, td::make_tl_object<td::td_api::testSquareInt>(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<bool> stop_send{false};
std::atomic<bool> 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;