added a timer abstraction and replaced the use of boost.date_time. the timers used now are QueryPerformanceCounter on windows, mach_absolute_time on darwin and currently falls back on boost.date_time on other platforms. This has the advantage of being a monotonic clock, and also slightly more efficient
This commit is contained in:
@@ -81,11 +81,6 @@ namespace
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
using boost::posix_time::second_clock;
|
||||
using boost::posix_time::seconds;
|
||||
using boost::posix_time::ptime;
|
||||
using boost::posix_time::time_duration;
|
||||
|
||||
// returns -1 if gzip header is invalid or the header size in bytes
|
||||
int gzip_header(const char* buf, int size)
|
||||
{
|
||||
@@ -318,8 +313,8 @@ namespace libtorrent
|
||||
|
||||
timeout_handler::timeout_handler(asio::strand& str)
|
||||
: m_strand(str)
|
||||
, m_start_time(second_clock::universal_time())
|
||||
, m_read_time(second_clock::universal_time())
|
||||
, m_start_time(time_now())
|
||||
, m_read_time(time_now())
|
||||
, m_timeout(str.io_service())
|
||||
, m_completion_timeout(0)
|
||||
, m_read_timeout(0)
|
||||
@@ -330,8 +325,8 @@ namespace libtorrent
|
||||
{
|
||||
m_completion_timeout = completion_timeout;
|
||||
m_read_timeout = read_timeout;
|
||||
m_start_time = second_clock::universal_time();
|
||||
m_read_time = second_clock::universal_time();
|
||||
m_start_time = time_now();
|
||||
m_read_time = time_now();
|
||||
|
||||
m_timeout.expires_at(std::min(
|
||||
m_read_time + seconds(m_read_timeout)
|
||||
@@ -342,7 +337,7 @@ namespace libtorrent
|
||||
|
||||
void timeout_handler::restart_read_timeout()
|
||||
{
|
||||
m_read_time = second_clock::universal_time();
|
||||
m_read_time = time_now();
|
||||
}
|
||||
|
||||
void timeout_handler::cancel()
|
||||
@@ -356,14 +351,14 @@ namespace libtorrent
|
||||
if (error) return;
|
||||
if (m_completion_timeout == 0) return;
|
||||
|
||||
ptime now(second_clock::universal_time());
|
||||
ptime now(time_now());
|
||||
time_duration receive_timeout = now - m_read_time;
|
||||
time_duration completion_timeout = now - m_start_time;
|
||||
|
||||
if (m_read_timeout
|
||||
< receive_timeout.total_seconds()
|
||||
< total_seconds(receive_timeout)
|
||||
|| m_completion_timeout
|
||||
< completion_timeout.total_seconds())
|
||||
< total_seconds(completion_timeout))
|
||||
{
|
||||
on_timeout();
|
||||
return;
|
||||
|
Reference in New Issue
Block a user