#2018-010, parseCpp method added
This commit is contained in:
parent
70a7863897
commit
0e11379e69
3 changed files with 48 additions and 11 deletions
|
@ -25,16 +25,11 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue