From a8defacf2ba9bc3029b16af48a539553f873866b Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Sun, 29 Jan 2023 14:54:20 +0100 Subject: Fix timeout issues (#251) --- src/net/BoostHttpOnlySslClient.cpp | 2 +- src/net/CurlHttpClient.cpp | 2 +- src/net/TgLongPoll.cpp | 17 ++++++++--------- 3 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/net/BoostHttpOnlySslClient.cpp b/src/net/BoostHttpOnlySslClient.cpp index 6e59649..82bd897 100644 --- a/src/net/BoostHttpOnlySslClient.cpp +++ b/src/net/BoostHttpOnlySslClient.cpp @@ -52,7 +52,7 @@ string BoostHttpOnlySslClient::makeRequest(const Url& url, const vector> 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(_api->_httpClient)._timeout = _timeout + 5; } -TgLongPoll::TgLongPoll(const Bot& bot, std::int32_t limit, std::int32_t timeout, const std::shared_ptr>& 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>& allowUpdates) + : TgLongPoll(&bot.getApi(), &bot.getEventHandler(), limit, timeout, allowUpdates) { } void TgLongPoll::start() { - // get all unconfirmed updates - std::vector 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); } } -- cgit v1.2.3