diff --git a/src/base/api/Api.cpp b/src/base/api/Api.cpp index 54666efd..a7246b9f 100644 --- a/src/base/api/Api.cpp +++ b/src/base/api/Api.cpp @@ -123,6 +123,20 @@ void xmrig::Api::stop() } +void xmrig::Api::tick() +{ +# ifdef XMRIG_FEATURE_HTTP + if (!m_base->config()->http().isEnabled() || m_httpd->isBound()) { + return; + } + if (++m_ticks % 10 == 0) { + m_ticks = 0; + m_httpd->start(); + } +# endif +} + + void xmrig::Api::onConfigChanged(Config *config, Config *previousConfig) { if (config->apiId() != previousConfig->apiId()) { diff --git a/src/base/api/Api.h b/src/base/api/Api.h index c56e29ee..685b56ff 100644 --- a/src/base/api/Api.h +++ b/src/base/api/Api.h @@ -54,6 +54,7 @@ public: void request(const HttpData &req); void start(); void stop(); + void tick(); protected: void onConfigChanged(Config *config, Config *previousConfig) override; @@ -67,6 +68,7 @@ private: char m_id[32]{}; String m_workerId; const uint64_t m_timestamp; + uint8_t m_ticks; Httpd *m_httpd = nullptr; std::vector m_listeners; }; diff --git a/src/base/api/Httpd.h b/src/base/api/Httpd.h index 188646f5..fe8cb914 100644 --- a/src/base/api/Httpd.h +++ b/src/base/api/Httpd.h @@ -48,6 +48,7 @@ public: bool start(); void stop(); + inline const bool isBound() const { return m_server != nullptr; } protected: void onConfigChanged(Config *config, Config *previousConfig) override; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index a3566242..841dd316 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -308,6 +308,9 @@ void xmrig::Network::tick() if (m_donate) { m_donate->tick(now); } +#ifdef XMRIG_FEATURE_API + m_controller->api()->tick(); +#endif }