Minor cut_tail improvements.
This commit is contained in:
parent
4a3f56e6c1
commit
b3aa31d398
@ -192,7 +192,6 @@ unique_ptr<RawConnection> SessionConnection::move_as_raw_connection() {
|
|||||||
return std::move(raw_connection_);
|
return std::move(raw_connection_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** SessionConnection ***/
|
|
||||||
BufferSlice SessionConnection::as_buffer_slice(Slice packet) {
|
BufferSlice SessionConnection::as_buffer_slice(Slice packet) {
|
||||||
return current_buffer_slice_->from_slice(packet);
|
return current_buffer_slice_->from_slice(packet);
|
||||||
}
|
}
|
||||||
@ -429,7 +428,7 @@ Status SessionConnection::on_packet(const MsgInfo &info, const mtproto_api::pong
|
|||||||
}
|
}
|
||||||
Status SessionConnection::on_packet(const MsgInfo &info, const mtproto_api::future_salts &salts) {
|
Status SessionConnection::on_packet(const MsgInfo &info, const mtproto_api::future_salts &salts) {
|
||||||
VLOG(mtproto) << "FUTURE_SALTS";
|
VLOG(mtproto) << "FUTURE_SALTS";
|
||||||
std::vector<ServerSalt> new_salts;
|
vector<ServerSalt> new_salts;
|
||||||
for (auto &it : salts.salts_) {
|
for (auto &it : salts.salts_) {
|
||||||
new_salts.push_back(
|
new_salts.push_back(
|
||||||
ServerSalt{it->salt_, static_cast<double>(it->valid_since_), static_cast<double>(it->valid_until_)});
|
ServerSalt{it->salt_, static_cast<double>(it->valid_since_), static_cast<double>(it->valid_until_)});
|
||||||
@ -440,7 +439,7 @@ Status SessionConnection::on_packet(const MsgInfo &info, const mtproto_api::futu
|
|||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status SessionConnection::on_msgs_state_info(const std::vector<int64> &ids, Slice info) {
|
Status SessionConnection::on_msgs_state_info(const vector<int64> &ids, Slice info) {
|
||||||
if (ids.size() != info.size()) {
|
if (ids.size() != info.size()) {
|
||||||
return Status::Error(PSLICE() << tag("ids.size()", ids.size()) << " != " << tag("info.size()", info.size()));
|
return Status::Error(PSLICE() << tag("ids.size()", ids.size()) << " != " << tag("info.size()", info.size()));
|
||||||
}
|
}
|
||||||
@ -897,7 +896,7 @@ void SessionConnection::flush_packet() {
|
|||||||
send_till++;
|
send_till++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::vector<MtprotoQuery> queries;
|
vector<MtprotoQuery> queries;
|
||||||
if (send_till == to_send_.size()) {
|
if (send_till == to_send_.size()) {
|
||||||
queries = std::move(to_send_);
|
queries = std::move(to_send_);
|
||||||
} else if (send_till != 0) {
|
} else if (send_till != 0) {
|
||||||
@ -922,14 +921,16 @@ void SessionConnection::flush_packet() {
|
|||||||
<< tag("resend", to_resend_answer_.size()) << tag("cancel", to_cancel_answer_.size())
|
<< tag("resend", to_resend_answer_.size()) << tag("cancel", to_cancel_answer_.size())
|
||||||
<< tag("destroy_key", destroy_auth_key) << tag("auth_id", auth_data_->get_auth_key().id());
|
<< tag("destroy_key", destroy_auth_key) << tag("auth_id", auth_data_->get_auth_key().id());
|
||||||
|
|
||||||
auto cut_tail = [](auto &v, size_t size, Slice name) {
|
auto cut_tail = [](vector<int64> &v, size_t size, Slice name) {
|
||||||
if (size >= v.size()) {
|
if (size >= v.size()) {
|
||||||
return std::move(v);
|
auto result = std::move(v);
|
||||||
|
v.clear();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
LOG(WARNING) << "Too much ids in container: " << v.size() << " " << name;
|
LOG(WARNING) << "Too much message identifiers in container " << name << ": " << v.size() << " instead of " << size;
|
||||||
std::decay_t<decltype(v)> res(std::make_move_iterator(v.end() - size), std::make_move_iterator(v.end()));
|
vector<int64> result(v.end() - size, v.end());
|
||||||
v.resize(v.size() - size);
|
v.resize(v.size() - size);
|
||||||
return res;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// no more than 8192 ids per container..
|
// no more than 8192 ids per container..
|
||||||
|
@ -164,15 +164,15 @@ class SessionConnection final
|
|||||||
|
|
||||||
struct ServiceQuery {
|
struct ServiceQuery {
|
||||||
enum Type { GetStateInfo, ResendAnswer } type;
|
enum Type { GetStateInfo, ResendAnswer } type;
|
||||||
std::vector<int64> message_ids;
|
vector<int64> message_ids;
|
||||||
};
|
};
|
||||||
std::vector<int64> to_resend_answer_;
|
vector<int64> to_resend_answer_;
|
||||||
std::vector<int64> to_cancel_answer_;
|
vector<int64> to_cancel_answer_;
|
||||||
std::vector<int64> to_get_state_info_;
|
vector<int64> to_get_state_info_;
|
||||||
std::unordered_map<uint64, ServiceQuery> service_queries_;
|
std::unordered_map<uint64, ServiceQuery> service_queries_;
|
||||||
|
|
||||||
// nobody cleans up this map. But it should be really small.
|
// nobody cleans up this map. But it should be really small.
|
||||||
std::unordered_map<uint64, std::vector<uint64>> container_to_service_msg_;
|
std::unordered_map<uint64, vector<uint64>> container_to_service_msg_;
|
||||||
|
|
||||||
double last_read_at_ = 0;
|
double last_read_at_ = 0;
|
||||||
double last_ping_at_ = 0;
|
double last_ping_at_ = 0;
|
||||||
@ -233,7 +233,7 @@ class SessionConnection final
|
|||||||
Status on_packet(const MsgInfo &info, const mtproto_api::pong &pong) TD_WARN_UNUSED_RESULT;
|
Status on_packet(const MsgInfo &info, const mtproto_api::pong &pong) TD_WARN_UNUSED_RESULT;
|
||||||
Status on_packet(const MsgInfo &info, const mtproto_api::future_salts &salts) TD_WARN_UNUSED_RESULT;
|
Status on_packet(const MsgInfo &info, const mtproto_api::future_salts &salts) TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
Status on_msgs_state_info(const std::vector<int64> &ids, Slice info) TD_WARN_UNUSED_RESULT;
|
Status on_msgs_state_info(const vector<int64> &ids, Slice info) TD_WARN_UNUSED_RESULT;
|
||||||
Status on_packet(const MsgInfo &info, const mtproto_api::msgs_state_info &msgs_state_info) TD_WARN_UNUSED_RESULT;
|
Status on_packet(const MsgInfo &info, const mtproto_api::msgs_state_info &msgs_state_info) TD_WARN_UNUSED_RESULT;
|
||||||
Status on_packet(const MsgInfo &info, const mtproto_api::msgs_all_info &msgs_all_info) TD_WARN_UNUSED_RESULT;
|
Status on_packet(const MsgInfo &info, const mtproto_api::msgs_all_info &msgs_all_info) TD_WARN_UNUSED_RESULT;
|
||||||
Status on_packet(const MsgInfo &info, const mtproto_api::msg_detailed_info &msg_detailed_info) TD_WARN_UNUSED_RESULT;
|
Status on_packet(const MsgInfo &info, const mtproto_api::msg_detailed_info &msg_detailed_info) TD_WARN_UNUSED_RESULT;
|
||||||
|
Loading…
Reference in New Issue
Block a user