aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/epee/include')
-rw-r--r--contrib/epee/include/math_helper.h20
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.inl8
-rw-r--r--contrib/epee/include/span.h3
3 files changed, 25 insertions, 6 deletions
diff --git a/contrib/epee/include/math_helper.h b/contrib/epee/include/math_helper.h
index 604a04680..29acffaea 100644
--- a/contrib/epee/include/math_helper.h
+++ b/contrib/epee/include/math_helper.h
@@ -32,6 +32,7 @@
#include <list>
#include <numeric>
+#include <random>
#include <boost/timer/timer.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/random_generator.hpp>
@@ -230,7 +231,7 @@ namespace math_helper
}
}
- template<uint64_t scale, int default_interval, bool start_immediate = true>
+ template<typename get_interval, bool start_immediate = true>
class once_a_time
{
uint64_t get_time() const
@@ -251,12 +252,18 @@ namespace math_helper
#endif
}
+ void set_next_interval()
+ {
+ m_interval = get_interval()();
+ }
+
public:
- once_a_time():m_interval(default_interval * scale)
+ once_a_time()
{
m_last_worked_time = 0;
if(!start_immediate)
m_last_worked_time = get_time();
+ set_next_interval();
}
void trigger()
@@ -273,6 +280,7 @@ namespace math_helper
{
bool res = functr();
m_last_worked_time = get_time();
+ set_next_interval();
return res;
}
return true;
@@ -283,9 +291,13 @@ namespace math_helper
uint64_t m_interval;
};
+ template<uint64_t N> struct get_constant_interval { public: uint64_t operator()() const { return N; } };
+
template<int default_interval, bool start_immediate = true>
- class once_a_time_seconds: public once_a_time<1000000, default_interval, start_immediate> {};
+ class once_a_time_seconds: public once_a_time<get_constant_interval<default_interval * (uint64_t)1000000>, start_immediate> {};
template<int default_interval, bool start_immediate = true>
- class once_a_time_milliseconds: public once_a_time<1000, default_interval, start_immediate> {};
+ class once_a_time_milliseconds: public once_a_time<get_constant_interval<default_interval * (uint64_t)1000>, start_immediate> {};
+ template<typename get_interval, bool start_immediate = true>
+ class once_a_time_seconds_range: public once_a_time<get_interval, start_immediate> {};
}
}
diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl
index 5d12f9466..128ff10aa 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.inl
+++ b/contrib/epee/include/net/abstract_tcp_server2.inl
@@ -410,7 +410,12 @@ PRAGMA_WARNING_DISABLE_VS(4355)
else
{
_dbg3("[sock " << socket().native_handle() << "] peer closed connection");
- if (m_ready_to_close)
+ bool do_shutdown = false;
+ CRITICAL_REGION_BEGIN(m_send_que_lock);
+ if(!m_send_que.size())
+ do_shutdown = true;
+ CRITICAL_REGION_END();
+ if (m_ready_to_close || do_shutdown)
shutdown();
}
m_ready_to_close = true;
@@ -470,6 +475,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
{
MERROR("SSL handshake failed");
boost::interprocess::ipcdetail::atomic_write32(&m_want_close_connection, 1);
+ m_ready_to_close = true;
bool do_shutdown = false;
CRITICAL_REGION_BEGIN(m_send_que_lock);
if(!m_send_que.size())
diff --git a/contrib/epee/include/span.h b/contrib/epee/include/span.h
index e100452ca..59895535f 100644
--- a/contrib/epee/include/span.h
+++ b/contrib/epee/include/span.h
@@ -110,7 +110,8 @@ namespace epee
constexpr std::size_t size() const noexcept { return len; }
constexpr std::size_t size_bytes() const noexcept { return size() * sizeof(value_type); }
- const T &operator[](size_t idx) const { return ptr[idx]; }
+ T &operator[](size_t idx) noexcept { return ptr[idx]; }
+ const T &operator[](size_t idx) const noexcept { return ptr[idx]; }
private:
T* ptr;