summaryrefslogtreecommitdiff
path: root/src/net/TgLongPoll.cpp
diff options
context:
space:
mode:
authorOleg Morozenkov <m@oleg.rocks>2023-01-29 18:17:12 +0300
committerGitHub <noreply@github.com>2023-01-29 18:17:12 +0300
commit4356f747596a42dd04766f9c7234fd1aded2eeda (patch)
tree8cea4cad5a8bc15e8213193743111f41a73e1461 /src/net/TgLongPoll.cpp
parentab7ce1f7ae842c74f67f3576542aa68f5eff8ebb (diff)
parenta8defacf2ba9bc3029b16af48a539553f873866b (diff)
Merge pull request #257 from llnulldisk/master
Fix timeout issues (#251)
Diffstat (limited to 'src/net/TgLongPoll.cpp')
-rw-r--r--src/net/TgLongPoll.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/net/TgLongPoll.cpp b/src/net/TgLongPoll.cpp
index 6a224cb..70333dd 100644
--- a/src/net/TgLongPoll.cpp
+++ b/src/net/TgLongPoll.cpp
@@ -12,20 +12,19 @@
namespace TgBot {
TgLongPoll::TgLongPoll(const Api* api, const EventHandler* eventHandler, std::int32_t limit, std::int32_t timeout, std::shared_ptr<std::vector<std::string>> allowUpdates)
- : _api(api), _eventHandler(eventHandler), _limit(limit), _timeout(timeout),
- _allowUpdates(std::move(allowUpdates)) {
+ : _api(api), _eventHandler(eventHandler), _limit(limit), _timeout(timeout)
+ , _allowUpdates(std::move(allowUpdates)) {
+
+ const_cast<TgBot::HttpClient&>(_api->_httpClient)._timeout = _timeout + 5;
}
-TgLongPoll::TgLongPoll(const Bot& bot, std::int32_t limit, std::int32_t timeout, const std::shared_ptr<std::vector<std::string>>& allowUpdates) :
- TgLongPoll(&bot.getApi(), &bot.getEventHandler(), limit, timeout, allowUpdates) {
+TgLongPoll::TgLongPoll(const Bot& bot, std::int32_t limit, std::int32_t timeout, const std::shared_ptr<std::vector<std::string>>& allowUpdates)
+ : TgLongPoll(&bot.getApi(), &bot.getEventHandler(), limit, timeout, allowUpdates) {
}
void TgLongPoll::start() {
- // get all unconfirmed updates
- std::vector<Update::Ptr> updates = _api->getUpdates(0, _limit, _timeout, _allowUpdates);
-
// handle updates
- for (Update::Ptr& item : updates) {
+ for (Update::Ptr& item : _updates) {
if (item->updateId >= _lastUpdateId) {
_lastUpdateId = item->updateId + 1;
}
@@ -33,7 +32,7 @@ void TgLongPoll::start() {
}
// confirm handled updates
- _api->getUpdates(_lastUpdateId, _limit, _timeout, _allowUpdates);
+ _updates = _api->getUpdates(_lastUpdateId, _limit, _timeout, _allowUpdates);
}
}