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) --- include/tgbot/Api.h | 3 ++- include/tgbot/net/HttpClient.h | 2 ++ include/tgbot/net/TgLongPoll.h | 8 +++++--- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index c3ae922..b34a10d 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -1982,12 +1982,13 @@ public: * @return Returns True if bot is blocked by user */ bool blockedByUser(std::int64_t chatId) const; + + const HttpClient& _httpClient; private: boost::property_tree::ptree sendRequest(const std::string& method, const std::vector& args = std::vector()) const; const std::string _token; - const HttpClient& _httpClient; const TgTypeParser _tgTypeParser; const std::string _url; }; diff --git a/include/tgbot/net/HttpClient.h b/include/tgbot/net/HttpClient.h index a35dd7d..024c8ad 100644 --- a/include/tgbot/net/HttpClient.h +++ b/include/tgbot/net/HttpClient.h @@ -26,6 +26,8 @@ public: * If at least 1 arg is marked as file, the content type of a request will be multipart/form-data, otherwise it will be application/x-www-form-urlencoded. */ virtual std::string makeRequest(const Url& url, const std::vector& args) const = 0; + + std::int32_t _timeout = 25; }; } diff --git a/include/tgbot/net/TgLongPoll.h b/include/tgbot/net/TgLongPoll.h index 417260a..9c50407 100644 --- a/include/tgbot/net/TgLongPoll.h +++ b/include/tgbot/net/TgLongPoll.h @@ -1,6 +1,7 @@ #ifndef TGBOT_TGLONGPOLL_H #define TGBOT_TGLONGPOLL_H +#include "tgbot/Api.h" #include "tgbot/export.h" #include @@ -10,7 +11,6 @@ namespace TgBot { -class Api; class Bot; class EventHandler; @@ -22,8 +22,8 @@ class EventHandler; class TGBOT_API TgLongPoll { public: - TgLongPoll(const Api* api, const EventHandler* eventHandler, std::int32_t, std::int32_t, std::shared_ptr>); - TgLongPoll(const Bot& bot, std::int32_t = 100, std::int32_t = 10, const std::shared_ptr>& = nullptr); + TgLongPoll(const Api* api, const EventHandler* eventHandler, std::int32_t limit, std::int32_t timeout, std::shared_ptr> allowUpdates); + TgLongPoll(const Bot& bot, std::int32_t limit = 100, std::int32_t timeout = 10, const std::shared_ptr>& allowUpdates = nullptr); /** * @brief Starts long poll. After new update will come, this method will parse it and send to EventHandler which invokes your listeners. Designed to be executed in a loop. @@ -37,6 +37,8 @@ private: std::int32_t _limit; std::int32_t _timeout; std::shared_ptr> _allowUpdates; + + std::vector _updates; }; } -- cgit v1.2.3