2007-04-05 00:27:36 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2007, Arvid Norberg
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TORRENT_TIME_HPP_INCLUDED
|
|
|
|
#define TORRENT_TIME_HPP_INCLUDED
|
|
|
|
|
2007-04-10 09:52:58 +02:00
|
|
|
#include <ctime>
|
2008-05-20 11:45:55 +02:00
|
|
|
#include <boost/version.hpp>
|
2009-04-06 19:12:14 +02:00
|
|
|
#include "libtorrent/config.hpp"
|
2007-04-10 09:52:58 +02:00
|
|
|
|
2007-04-09 22:18:54 +02:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2007-04-10 09:52:58 +02:00
|
|
|
namespace libtorrent
|
|
|
|
{
|
|
|
|
inline char const* time_now_string()
|
|
|
|
{
|
|
|
|
time_t t = std::time(0);
|
2007-04-14 22:12:15 +02:00
|
|
|
tm* timeinfo = std::localtime(&t);
|
|
|
|
static char str[200];
|
|
|
|
std::strftime(str, 200, "%b %d %X", timeinfo);
|
|
|
|
return str;
|
2007-04-10 09:52:58 +02:00
|
|
|
}
|
2007-09-29 22:35:55 +02:00
|
|
|
|
2007-10-01 04:21:58 +02:00
|
|
|
std::string log_time();
|
2007-04-10 09:52:58 +02:00
|
|
|
}
|
|
|
|
|
2009-05-25 04:45:51 +02:00
|
|
|
#if defined TORRENT_USE_BOOST_DATE_TIME
|
2007-04-05 00:27:36 +02:00
|
|
|
|
2007-04-10 11:11:32 +02:00
|
|
|
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
2007-09-10 08:12:41 +02:00
|
|
|
#include "libtorrent/assert.hpp"
|
2007-04-05 00:27:36 +02:00
|
|
|
|
|
|
|
namespace libtorrent
|
|
|
|
{
|
|
|
|
typedef boost::posix_time::ptime ptime;
|
|
|
|
typedef boost::posix_time::time_duration time_duration;
|
2009-05-25 04:45:51 +02:00
|
|
|
inline ptime time_now_hires()
|
2007-04-05 00:27:36 +02:00
|
|
|
{ return boost::posix_time::microsec_clock::universal_time(); }
|
|
|
|
inline ptime min_time()
|
|
|
|
{ return boost::posix_time::ptime(boost::posix_time::min_date_time); }
|
|
|
|
inline ptime max_time()
|
|
|
|
{ return boost::posix_time::ptime(boost::posix_time::max_date_time); }
|
|
|
|
inline time_duration seconds(int s) { return boost::posix_time::seconds(s); }
|
|
|
|
inline time_duration milliseconds(int s) { return boost::posix_time::milliseconds(s); }
|
|
|
|
inline time_duration microsec(int s) { return boost::posix_time::microsec(s); }
|
|
|
|
inline time_duration minutes(int s) { return boost::posix_time::minutes(s); }
|
|
|
|
inline time_duration hours(int s) { return boost::posix_time::hours(s); }
|
|
|
|
|
|
|
|
inline int total_seconds(time_duration td)
|
|
|
|
{ return td.total_seconds(); }
|
|
|
|
inline int total_milliseconds(time_duration td)
|
|
|
|
{ return td.total_milliseconds(); }
|
|
|
|
inline boost::int64_t total_microseconds(time_duration td)
|
|
|
|
{ return td.total_microseconds(); }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-05-25 04:45:51 +02:00
|
|
|
#else // TORRENT_USE_BOOST_DATE_TIME
|
2007-04-05 00:27:36 +02:00
|
|
|
|
2008-05-20 08:03:46 +02:00
|
|
|
#if BOOST_VERSION < 103500
|
|
|
|
#include <asio/time_traits.hpp>
|
|
|
|
#else
|
2008-05-03 18:05:42 +02:00
|
|
|
#include <boost/asio/time_traits.hpp>
|
2008-05-20 08:03:46 +02:00
|
|
|
#endif
|
2007-04-05 00:27:36 +02:00
|
|
|
#include <boost/cstdint.hpp>
|
2007-09-10 08:12:41 +02:00
|
|
|
#include "libtorrent/assert.hpp"
|
2007-04-05 00:27:36 +02:00
|
|
|
|
|
|
|
namespace libtorrent
|
|
|
|
{
|
|
|
|
// libtorrent time_duration type
|
|
|
|
struct time_duration
|
|
|
|
{
|
|
|
|
time_duration() {}
|
2007-05-12 20:24:14 +02:00
|
|
|
time_duration operator/(int rhs) const { return time_duration(diff / rhs); }
|
2007-04-05 00:27:36 +02:00
|
|
|
explicit time_duration(boost::int64_t d) : diff(d) {}
|
2007-11-25 09:18:57 +01:00
|
|
|
time_duration& operator-=(time_duration const& c) { diff -= c.diff; return *this; }
|
2008-04-16 08:31:05 +02:00
|
|
|
time_duration& operator+=(time_duration const& c) { diff += c.diff; return *this; }
|
2009-08-20 05:19:12 +02:00
|
|
|
time_duration& operator*=(int v) { diff *= v; return *this; }
|
2007-12-04 03:53:10 +01:00
|
|
|
time_duration operator+(time_duration const& c) { return time_duration(diff + c.diff); }
|
2009-04-06 19:12:14 +02:00
|
|
|
time_duration operator-(time_duration const& c) { return time_duration(diff - c.diff); }
|
2007-04-05 00:27:36 +02:00
|
|
|
boost::int64_t diff;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline bool is_negative(time_duration dt) { return dt.diff < 0; }
|
2009-03-16 04:36:20 +01:00
|
|
|
inline bool operator==(time_duration lhs, time_duration rhs)
|
|
|
|
{ return lhs.diff == rhs.diff; }
|
2007-04-05 00:27:36 +02:00
|
|
|
inline bool operator<(time_duration lhs, time_duration rhs)
|
|
|
|
{ return lhs.diff < rhs.diff; }
|
2007-06-15 01:15:30 +02:00
|
|
|
inline bool operator<=(time_duration lhs, time_duration rhs)
|
|
|
|
{ return lhs.diff <= rhs.diff; }
|
2007-04-05 00:27:36 +02:00
|
|
|
inline bool operator>(time_duration lhs, time_duration rhs)
|
|
|
|
{ return lhs.diff > rhs.diff; }
|
2007-06-15 01:15:30 +02:00
|
|
|
inline bool operator>=(time_duration lhs, time_duration rhs)
|
|
|
|
{ return lhs.diff >= rhs.diff; }
|
2009-07-19 06:59:27 +02:00
|
|
|
inline time_duration operator*(time_duration lhs, int rhs)
|
2009-05-25 11:32:50 +02:00
|
|
|
{ return time_duration(boost::int64_t(lhs.diff * rhs)); }
|
2009-07-19 06:59:27 +02:00
|
|
|
inline time_duration operator*(int lhs, time_duration rhs)
|
2009-05-25 11:32:50 +02:00
|
|
|
{ return time_duration(boost::int64_t(lhs * rhs.diff)); }
|
2007-04-05 00:27:36 +02:00
|
|
|
|
|
|
|
// libtorrent time type
|
|
|
|
struct ptime
|
|
|
|
{
|
|
|
|
ptime() {}
|
2009-04-25 23:51:34 +02:00
|
|
|
explicit ptime(boost::uint64_t t): time(t) {}
|
2008-07-10 21:31:22 +02:00
|
|
|
ptime& operator+=(time_duration rhs) { time += rhs.diff; return *this; }
|
|
|
|
ptime& operator-=(time_duration rhs) { time -= rhs.diff; return *this; }
|
2009-04-25 23:51:34 +02:00
|
|
|
boost::uint64_t time;
|
2007-04-05 00:27:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
inline bool operator>(ptime lhs, ptime rhs)
|
|
|
|
{ return lhs.time > rhs.time; }
|
|
|
|
inline bool operator>=(ptime lhs, ptime rhs)
|
|
|
|
{ return lhs.time >= rhs.time; }
|
|
|
|
inline bool operator<=(ptime lhs, ptime rhs)
|
|
|
|
{ return lhs.time <= rhs.time; }
|
|
|
|
inline bool operator<(ptime lhs, ptime rhs)
|
|
|
|
{ return lhs.time < rhs.time; }
|
|
|
|
inline bool operator!=(ptime lhs, ptime rhs)
|
|
|
|
{ return lhs.time != rhs.time;}
|
|
|
|
inline bool operator==(ptime lhs, ptime rhs)
|
|
|
|
{ return lhs.time == rhs.time;}
|
|
|
|
inline time_duration operator-(ptime lhs, ptime rhs)
|
|
|
|
{ return time_duration(lhs.time - rhs.time); }
|
|
|
|
inline ptime operator+(ptime lhs, time_duration rhs)
|
|
|
|
{ return ptime(lhs.time + rhs.diff); }
|
|
|
|
inline ptime operator+(time_duration lhs, ptime rhs)
|
|
|
|
{ return ptime(rhs.time + lhs.diff); }
|
|
|
|
inline ptime operator-(ptime lhs, time_duration rhs)
|
|
|
|
{ return ptime(lhs.time - rhs.diff); }
|
|
|
|
|
2009-05-25 04:45:51 +02:00
|
|
|
ptime time_now_hires();
|
2007-04-05 00:27:36 +02:00
|
|
|
inline ptime min_time() { return ptime(0); }
|
2009-04-25 23:51:34 +02:00
|
|
|
inline ptime max_time() { return ptime((std::numeric_limits<boost::uint64_t>::max)()); }
|
2007-04-05 00:27:36 +02:00
|
|
|
int total_seconds(time_duration td);
|
|
|
|
int total_milliseconds(time_duration td);
|
|
|
|
boost::int64_t total_microseconds(time_duration td);
|
|
|
|
}
|
|
|
|
|
|
|
|
// asio time_traits
|
2008-05-20 11:45:55 +02:00
|
|
|
#if BOOST_VERSION >= 103500
|
2008-05-20 08:03:46 +02:00
|
|
|
namespace boost {
|
|
|
|
#endif
|
|
|
|
namespace asio
|
2007-04-05 00:27:36 +02:00
|
|
|
{
|
|
|
|
template<>
|
|
|
|
struct time_traits<libtorrent::ptime>
|
|
|
|
{
|
|
|
|
typedef libtorrent::ptime time_type;
|
|
|
|
typedef libtorrent::time_duration duration_type;
|
|
|
|
static time_type now()
|
2009-05-25 04:45:51 +02:00
|
|
|
{ return time_type(libtorrent::time_now_hires()); }
|
2007-04-05 00:27:36 +02:00
|
|
|
static time_type add(time_type t, duration_type d)
|
|
|
|
{ return time_type(t.time + d.diff);}
|
|
|
|
static duration_type subtract(time_type t1, time_type t2)
|
|
|
|
{ return duration_type(t1 - t2); }
|
|
|
|
static bool less_than(time_type t1, time_type t2)
|
|
|
|
{ return t1 < t2; }
|
|
|
|
static boost::posix_time::time_duration to_posix_duration(
|
|
|
|
duration_type d)
|
|
|
|
{ return boost::posix_time::microseconds(libtorrent::total_microseconds(d)); }
|
|
|
|
};
|
2008-05-20 08:03:46 +02:00
|
|
|
}
|
2008-05-20 11:45:55 +02:00
|
|
|
#if BOOST_VERSION >= 103500
|
2008-05-20 08:03:46 +02:00
|
|
|
}
|
|
|
|
#endif
|
2007-04-05 00:27:36 +02:00
|
|
|
|
2009-05-25 04:45:51 +02:00
|
|
|
#if defined TORRENT_USE_ABSOLUTE_TIME
|
2007-04-05 00:27:36 +02:00
|
|
|
|
|
|
|
#include <mach/mach_time.h>
|
|
|
|
#include <boost/cstdint.hpp>
|
2007-09-10 08:12:41 +02:00
|
|
|
#include "libtorrent/assert.hpp"
|
2007-04-05 00:27:36 +02:00
|
|
|
|
|
|
|
// high precision timer for darwin intel and ppc
|
|
|
|
|
|
|
|
namespace libtorrent
|
|
|
|
{
|
|
|
|
inline int total_seconds(time_duration td)
|
|
|
|
{
|
2009-04-25 23:51:34 +02:00
|
|
|
return td.diff / 1000000;
|
2007-04-05 00:27:36 +02:00
|
|
|
}
|
|
|
|
inline int total_milliseconds(time_duration td)
|
|
|
|
{
|
2009-04-25 23:51:34 +02:00
|
|
|
return td.diff / 1000;
|
2007-04-05 00:27:36 +02:00
|
|
|
}
|
|
|
|
inline boost::int64_t total_microseconds(time_duration td)
|
|
|
|
{
|
2009-04-25 23:51:34 +02:00
|
|
|
return td.diff;
|
2007-04-05 00:27:36 +02:00
|
|
|
}
|
|
|
|
|
2009-05-25 04:45:51 +02:00
|
|
|
inline ptime time_now_hires()
|
2009-04-25 23:51:34 +02:00
|
|
|
{
|
|
|
|
static mach_timebase_info_data_t timebase_info = {0,0};
|
|
|
|
if (timebase_info.denom == 0)
|
|
|
|
mach_timebase_info(&timebase_info);
|
|
|
|
boost::uint64_t at = mach_absolute_time();
|
|
|
|
// make sure we don't overflow
|
|
|
|
TORRENT_ASSERT((at >= 0 && at >= at / 1000 * timebase_info.numer / timebase_info.denom)
|
|
|
|
|| (at < 0 && at < at / 1000 * timebase_info.numer / timebase_info.denom));
|
|
|
|
return ptime(at / 1000 * timebase_info.numer / timebase_info.denom);
|
|
|
|
}
|
2007-04-05 00:27:36 +02:00
|
|
|
|
|
|
|
inline time_duration microsec(boost::int64_t s)
|
|
|
|
{
|
2009-04-25 23:51:34 +02:00
|
|
|
return time_duration(s);
|
2007-04-05 00:27:36 +02:00
|
|
|
}
|
|
|
|
inline time_duration milliseconds(boost::int64_t s)
|
|
|
|
{
|
2009-04-25 23:51:34 +02:00
|
|
|
return time_duration(s * 1000);
|
2007-04-05 00:27:36 +02:00
|
|
|
}
|
|
|
|
inline time_duration seconds(boost::int64_t s)
|
|
|
|
{
|
2009-04-25 23:51:34 +02:00
|
|
|
return time_duration(s * 1000000);
|
2007-04-05 00:27:36 +02:00
|
|
|
}
|
|
|
|
inline time_duration minutes(boost::int64_t s)
|
|
|
|
{
|
2009-04-25 23:51:34 +02:00
|
|
|
return time_duration(s * 1000000 * 60);
|
2007-04-05 00:27:36 +02:00
|
|
|
}
|
|
|
|
inline time_duration hours(boost::int64_t s)
|
|
|
|
{
|
2009-04-25 23:51:34 +02:00
|
|
|
return time_duration(s * 1000000 * 60 * 60);
|
2007-04-05 00:27:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2009-05-25 04:45:51 +02:00
|
|
|
#elif defined TORRENT_USE_QUERY_PERFORMANCE_TIMER
|
2007-04-05 00:27:36 +02:00
|
|
|
|
2007-04-05 03:08:21 +02:00
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
2007-04-05 00:27:36 +02:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2007-04-05 03:08:21 +02:00
|
|
|
#endif
|
2008-04-28 01:21:04 +02:00
|
|
|
#include <windows.h>
|
2007-09-10 08:12:41 +02:00
|
|
|
#include "libtorrent/assert.hpp"
|
2007-04-05 00:27:36 +02:00
|
|
|
|
|
|
|
namespace libtorrent
|
|
|
|
{
|
|
|
|
namespace aux
|
|
|
|
{
|
|
|
|
inline boost::int64_t performance_counter_to_microseconds(boost::int64_t pc)
|
|
|
|
{
|
|
|
|
static LARGE_INTEGER performace_counter_frequency = {0,0};
|
|
|
|
if (performace_counter_frequency.QuadPart == 0)
|
|
|
|
QueryPerformanceFrequency(&performace_counter_frequency);
|
|
|
|
|
2008-11-29 22:33:21 +01:00
|
|
|
#ifdef TORRENT_DEBUG
|
2007-04-26 23:33:07 +02:00
|
|
|
// make sure we don't overflow
|
|
|
|
boost::int64_t ret = (pc * 1000 / performace_counter_frequency.QuadPart) * 1000;
|
2007-10-05 02:30:00 +02:00
|
|
|
TORRENT_ASSERT((pc >= 0 && pc >= ret) || (pc < 0 && pc < ret));
|
2007-04-26 23:33:07 +02:00
|
|
|
#endif
|
|
|
|
return (pc * 1000 / performace_counter_frequency.QuadPart) * 1000;
|
2007-04-05 00:27:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline boost::int64_t microseconds_to_performance_counter(boost::int64_t ms)
|
|
|
|
{
|
|
|
|
static LARGE_INTEGER performace_counter_frequency = {0,0};
|
|
|
|
if (performace_counter_frequency.QuadPart == 0)
|
|
|
|
QueryPerformanceFrequency(&performace_counter_frequency);
|
2008-11-29 22:33:21 +01:00
|
|
|
#ifdef TORRENT_DEBUG
|
2007-04-26 23:33:07 +02:00
|
|
|
// make sure we don't overflow
|
|
|
|
boost::int64_t ret = (ms / 1000) * performace_counter_frequency.QuadPart / 1000;
|
2007-10-05 02:30:00 +02:00
|
|
|
TORRENT_ASSERT((ms >= 0 && ms <= ret)
|
2007-04-26 23:33:07 +02:00
|
|
|
|| (ms < 0 && ms > ret));
|
|
|
|
#endif
|
|
|
|
return (ms / 1000) * performace_counter_frequency.QuadPart / 1000;
|
2007-04-05 00:27:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int total_seconds(time_duration td)
|
|
|
|
{
|
2008-04-05 23:18:27 +02:00
|
|
|
return int(aux::performance_counter_to_microseconds(td.diff)
|
|
|
|
/ 1000000);
|
2007-04-05 00:27:36 +02:00
|
|
|
}
|
|
|
|
inline int total_milliseconds(time_duration td)
|
|
|
|
{
|
2008-04-05 23:18:27 +02:00
|
|
|
return int(aux::performance_counter_to_microseconds(td.diff)
|
|
|
|
/ 1000);
|
2007-04-05 00:27:36 +02:00
|
|
|
}
|
|
|
|
inline boost::int64_t total_microseconds(time_duration td)
|
|
|
|
{
|
|
|
|
return aux::performance_counter_to_microseconds(td.diff);
|
|
|
|
}
|
|
|
|
|
2009-05-25 04:45:51 +02:00
|
|
|
inline ptime time_now_hires()
|
2007-04-05 00:27:36 +02:00
|
|
|
{
|
|
|
|
LARGE_INTEGER now;
|
|
|
|
QueryPerformanceCounter(&now);
|
|
|
|
return ptime(now.QuadPart);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline time_duration microsec(boost::int64_t s)
|
|
|
|
{
|
|
|
|
return time_duration(aux::microseconds_to_performance_counter(s));
|
|
|
|
}
|
|
|
|
inline time_duration milliseconds(boost::int64_t s)
|
|
|
|
{
|
|
|
|
return time_duration(aux::microseconds_to_performance_counter(
|
|
|
|
s * 1000));
|
|
|
|
}
|
|
|
|
inline time_duration seconds(boost::int64_t s)
|
|
|
|
{
|
|
|
|
return time_duration(aux::microseconds_to_performance_counter(
|
|
|
|
s * 1000000));
|
|
|
|
}
|
|
|
|
inline time_duration minutes(boost::int64_t s)
|
|
|
|
{
|
|
|
|
return time_duration(aux::microseconds_to_performance_counter(
|
|
|
|
s * 1000000 * 60));
|
|
|
|
}
|
|
|
|
inline time_duration hours(boost::int64_t s)
|
|
|
|
{
|
|
|
|
return time_duration(aux::microseconds_to_performance_counter(
|
|
|
|
s * 1000000 * 60 * 60));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-05-25 04:45:51 +02:00
|
|
|
#elif defined TORRENT_USE_CLOCK_GETTIME
|
2007-04-09 22:18:54 +02:00
|
|
|
|
|
|
|
#include <time.h>
|
2007-09-10 08:12:41 +02:00
|
|
|
#include "libtorrent/assert.hpp"
|
2007-04-09 22:18:54 +02:00
|
|
|
|
|
|
|
namespace libtorrent
|
|
|
|
{
|
|
|
|
inline int total_seconds(time_duration td)
|
|
|
|
{
|
|
|
|
return td.diff / 1000000;
|
|
|
|
}
|
|
|
|
inline int total_milliseconds(time_duration td)
|
|
|
|
{
|
|
|
|
return td.diff / 1000;
|
|
|
|
}
|
|
|
|
inline boost::int64_t total_microseconds(time_duration td)
|
|
|
|
{
|
|
|
|
return td.diff;
|
|
|
|
}
|
|
|
|
|
2009-05-25 04:45:51 +02:00
|
|
|
inline ptime time_now_hires()
|
2007-04-09 22:18:54 +02:00
|
|
|
{
|
|
|
|
timespec ts;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
2009-04-25 23:51:34 +02:00
|
|
|
return ptime(boost::uint64_t(ts.tv_sec) * 1000000 + ts.tv_nsec / 1000);
|
2007-04-09 22:18:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline time_duration microsec(boost::int64_t s)
|
|
|
|
{
|
|
|
|
return time_duration(s);
|
|
|
|
}
|
|
|
|
inline time_duration milliseconds(boost::int64_t s)
|
|
|
|
{
|
|
|
|
return time_duration(s * 1000);
|
|
|
|
}
|
|
|
|
inline time_duration seconds(boost::int64_t s)
|
|
|
|
{
|
|
|
|
return time_duration(s * 1000000);
|
|
|
|
}
|
|
|
|
inline time_duration minutes(boost::int64_t s)
|
|
|
|
{
|
|
|
|
return time_duration(s * 1000000 * 60);
|
|
|
|
}
|
|
|
|
inline time_duration hours(boost::int64_t s)
|
|
|
|
{
|
|
|
|
return time_duration(s * 1000000 * 60 * 60);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-05-25 04:45:51 +02:00
|
|
|
#endif // TORRENT_USE_CLOCK_GETTIME
|
2007-04-05 00:27:36 +02:00
|
|
|
|
2009-05-25 04:45:51 +02:00
|
|
|
#endif // TORRENT_USE_BOOST_DATE_TIME
|
2007-09-29 18:14:03 +02:00
|
|
|
|
2009-05-25 04:45:51 +02:00
|
|
|
namespace libtorrent
|
|
|
|
{
|
|
|
|
namespace aux
|
|
|
|
{
|
2009-07-26 04:27:52 +02:00
|
|
|
extern TORRENT_EXPORT ptime g_current_time;
|
2009-05-25 04:45:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline ptime const& time_now() { return aux::g_current_time; }
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // TORRENT_TIME_HPP_INCLUDED
|
2007-09-10 08:12:41 +02:00
|
|
|
|