init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
104
Telegram/SourceFiles/data/data_pts_waiter.h
Normal file
104
Telegram/SourceFiles/data/data_pts_waiter.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace Api {
|
||||
class Updates;
|
||||
} // namespace Api
|
||||
|
||||
enum PtsSkippedQueue {
|
||||
SkippedUpdate,
|
||||
SkippedUpdates,
|
||||
};
|
||||
|
||||
class PtsWaiter {
|
||||
public:
|
||||
explicit PtsWaiter(not_null<Api::Updates*> owner);
|
||||
|
||||
// 1s wait for skipped seq or pts in updates.
|
||||
static constexpr auto kWaitForSkippedTimeout = 1000;
|
||||
|
||||
void init(int32 pts) {
|
||||
_good = _last = _count = pts;
|
||||
clearSkippedUpdates();
|
||||
}
|
||||
bool inited() const {
|
||||
return _good > 0;
|
||||
}
|
||||
void setRequesting(bool isRequesting) {
|
||||
_requesting = isRequesting;
|
||||
if (_requesting) {
|
||||
clearSkippedUpdates();
|
||||
}
|
||||
}
|
||||
bool requesting() const {
|
||||
return _requesting;
|
||||
}
|
||||
bool waitingForSkipped() const {
|
||||
return _waitingForSkipped;
|
||||
}
|
||||
bool waitingForShortPoll() const {
|
||||
return _waitingForShortPoll;
|
||||
}
|
||||
void setWaitingForSkipped(ChannelData *channel, crl::time ms); // < 0 - not waiting
|
||||
void setWaitingForShortPoll(ChannelData *channel, crl::time ms); // < 0 - not waiting
|
||||
int32 current() const{
|
||||
return _good;
|
||||
}
|
||||
bool updated(
|
||||
ChannelData *channel,
|
||||
int32 pts,
|
||||
int32 count,
|
||||
const MTPUpdates &updates);
|
||||
bool updated(
|
||||
ChannelData *channel,
|
||||
int32 pts,
|
||||
int32 count,
|
||||
const MTPUpdate &update);
|
||||
bool updated(
|
||||
ChannelData *channel,
|
||||
int32 pts,
|
||||
int32 count);
|
||||
bool updateAndApply(
|
||||
ChannelData *channel,
|
||||
int32 pts,
|
||||
int32 count,
|
||||
const MTPUpdates &updates);
|
||||
bool updateAndApply(
|
||||
ChannelData *channel,
|
||||
int32 pts,
|
||||
int32 count,
|
||||
const MTPUpdate &update);
|
||||
bool updateAndApply(
|
||||
ChannelData *channel,
|
||||
int32 pts,
|
||||
int32 count);
|
||||
void applySkippedUpdates(ChannelData *channel);
|
||||
void clearSkippedUpdates();
|
||||
|
||||
private:
|
||||
// Return false if need to save that update and apply later.
|
||||
bool check(ChannelData *channel, int32 pts, int32 count);
|
||||
|
||||
uint64 ptsKey(PtsSkippedQueue queue, int32 pts);
|
||||
void checkForWaiting(ChannelData *channel);
|
||||
|
||||
const not_null<Api::Updates*> _owner;
|
||||
base::flat_map<uint64, PtsSkippedQueue> _queue;
|
||||
base::flat_map<uint64, MTPUpdate> _updateQueue;
|
||||
base::flat_map<uint64, MTPUpdates> _updatesQueue;
|
||||
int32 _good = 0;
|
||||
int32 _last = 0;
|
||||
int32 _count = 0;
|
||||
int32 _applySkippedLevel = 0;
|
||||
bool _requesting = false;
|
||||
bool _waitingForSkipped = false;
|
||||
bool _waitingForShortPoll = false;
|
||||
uint32 _skippedKey = 0;
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user