From 0e11379e694eec39ca9ef864a4d548e1fd2911f0 Mon Sep 17 00:00:00 2001 From: avujic Date: Tue, 27 Mar 2018 21:31:25 +0200 Subject: [PATCH] #2018-010, parseCpp method added --- src/net/Url.cpp | 45 +++++++++++++++++++++++++++++++++------- src/net/Url.h | 6 ++++++ src/workers/Hashrate.cpp | 8 +++---- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/net/Url.cpp b/src/net/Url.cpp index dcbe82af..d423e9cc 100644 --- a/src/net/Url.cpp +++ b/src/net/Url.cpp @@ -25,16 +25,11 @@ #include #include #include - +#include #include "net/Url.h" -#ifdef _MSC_VER -# define strncasecmp(x,y,z) _strnicmp(x,y,z) -#endif - - Url::Url() : m_keepAlive(false), m_nicehash(false), @@ -87,7 +82,12 @@ Url::~Url() free(m_user); } - +/*--------------------------------------------------------------------- +* NAME : bool Url::parse(const char *url) +* SYNOPSIS : Parse URL string, xmrig original version +* DESCRIPTION: +* +---------------------------------------------------------------------*/ bool Url::parse(const char *url) { const char *p = strstr(url, "://"); @@ -120,6 +120,37 @@ bool Url::parse(const char *url) return true; } +/*--------------------------------------------------------------------- +* NAME : bool Url::parseCpp(const char *url) +* SYNOPSIS : Parse url string, C++ version +* DESCRIPTION: +* +---------------------------------------------------------------------*/ +bool Url::parseCpp(const char *url) +{ + std::stringstream strStream; + std::string strURL; + std::size_t found, il, ir; + //--- + + strStream << url; + strStream >> strURL; + + found = strURL.find("//"); + if (found == std::string::npos) il = 0; + else il = found + 2; + + found = strURL.rfind(":"); + if (found == std::string::npos) return(false); + else ir = found; + + + m_host_cpp.assign( strURL.substr(il, ir-il) ); + m_port = std::stoi( strURL.substr( ir+1, strURL.length() - ir) ); + //--- + return(true); +} + bool Url::setUserpass(const char *userpass) { diff --git a/src/net/Url.h b/src/net/Url.h index a1982300..ea00aa92 100644 --- a/src/net/Url.h +++ b/src/net/Url.h @@ -51,6 +51,7 @@ public: inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } bool parse(const char *url); + bool parseCpp(const char *url); //C++ version of parse bool setUserpass(const char *userpass); void applyExceptions(); void setPassword(const char *password); @@ -64,6 +65,11 @@ private: char *m_host; char *m_password; char *m_user; + //--- + std::string m_host_cpp; + std::string m_password_cpp; + std::string m_user_cpp; + //--- uint16_t m_port; }; diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp index 27d72560..6e70f41b 100644 --- a/src/workers/Hashrate.cpp +++ b/src/workers/Hashrate.cpp @@ -56,7 +56,7 @@ Hashrate::Hashrate(int threads) : m_timestamps[i] = new uint64_t[kBucketSize]; m_top[i] = 0; - memset(m_counts[0], 0, sizeof(uint64_t) * kBucketSize); + memset(m_counts[0], 0, sizeof(uint64_t) * kBucketSize); memset(m_timestamps[0], 0, sizeof(uint64_t) * kBucketSize); } @@ -115,7 +115,7 @@ double Hashrate::calc(size_t threadId, size_t ms) const break; } - earliestStamp = m_timestamps[threadId][idx]; + earliestStamp = m_timestamps[threadId][idx]; earliestHashCount = m_counts[threadId][idx]; } @@ -138,11 +138,11 @@ double Hashrate::calc(size_t threadId, size_t ms) const void Hashrate::add(size_t threadId, uint64_t count, uint64_t timestamp) { - const size_t top = m_top[threadId]; + const size_t top = m_top[threadId]; m_counts[threadId][top] = count; m_timestamps[threadId][top] = timestamp; - m_top[threadId] = (top + 1) & kBucketMask; + m_top[threadId] = (top + 1) & kBucketMask; }