mirror of
https://github.com/wownero/wownero.git
synced 2026-10-24 10:58:33 +02:00
epee: replace some fragile code
This commit is contained in:
@@ -87,7 +87,8 @@ namespace net_utils
|
|||||||
static std::mutex hosts_mutex;
|
static std::mutex hosts_mutex;
|
||||||
std::lock_guard<std::mutex> guard(hosts_mutex);
|
std::lock_guard<std::mutex> guard(hosts_mutex);
|
||||||
static std::map<std::string, unsigned int> hosts;
|
static std::map<std::string, unsigned int> hosts;
|
||||||
unsigned int &val = hosts[m_host];
|
auto it = hosts.emplace(m_host, 0).first;
|
||||||
|
unsigned int &val = it->second;
|
||||||
if (delta > 0)
|
if (delta > 0)
|
||||||
MTRACE("New connection from host " << m_host << ": " << val);
|
MTRACE("New connection from host " << m_host << ": " << val);
|
||||||
else if (delta < 0)
|
else if (delta < 0)
|
||||||
@@ -95,7 +96,9 @@ namespace net_utils
|
|||||||
CHECK_AND_ASSERT_THROW_MES(delta >= 0 || val >= (unsigned)-delta, "Count would go negative");
|
CHECK_AND_ASSERT_THROW_MES(delta >= 0 || val >= (unsigned)-delta, "Count would go negative");
|
||||||
CHECK_AND_ASSERT_THROW_MES(delta <= 0 || val <= std::numeric_limits<unsigned int>::max() - (unsigned)delta, "Count would wrap");
|
CHECK_AND_ASSERT_THROW_MES(delta <= 0 || val <= std::numeric_limits<unsigned int>::max() - (unsigned)delta, "Count would wrap");
|
||||||
val += delta;
|
val += delta;
|
||||||
return val;
|
const unsigned int ret = val;
|
||||||
|
if (ret == 0) hosts.erase(it);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ size_t network_throttle::get_recommended_size_of_planned_transport() const {
|
|||||||
|
|
||||||
double network_throttle::get_current_speed() const {
|
double network_throttle::get_current_speed() const {
|
||||||
unsigned int bytes_transferred = 0;
|
unsigned int bytes_transferred = 0;
|
||||||
if (m_history.size() == 0 || m_slot_size == 0)
|
if (m_history.size() <= 1 || m_slot_size == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
auto it = m_history.begin();
|
auto it = m_history.begin();
|
||||||
|
|||||||
Reference in New Issue
Block a user