Fix some code bugs
This commit is contained in:
parent
82da84d849
commit
9b68f187f9
4 changed files with 26 additions and 29 deletions
|
@ -36,11 +36,11 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static inline char* createUserAgent()
|
static inline std::string createUserAgent()
|
||||||
{
|
{
|
||||||
const size_t max = 160;
|
const size_t max = 160;
|
||||||
|
|
||||||
char* buf = new char[max];
|
char buf[max];
|
||||||
|
|
||||||
#ifdef XMRIG_NVIDIA_PROJECT
|
#ifdef XMRIG_NVIDIA_PROJECT
|
||||||
const int cudaVersion = cuda_get_runtime_version();
|
const int cudaVersion = cuda_get_runtime_version();
|
||||||
|
@ -58,13 +58,13 @@ static inline char* createUserAgent()
|
||||||
|
|
||||||
void Platform::init(const std::string & userAgent)
|
void Platform::init(const std::string & userAgent)
|
||||||
{
|
{
|
||||||
m_userAgent = (userAgent.size() != "") ? userAgent : createUserAgent();
|
m_userAgent = (0 < userAgent.size()) ? userAgent : createUserAgent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Platform::release()
|
void Platform::release()
|
||||||
{
|
{
|
||||||
delete [] m_userAgent;
|
m_userAgent.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ static inline std::string createUserAgent()
|
||||||
{
|
{
|
||||||
const size_t max = 160;
|
const size_t max = 160;
|
||||||
|
|
||||||
char* buf = new char[max];
|
char buf[max];
|
||||||
int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION);
|
int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION);
|
||||||
|
|
||||||
#if defined(__x86_64__)
|
#if defined(__x86_64__)
|
||||||
|
@ -71,19 +71,15 @@ void Platform::init(const std::string & userAgent)
|
||||||
m_userAgent = (0 < userAgent.size()) ? userAgent : createUserAgent();
|
m_userAgent = (0 < userAgent.size()) ? userAgent : createUserAgent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Platform::release()
|
void Platform::release()
|
||||||
{
|
{
|
||||||
m_userAgent.clear();
|
m_userAgent.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Platform::setProcessPriority(int priority)
|
void Platform::setProcessPriority(int priority)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Platform::setThreadPriority(int priority)
|
void Platform::setThreadPriority(int priority)
|
||||||
{
|
{
|
||||||
if(priority == -1)
|
if(priority == -1)
|
||||||
|
|
|
@ -485,7 +485,7 @@ void Client::parse(char* line, size_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Client::parseNotification(const char* method, const rapidjson::Value & params,
|
void Client::parseNotification(const std::string & method, const rapidjson::Value & params,
|
||||||
const rapidjson::Value & error)
|
const rapidjson::Value & error)
|
||||||
{
|
{
|
||||||
if(error.IsObject())
|
if(error.IsObject())
|
||||||
|
@ -498,12 +498,12 @@ void Client::parseNotification(const char* method, const rapidjson::Value & para
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!method)
|
if(0 == method.size())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp(method, "job") == 0)
|
if(method == "job")
|
||||||
{
|
{
|
||||||
int code = -1;
|
int code = -1;
|
||||||
if(parseJob(params, &code))
|
if(parseJob(params, &code))
|
||||||
|
@ -522,7 +522,7 @@ void Client::parseResponse(int64_t id, const rapidjson::Value & result, const ra
|
||||||
{
|
{
|
||||||
if(error.IsObject())
|
if(error.IsObject())
|
||||||
{
|
{
|
||||||
const char* message = error["message"].GetString();
|
const std::string message = error["message"].GetString();
|
||||||
|
|
||||||
auto it = m_results.find(id);
|
auto it = m_results.find(id);
|
||||||
if(it != m_results.end())
|
if(it != m_results.end())
|
||||||
|
@ -582,8 +582,8 @@ void Client::parseResponse(int64_t id, const rapidjson::Value & result, const ra
|
||||||
void Client::ping()
|
void Client::ping()
|
||||||
{
|
{
|
||||||
send(snprintf(m_sendBuf, sizeof(m_sendBuf),
|
send(snprintf(m_sendBuf, sizeof(m_sendBuf),
|
||||||
"{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence,
|
"{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n",
|
||||||
m_rpcId));
|
m_sequence, m_rpcId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,8 @@ private:
|
||||||
void prelogin();
|
void prelogin();
|
||||||
void login();
|
void login();
|
||||||
void parse(char* line, size_t len);
|
void parse(char* line, size_t len);
|
||||||
void parseNotification(const char* method, const rapidjson::Value & params, const rapidjson::Value & error);
|
void parseNotification(const std::string & method, const rapidjson::Value & params,
|
||||||
|
const rapidjson::Value & error);
|
||||||
void parseResponse(int64_t id, const rapidjson::Value & result, const rapidjson::Value & error);
|
void parseResponse(int64_t id, const rapidjson::Value & result, const rapidjson::Value & error);
|
||||||
void ping();
|
void ping();
|
||||||
void reconnect();
|
void reconnect();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue