Fix handling of requests to unexisting Client.
GitOrigin-RevId: 5de9709abe73ae73dc52c9ca04c480a60efbf437
This commit is contained in:
parent
8a607933a7
commit
f7393d2717
@ -100,6 +100,10 @@ class TdReceiver {
|
|||||||
return td::make_unique<Callback>(client_id, this);
|
return td::make_unique<Callback>(client_id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add_response(ClientManager::ClientId client_id, uint64 id, td_api::object_ptr<td_api::Object> result) {
|
||||||
|
responses_.push({client_id, id, std::move(result)});
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::queue<ClientManager::Response> responses_;
|
std::queue<ClientManager::Response> responses_;
|
||||||
};
|
};
|
||||||
@ -256,6 +260,10 @@ class TdReceiver {
|
|||||||
return td::make_unique<Callback>(client_id, output_queue_);
|
return td::make_unique<Callback>(client_id, output_queue_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add_response(ClientManager::ClientId client_id, uint64 id, td_api::object_ptr<td_api::Object> result) {
|
||||||
|
output_queue_->writer_put({client_id, id, std::move(result)});
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using OutputQueue = MpscPollableQueue<ClientManager::Response>;
|
using OutputQueue = MpscPollableQueue<ClientManager::Response>;
|
||||||
std::shared_ptr<OutputQueue> output_queue_;
|
std::shared_ptr<OutputQueue> output_queue_;
|
||||||
@ -385,7 +393,11 @@ class ClientManager::Impl final {
|
|||||||
void send(ClientId client_id, RequestId request_id, td_api::object_ptr<td_api::Function> &&request) {
|
void send(ClientId client_id, RequestId request_id, td_api::object_ptr<td_api::Function> &&request) {
|
||||||
auto lock = impls_mutex_.lock_read().move_as_ok();
|
auto lock = impls_mutex_.lock_read().move_as_ok();
|
||||||
auto it = impls_.find(client_id);
|
auto it = impls_.find(client_id);
|
||||||
CHECK(it != impls_.end());
|
if (it == impls_.end()) {
|
||||||
|
receiver_->add_response(client_id, request_id,
|
||||||
|
td_api::make_object<td_api::error>(400, "Invalid TDLib instance specified"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
it->second->send(client_id, request_id, std::move(request));
|
it->second->send(client_id, request_id, std::move(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -922,6 +922,8 @@ TEST(Client, Manager) {
|
|||||||
td::ClientManager client;
|
td::ClientManager client;
|
||||||
int threads_n = 4;
|
int threads_n = 4;
|
||||||
int clients_n = 1000;
|
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));
|
||||||
for (int i = 0; i < threads_n; i++) {
|
for (int i = 0; i < threads_n; i++) {
|
||||||
threads.emplace_back([&] {
|
threads.emplace_back([&] {
|
||||||
for (int i = 0; i < clients_n; i++) {
|
for (int i = 0; i < clients_n; i++) {
|
||||||
@ -937,8 +939,13 @@ TEST(Client, Manager) {
|
|||||||
std::set<int32> ids;
|
std::set<int32> ids;
|
||||||
while (ids.size() != static_cast<size_t>(threads_n) * clients_n) {
|
while (ids.size() != static_cast<size_t>(threads_n) * clients_n) {
|
||||||
auto event = client.receive(10);
|
auto event = client.receive(10);
|
||||||
if (event.client_id != 0 && event.request_id == 3) {
|
if (event.client_id == 0 || event.client_id == -1) {
|
||||||
ids.insert(event.client_id);
|
ASSERT_EQ(td_api::error::ID, event.object->get_id());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (event.request_id == 3) {
|
||||||
|
ASSERT_EQ(td_api::testInt::ID, event.object->get_id());
|
||||||
|
ASSERT_TRUE(ids.insert(event.client_id).second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user