Rename class Url to Pool.

This commit is contained in:
XMRig 2018-04-11 06:09:34 +07:00
parent ad7545d149
commit 36ef254c73
18 changed files with 136 additions and 126 deletions

View file

@ -32,7 +32,7 @@
#include "core/CommonConfig.h"
#include "donate.h"
#include "log/Log.h"
#include "net/Url.h"
#include "net/Pool.h"
#include "rapidjson/document.h"
#include "rapidjson/filewritestream.h"
#include "rapidjson/prettywriter.h"
@ -79,7 +79,7 @@ xmrig::CommonConfig::CommonConfig() :
m_retries(5),
m_retryPause(5)
{
m_pools.push_back(new Url());
m_pools.push_back(Pool());
# ifdef XMRIG_PROXY_PROJECT
m_retries = 2;
@ -90,11 +90,6 @@ xmrig::CommonConfig::CommonConfig() :
xmrig::CommonConfig::~CommonConfig()
{
for (Url *url : m_pools) {
delete url;
}
m_pools.clear();
}
@ -112,8 +107,8 @@ bool xmrig::CommonConfig::adjust()
m_adjusted = true;
for (Url *url : m_pools) {
url->adjust(algorithm());
for (Pool &pool : m_pools) {
pool.adjust(algorithm());
}
return true;
@ -122,7 +117,7 @@ bool xmrig::CommonConfig::adjust()
bool xmrig::CommonConfig::isValid() const
{
return m_pools[0]->isValid();
return m_pools[0].isValid();
}
@ -138,12 +133,12 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable)
break;
case KeepAliveKey: /* --keepalive */
m_pools.back()->setKeepAlive(enable ? Url::kKeepAliveTimeout : 0);
m_pools.back().setKeepAlive(enable ? Pool::kKeepAliveTimeout : 0);
break;
# ifndef XMRIG_PROXY_PROJECT
case NicehashKey: /* --nicehash */
m_pools.back()->setNicehash(enable);
m_pools.back().setNicehash(enable);
break;
# endif
@ -177,38 +172,36 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg)
break;
case UserpassKey: /* --userpass */
if (!m_pools.back()->setUserpass(arg)) {
if (!m_pools.back().setUserpass(arg)) {
return false;
}
break;
case UrlKey: /* --url */
if (m_pools.size() > 1 || m_pools[0]->isValid()) {
Url *url = new Url(arg);
if (url->isValid()) {
m_pools.push_back(url);
}
else {
delete url;
if (m_pools.size() > 1 || m_pools[0].isValid()) {
Pool pool(arg);
if (pool.isValid()) {
m_pools.push_back(std::move(pool));
}
}
else {
m_pools[0]->parse(arg);
m_pools[0].parse(arg);
}
if (!m_pools.back()->isValid()) {
if (!m_pools.back().isValid()) {
return false;
}
break;
case UserKey: /* --user */
m_pools.back()->setUser(arg);
m_pools.back().setUser(arg);
break;
case PasswordKey: /* --pass */
m_pools.back()->setPassword(arg);
m_pools.back().setPassword(arg);
break;
case LogFileKey: /* --log-file */
@ -325,11 +318,11 @@ bool xmrig::CommonConfig::parseInt(int key, int arg)
break;
case KeepAliveKey: /* --keepalive */
m_pools.back()->setKeepAlive(arg);
m_pools.back().setKeepAlive(arg);
break;
case VariantKey: /* --variant */
m_pools.back()->setVariant(arg);
m_pools.back().setVariant(arg);
break;
case DonateLevelKey: /* --donate-level */

View file

@ -31,9 +31,7 @@
#include "core/utils/c_str.h"
#include "interfaces/IConfig.h"
#include "xmrig.h"
class Url;
#include "net/Pool.h"
namespace xmrig {
@ -58,7 +56,7 @@ public:
inline const char *apiWorkerId() const { return m_apiWorkerId.data(); }
inline const char *logFile() const { return m_logFile.data(); }
inline const char *userAgent() const { return m_userAgent.data(); }
inline const std::vector<Url*> &pools() const { return m_pools; }
inline const std::vector<Pool> &pools() const { return m_pools; }
inline int apiPort() const { return m_apiPort; }
inline int donateLevel() const { return m_donateLevel; }
inline int printTime() const { return m_printTime; }
@ -91,7 +89,7 @@ protected:
int m_printTime;
int m_retries;
int m_retryPause;
std::vector<Url*> m_pools;
std::vector<Pool> m_pools;
xmrig::c_str m_apiToken;
xmrig::c_str m_apiWorkerId;
xmrig::c_str m_fileName;

View file

@ -30,7 +30,7 @@
#include "core/ConfigCreator.h"
#include "core/ConfigLoader.h"
#include "Cpu.h"
#include "net/Url.h"
#include "net/Pool.h"
#include "rapidjson/document.h"
#include "rapidjson/filewritestream.h"
#include "rapidjson/prettywriter.h"
@ -110,22 +110,22 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
rapidjson::Value pools(rapidjson::kArrayType);
for (const Url *url : m_pools) {
for (const Pool &pool : m_pools) {
rapidjson::Value obj(rapidjson::kObjectType);
obj.AddMember("url", rapidjson::StringRef(url->url()), allocator);
obj.AddMember("user", rapidjson::StringRef(url->user()), allocator);
obj.AddMember("pass", rapidjson::StringRef(url->password()), allocator);
obj.AddMember("url", rapidjson::StringRef(pool.url()), allocator);
obj.AddMember("user", rapidjson::StringRef(pool.user()), allocator);
obj.AddMember("pass", rapidjson::StringRef(pool.password()), allocator);
if (url->keepAlive() == 0 || url->keepAlive() == Url::kKeepAliveTimeout) {
obj.AddMember("keepalive", url->keepAlive() > 0, allocator);
if (pool.keepAlive() == 0 || pool.keepAlive() == Pool::kKeepAliveTimeout) {
obj.AddMember("keepalive", pool.keepAlive() > 0, allocator);
}
else {
obj.AddMember("keepalive", url->keepAlive(), allocator);
obj.AddMember("keepalive", pool.keepAlive(), allocator);
}
obj.AddMember("nicehash", url->isNicehash(), allocator);
obj.AddMember("variant", url->variant(), allocator);
obj.AddMember("nicehash", pool.isNicehash(), allocator);
obj.AddMember("variant", pool.variant(), allocator);
pools.PushBack(obj, allocator);
}

View file

@ -38,7 +38,7 @@
#include "core/ConfigWatcher.h"
#include "interfaces/IConfig.h"
#include "interfaces/IWatcherListener.h"
#include "net/Url.h"
#include "net/Pool.h"
#include "Platform.h"
#include "rapidjson/document.h"
#include "rapidjson/error/en.h"

View file

@ -43,9 +43,11 @@ namespace xmrig {
class c_str
{
public:
inline c_str() : m_data(nullptr) {}
inline c_str(const char *str) : m_data(nullptr) { set(str); }
inline ~c_str() { free(m_data); }
inline c_str() : m_data(nullptr) {}
inline c_str(c_str &&other) { m_data = other.m_data; other.m_data = nullptr; }
inline c_str(const c_str &other) : m_data(nullptr) { set(other.data()); }
inline c_str(const char *str) : m_data(nullptr) { set(str); }
inline ~c_str() { free(m_data); }
inline void set(const char *str)