Fixed graceful shutdown.
This commit is contained in:
parent
9732636155
commit
a3988374f0
15 changed files with 62 additions and 4 deletions
|
@ -123,7 +123,10 @@ int App::exec()
|
|||
|
||||
void App::close()
|
||||
{
|
||||
uv_stop(uv_default_loop());
|
||||
uv_signal_stop(&m_signal);
|
||||
|
||||
m_network->stop();
|
||||
Workers::stop();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
virtual int64_t submit(const JobResult &result) = 0;
|
||||
virtual void connect() = 0;
|
||||
virtual void resume() = 0;
|
||||
virtual void stop() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -135,6 +135,8 @@ void Client::connect(const Url *url)
|
|||
|
||||
void Client::disconnect()
|
||||
{
|
||||
uv_timer_stop(&m_keepAliveTimer);
|
||||
uv_timer_stop(&m_responseTimer);
|
||||
uv_timer_stop(&m_retriesTimer);
|
||||
m_failures = -1;
|
||||
|
||||
|
|
|
@ -76,6 +76,16 @@ void Network::connect()
|
|||
}
|
||||
|
||||
|
||||
void Network::stop()
|
||||
{
|
||||
if (m_donate) {
|
||||
m_donate->stop();
|
||||
}
|
||||
|
||||
m_strategy->stop();
|
||||
}
|
||||
|
||||
|
||||
void Network::onActive(Client *client)
|
||||
{
|
||||
if (client->id() == -1) {
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
~Network();
|
||||
|
||||
void connect();
|
||||
void stop();
|
||||
|
||||
static char *userAgent();
|
||||
|
||||
|
|
|
@ -62,6 +62,13 @@ void DonateStrategy::connect()
|
|||
}
|
||||
|
||||
|
||||
void DonateStrategy::stop()
|
||||
{
|
||||
uv_timer_stop(&m_timer);
|
||||
m_client->disconnect();
|
||||
}
|
||||
|
||||
|
||||
void DonateStrategy::onClose(Client *client, int failures)
|
||||
{
|
||||
}
|
||||
|
@ -96,7 +103,7 @@ void DonateStrategy::idle()
|
|||
}
|
||||
|
||||
|
||||
void DonateStrategy::stop()
|
||||
void DonateStrategy::suspend()
|
||||
{
|
||||
m_client->disconnect();
|
||||
|
||||
|
@ -115,5 +122,5 @@ void DonateStrategy::onTimer(uv_timer_t *handle)
|
|||
return strategy->connect();
|
||||
}
|
||||
|
||||
strategy->stop();
|
||||
strategy->suspend();
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ public:
|
|||
|
||||
int64_t submit(const JobResult &result) override;
|
||||
void connect() override;
|
||||
void stop() override;
|
||||
|
||||
protected:
|
||||
void onClose(Client *client, int failures) override;
|
||||
|
@ -57,7 +58,7 @@ protected:
|
|||
|
||||
private:
|
||||
void idle();
|
||||
void stop();
|
||||
void suspend();
|
||||
|
||||
static void onTimer(uv_timer_t *handle);
|
||||
|
||||
|
|
|
@ -61,6 +61,14 @@ void FailoverStrategy::resume()
|
|||
}
|
||||
|
||||
|
||||
void FailoverStrategy::stop()
|
||||
{
|
||||
for (size_t i = 0; i < m_pools.size(); ++i) {
|
||||
m_pools[i]->disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FailoverStrategy::onClose(Client *client, int failures)
|
||||
{
|
||||
if (failures == -1) {
|
||||
|
|
|
@ -48,6 +48,7 @@ public:
|
|||
int64_t submit(const JobResult &result) override;
|
||||
void connect() override;
|
||||
void resume() override;
|
||||
void stop() override;
|
||||
|
||||
protected:
|
||||
void onClose(Client *client, int failures) override;
|
||||
|
|
|
@ -60,6 +60,12 @@ void SinglePoolStrategy::resume()
|
|||
}
|
||||
|
||||
|
||||
void SinglePoolStrategy::stop()
|
||||
{
|
||||
m_client->disconnect();
|
||||
}
|
||||
|
||||
|
||||
void SinglePoolStrategy::onClose(Client *client, int failures)
|
||||
{
|
||||
if (!isActive()) {
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
int64_t submit(const JobResult &result) override;
|
||||
void connect() override;
|
||||
void resume() override;
|
||||
void stop() override;
|
||||
|
||||
protected:
|
||||
void onClose(Client *client, int failures) override;
|
||||
|
|
|
@ -161,6 +161,12 @@ void Hashrate::print()
|
|||
}
|
||||
|
||||
|
||||
void Hashrate::stop()
|
||||
{
|
||||
uv_timer_stop(&m_timer);
|
||||
}
|
||||
|
||||
|
||||
void Hashrate::updateHighest()
|
||||
{
|
||||
double highest = calc(2500);
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
double calc(size_t threadId, size_t ms) const;
|
||||
void add(size_t threadId, uint64_t count, uint64_t timestamp);
|
||||
void print();
|
||||
void stop();
|
||||
void updateHighest();
|
||||
|
||||
inline double highest() const { return m_highest; }
|
||||
|
|
|
@ -115,6 +115,15 @@ void Workers::start(int64_t affinity)
|
|||
}
|
||||
|
||||
|
||||
void Workers::stop()
|
||||
{
|
||||
uv_timer_stop(&m_timer);
|
||||
m_hashrate->stop();
|
||||
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(&m_async), nullptr);
|
||||
}
|
||||
|
||||
|
||||
void Workers::submit(const JobResult &result)
|
||||
{
|
||||
uv_mutex_lock(&m_mutex);
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
static void setEnabled(bool enabled);
|
||||
static void setJob(const Job &job);
|
||||
static void start(int64_t affinity);
|
||||
static void stop();
|
||||
static void submit(const JobResult &result);
|
||||
|
||||
static inline bool isEnabled() { return m_enabled; }
|
||||
|
|
Loading…
Reference in a new issue