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:
Arvid Norberg 2007-04-04 22:27:36 +00:00
parent 7fc238407c
commit 306d015924
42 changed files with 590 additions and 366 deletions

View File

@ -148,6 +148,8 @@ void clear_home()
#endif #endif
namespace pt = boost::posix_time;
std::string esc(char const* code) std::string esc(char const* code)
{ {
#ifdef ANSI_TERMINAL_COLORS #ifdef ANSI_TERMINAL_COLORS
@ -310,9 +312,6 @@ void print_peer_info(std::ostream& out, std::vector<libtorrent::peer_info> const
typedef std::multimap<std::string, libtorrent::torrent_handle> handles_t; typedef std::multimap<std::string, libtorrent::torrent_handle> handles_t;
using boost::posix_time::ptime;
using boost::posix_time::second_clock;
using boost::posix_time::seconds;
using boost::bind; using boost::bind;
using boost::filesystem::path; using boost::filesystem::path;
using boost::filesystem::exists; using boost::filesystem::exists;
@ -579,7 +578,7 @@ int main(int ac, char* av[])
std::deque<std::string> events; std::deque<std::string> events;
ptime next_dir_scan = second_clock::universal_time(); boost::posix_time::ptime next_dir_scan = boost::posix_time::second_clock::universal_time();
// the string is the filename of the .torrent file, but only if // the string is the filename of the .torrent file, but only if
// it was added through the directory monitor. It is used to // it was added through the directory monitor. It is used to
@ -777,7 +776,7 @@ int main(int ac, char* av[])
// loop through the alert queue to see if anything has happened. // loop through the alert queue to see if anything has happened.
std::auto_ptr<alert> a; std::auto_ptr<alert> a;
a = ses.pop_alert(); a = ses.pop_alert();
std::string now = to_simple_string(second_clock::local_time()); std::string now = to_simple_string(boost::posix_time::second_clock::local_time());
while (a.get()) while (a.get())
{ {
std::stringstream event_string; std::stringstream event_string;
@ -999,11 +998,12 @@ int main(int ac, char* av[])
puts(out.str().c_str()); puts(out.str().c_str());
if (!monitor_dir.empty() if (!monitor_dir.empty()
&& next_dir_scan < second_clock::universal_time()) && next_dir_scan < boost::posix_time::second_clock::universal_time())
{ {
scan_dir(monitor_dir, ses, handles, preferred_ratio scan_dir(monitor_dir, ses, handles, preferred_ratio
, compact_allocation_mode, save_path); , compact_allocation_mode, save_path);
next_dir_scan = second_clock::universal_time() + seconds(poll_interval); next_dir_scan = boost::posix_time::second_clock::universal_time()
+ boost::posix_time::seconds(poll_interval);
} }
} }

View File

@ -49,12 +49,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/preprocessor/repetition/enum.hpp> #include <boost/preprocessor/repetition/enum.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp> #include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_shifted_params.hpp> #include <boost/preprocessor/repetition/enum_shifted_params.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
#endif #endif
#include "libtorrent/time.hpp"
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
#define TORRENT_MAX_ALERT_TYPES 10 #define TORRENT_MAX_ALERT_TYPES 10
@ -70,7 +70,7 @@ namespace libtorrent {
virtual ~alert(); virtual ~alert();
// a timestamp is automatically created in the constructor // a timestamp is automatically created in the constructor
boost::posix_time::ptime timestamp() const; ptime timestamp() const;
const std::string& msg() const; const std::string& msg() const;
@ -81,7 +81,7 @@ namespace libtorrent {
private: private:
std::string m_msg; std::string m_msg;
severity_t m_severity; severity_t m_severity;
boost::posix_time::ptime m_timestamp; ptime m_timestamp;
}; };
class TORRENT_EXPORT alert_manager class TORRENT_EXPORT alert_manager

View File

@ -382,7 +382,7 @@ namespace libtorrent
file_pool m_files; file_pool m_files;
void second_tick(asio::error_code const& e); void second_tick(asio::error_code const& e);
boost::posix_time::ptime m_last_tick; ptime m_last_tick;
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
boost::intrusive_ptr<dht::dht_tracker> m_dht; boost::intrusive_ptr<dht::dht_tracker> m_dht;

View File

@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_BANDWIDTH_MANAGER_HPP_INCLUDED #define TORRENT_BANDWIDTH_MANAGER_HPP_INCLUDED
#include "libtorrent/socket.hpp" #include "libtorrent/socket.hpp"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/intrusive_ptr.hpp> #include <boost/intrusive_ptr.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
@ -42,7 +43,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
#include <deque> #include <deque>
namespace pt = boost::posix_time;
using boost::weak_ptr; using boost::weak_ptr;
using boost::shared_ptr; using boost::shared_ptr;
using boost::intrusive_ptr; using boost::intrusive_ptr;
@ -70,8 +70,8 @@ namespace libtorrent
struct history_entry struct history_entry
{ {
history_entry(intrusive_ptr<peer_connection> p, weak_ptr<torrent> t history_entry(intrusive_ptr<peer_connection> p, weak_ptr<torrent> t
, int a, pt::ptime exp); , int a, ptime exp);
pt::ptime expires_at; ptime expires_at;
int amount; int amount;
intrusive_ptr<peer_connection> peer; intrusive_ptr<peer_connection> peer;
weak_ptr<torrent> tor; weak_ptr<torrent> tor;

View File

@ -199,7 +199,7 @@ namespace libtorrent
#ifndef NDEBUG #ifndef NDEBUG
void check_invariant() const; void check_invariant() const;
boost::posix_time::ptime m_last_choke; ptime m_last_choke;
#endif #endif
private: private:

View File

@ -49,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE.
#endif #endif
#include "libtorrent/file.hpp" #include "libtorrent/file.hpp"
#include "libtorrent/time.hpp"
namespace libtorrent namespace libtorrent
{ {
@ -58,7 +59,6 @@ namespace libtorrent
using boost::multi_index::ordered_unique; using boost::multi_index::ordered_unique;
using boost::multi_index::indexed_by; using boost::multi_index::indexed_by;
using boost::multi_index::member; using boost::multi_index::member;
namespace pt = boost::posix_time;
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
struct TORRENT_EXPORT file_pool : boost::noncopyable struct TORRENT_EXPORT file_pool : boost::noncopyable
@ -76,11 +76,11 @@ namespace libtorrent
{ {
lru_file_entry(boost::shared_ptr<file> const& f) lru_file_entry(boost::shared_ptr<file> const& f)
: file_ptr(f) : file_ptr(f)
, last_use(pt::second_clock::universal_time()) {} , last_use(time_now()) {}
mutable boost::shared_ptr<file> file_ptr; mutable boost::shared_ptr<file> file_ptr;
fs::path file_path; fs::path file_path;
void* key; void* key;
pt::ptime last_use; ptime last_use;
file::open_mode mode; file::open_mode mode;
}; };
@ -88,7 +88,7 @@ namespace libtorrent
lru_file_entry, indexed_by< lru_file_entry, indexed_by<
ordered_unique<member<lru_file_entry, fs::path ordered_unique<member<lru_file_entry, fs::path
, &lru_file_entry::file_path> > , &lru_file_entry::file_path> >
, ordered_non_unique<member<lru_file_entry, pt::ptime , ordered_non_unique<member<lru_file_entry, ptime
, &lru_file_entry::last_use> > , &lru_file_entry::last_use> >
, ordered_non_unique<member<lru_file_entry, void* , ordered_non_unique<member<lru_file_entry, void*
, &lru_file_entry::key> > , &lru_file_entry::key> >

View File

@ -44,6 +44,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp" #include "libtorrent/socket.hpp"
#include "libtorrent/http_tracker_connection.hpp" #include "libtorrent/http_tracker_connection.hpp"
#include "libtorrent/time.hpp"
namespace libtorrent namespace libtorrent
{ {
@ -63,7 +64,7 @@ struct http_connection : boost::enable_shared_from_this<http_connection>, boost:
, m_resolver(ios) , m_resolver(ios)
, m_handler(handler) , m_handler(handler)
, m_timer(ios) , m_timer(ios)
, m_last_receive(boost::posix_time::second_clock::universal_time()) , m_last_receive(time_now())
, m_bottled(bottled) , m_bottled(bottled)
, m_called(false) , m_called(false)
, m_rate_limit(0) , m_rate_limit(0)
@ -81,11 +82,10 @@ struct http_connection : boost::enable_shared_from_this<http_connection>, boost:
std::string sendbuffer; std::string sendbuffer;
void get(std::string const& url, boost::posix_time::time_duration timeout void get(std::string const& url, time_duration timeout = seconds(30));
= boost::posix_time::seconds(30));
void start(std::string const& hostname, std::string const& port void start(std::string const& hostname, std::string const& port
, boost::posix_time::time_duration timeout); , time_duration timeout);
void close(); void close();
private: private:
@ -107,8 +107,8 @@ private:
http_parser m_parser; http_parser m_parser;
http_handler m_handler; http_handler m_handler;
deadline_timer m_timer; deadline_timer m_timer;
boost::posix_time::time_duration m_timeout; time_duration m_timeout;
boost::posix_time::ptime m_last_receive; ptime m_last_receive;
// bottled means that the handler is called once, when // bottled means that the handler is called once, when
// everything is received (and buffered in memory). // everything is received (and buffered in memory).
// non bottled means that once the headers have been // non bottled means that once the headers have been

View File

@ -39,8 +39,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <set> #include <set>
#include <numeric> #include <numeric>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/date_time/posix_time/ptime.hpp>
#include <boost/ref.hpp> #include <boost/ref.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
@ -120,7 +118,7 @@ namespace libtorrent { namespace dht
udp::endpoint m_remote_endpoint[2]; udp::endpoint m_remote_endpoint[2];
std::vector<char> m_send_buf; std::vector<char> m_send_buf;
boost::posix_time::ptime m_last_refresh; ptime m_last_refresh;
deadline_timer m_timer; deadline_timer m_timer;
deadline_timer m_connection_timer; deadline_timer m_connection_timer;
deadline_timer m_refresh_timer; deadline_timer m_refresh_timer;

View File

@ -47,11 +47,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/cstdint.hpp> #include <boost/cstdint.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/date_time/posix_time/ptime.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/iterator/transform_iterator.hpp> #include <boost/iterator/transform_iterator.hpp>
#include <boost/ref.hpp> #include <boost/ref.hpp>
#include "libtorrent/socket.hpp"
namespace libtorrent { namespace dht namespace libtorrent { namespace dht
{ {
@ -67,7 +67,7 @@ TORRENT_DECLARE_LOG(node);
struct peer_entry struct peer_entry
{ {
tcp::endpoint addr; tcp::endpoint addr;
boost::posix_time::ptime added; ptime added;
}; };
// this is a group. It contains a set of group members // this is a group. It contains a set of group members
@ -133,8 +133,8 @@ public:
// the returned time is the delay until connection_timeout() // the returned time is the delay until connection_timeout()
// should be called again the next time // should be called again the next time
boost::posix_time::time_duration connection_timeout(); time_duration connection_timeout();
boost::posix_time::time_duration refresh_timeout(); time_duration refresh_timeout();
// generates a new secret number used to generate write tokens // generates a new secret number used to generate write tokens
void new_write_key(); void new_write_key();
@ -172,7 +172,7 @@ private:
rpc_manager m_rpc; rpc_manager m_rpc;
table_t m_map; table_t m_map;
boost::posix_time::ptime m_last_tracker_tick; ptime m_last_tracker_tick;
// secret random numbers used to create write tokens // secret random numbers used to create write tokens
int m_secret[2]; int m_secret[2];

View File

@ -36,7 +36,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <vector> #include <vector>
#include <deque> #include <deque>
#include <boost/cstdint.hpp> #include <boost/cstdint.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/iterator/iterator_facade.hpp> #include <boost/iterator/iterator_facade.hpp>
#include <boost/iterator/iterator_categories.hpp> #include <boost/iterator/iterator_categories.hpp>
@ -51,8 +50,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/kademlia/node_entry.hpp> #include <libtorrent/kademlia/node_entry.hpp>
#include <libtorrent/session_settings.hpp> #include <libtorrent/session_settings.hpp>
namespace pt = boost::posix_time;
namespace libtorrent { namespace dht namespace libtorrent { namespace dht
{ {
@ -177,7 +174,7 @@ public:
// if the given bucket is empty but there are nodes // if the given bucket is empty but there are nodes
// in a bucket closer to us, or if the bucket is non-empty and // in a bucket closer to us, or if the bucket is non-empty and
// the time from the last activity is more than 15 minutes // the time from the last activity is more than 15 minutes
boost::posix_time::ptime next_refresh(int bucket); ptime next_refresh(int bucket);
// fills the vector with the count nodes from our buckets that // fills the vector with the count nodes from our buckets that
// are nearest to the given id. // are nearest to the given id.
@ -226,7 +223,7 @@ private:
typedef boost::array<std::pair<bucket_t, bucket_t>, 160> table_t; typedef boost::array<std::pair<bucket_t, bucket_t>, 160> table_t;
table_t m_buckets; table_t m_buckets;
// timestamps of the last activity in each bucket // timestamps of the last activity in each bucket
typedef boost::array<boost::posix_time::ptime, 160> table_activity_t; typedef boost::array<ptime, 160> table_activity_t;
table_activity_t m_bucket_activity; table_activity_t m_bucket_activity;
node_id m_id; // our own node id node_id m_id; // our own node id

View File

@ -36,7 +36,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <vector> #include <vector>
#include <map> #include <map>
#include <boost/function.hpp> #include <boost/function.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/cstdint.hpp> #include <boost/cstdint.hpp>
@ -49,6 +48,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/kademlia/logging.hpp> #include <libtorrent/kademlia/logging.hpp>
#include <libtorrent/kademlia/node_entry.hpp> #include <libtorrent/kademlia/node_entry.hpp>
#include "libtorrent/time.hpp"
namespace libtorrent { namespace dht namespace libtorrent { namespace dht
{ {
@ -112,8 +113,7 @@ struct msg
struct observer : boost::noncopyable struct observer : boost::noncopyable
{ {
observer() observer(): sent(time_now())
: sent(boost::posix_time::microsec_clock::universal_time())
{} {}
virtual ~observer() {} virtual ~observer() {}
@ -136,7 +136,7 @@ struct observer : boost::noncopyable
virtual void abort() = 0; virtual void abort() = 0;
udp::endpoint target_addr; udp::endpoint target_addr;
boost::posix_time::ptime sent; ptime sent;
}; };
class routing_table; class routing_table;
@ -153,7 +153,7 @@ public:
// returns true if the node needs a refresh // returns true if the node needs a refresh
bool incoming(msg const&); bool incoming(msg const&);
boost::posix_time::time_duration tick(); time_duration tick();
void invoke(int message_id, udp::endpoint target void invoke(int message_id, udp::endpoint target
, boost::shared_ptr<observer> o); , boost::shared_ptr<observer> o);
@ -191,7 +191,7 @@ private:
send_fun m_send; send_fun m_send;
node_id m_our_id; node_id m_our_id;
routing_table& m_table; routing_table& m_table;
boost::posix_time::ptime m_timer; ptime m_timer;
node_id m_random_number; node_id m_random_number;
bool m_destructing; bool m_destructing;
}; };

View File

@ -33,8 +33,8 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_NATPMP_HPP #ifndef TORRENT_NATPMP_HPP
#define TORRENT_NATPMP_HPP #define TORRENT_NATPMP_HPP
#include <libtorrent/socket.hpp> #include "libtorrent/socket.hpp"
#include <boost/date_time/posix_time/ptime.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING) #if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
@ -88,7 +88,7 @@ private:
bool need_update; bool need_update;
// the time the port mapping will expire // the time the port mapping will expire
boost::posix_time::ptime expires; ptime expires;
// the local port for this mapping. If this is set // the local port for this mapping. If this is set
// to 0, the mapping is not in use // to 0, the mapping is not in use

View File

@ -314,7 +314,7 @@ namespace libtorrent
#ifndef NDEBUG #ifndef NDEBUG
void check_invariant() const; void check_invariant() const;
boost::posix_time::ptime m_last_choke; ptime m_last_choke;
#endif #endif
virtual void get_peer_info(peer_info& p) const = 0; virtual void get_peer_info(peer_info& p) const = 0;
@ -452,7 +452,7 @@ namespace libtorrent
// the time when we last got a part of a // the time when we last got a part of a
// piece packet from this peer // piece packet from this peer
boost::posix_time::ptime m_last_piece; ptime m_last_piece;
int m_packet_size; int m_packet_size;
int m_recv_pos; int m_recv_pos;
@ -479,8 +479,8 @@ namespace libtorrent
int m_write_pos; int m_write_pos;
// timeouts // timeouts
boost::posix_time::ptime m_last_receive; ptime m_last_receive;
boost::posix_time::ptime m_last_sent; ptime m_last_sent;
boost::shared_ptr<stream_socket> m_socket; boost::shared_ptr<stream_socket> m_socket;
// this is the peer we're actually talking to // this is the peer we're actually talking to
@ -588,11 +588,11 @@ namespace libtorrent
// the time when this peer sent us a not_interested message // the time when this peer sent us a not_interested message
// the last time. // the last time.
boost::posix_time::ptime m_became_uninterested; ptime m_became_uninterested;
// the time when we sent a not_interested message to // the time when we sent a not_interested message to
// this peer the last time. // this peer the last time.
boost::posix_time::ptime m_became_uninteresting; ptime m_became_uninteresting;
// this is true until this socket has become // this is true until this socket has become
// writable for the first time (i.e. the // writable for the first time (i.e. the

View File

@ -40,8 +40,6 @@ POSSIBILITY OF SUCH DAMAGE.
#pragma warning(push, 1) #pragma warning(push, 1)
#endif #endif
#include <boost/date_time/posix_time/posix_time.hpp>
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
#endif #endif
@ -52,6 +50,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/size_type.hpp" #include "libtorrent/size_type.hpp"
#include "libtorrent/invariant_check.hpp" #include "libtorrent/invariant_check.hpp"
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
#include "libtorrent/time.hpp"
namespace libtorrent namespace libtorrent
{ {
@ -156,11 +155,11 @@ namespace libtorrent
// the time when this peer was optimistically unchoked // the time when this peer was optimistically unchoked
// the last time. // the last time.
boost::posix_time::ptime last_optimistically_unchoked; ptime last_optimistically_unchoked;
// the time when the peer connected to us // the time when the peer connected to us
// or disconnected if it isn't connected right now // or disconnected if it isn't connected right now
boost::posix_time::ptime connected; ptime connected;
// this is the accumulated amount of // this is the accumulated amount of
// uploaded and downloaded data to this // uploaded and downloaded data to this
@ -222,14 +221,12 @@ namespace libtorrent
{ {
bool operator()(const peer& p) bool operator()(const peer& p)
{ {
using namespace boost::posix_time; ptime not_tried_yet(min_time());
ptime not_tried_yet(boost::gregorian::date(1970,boost::gregorian::Jan,1));
// this timeout has to be customizable! // this timeout has to be customizable!
return p.connection == 0 return p.connection == 0
&& p.connected != not_tried_yet && p.connected != not_tried_yet
&& second_clock::universal_time() - p.connected > minutes(120); && time_now() - p.connected > minutes(120);
} }
}; };
@ -249,7 +246,7 @@ namespace libtorrent
// if there is a connection limit, // if there is a connection limit,
// we disconnect one peer every minute in hope of // we disconnect one peer every minute in hope of
// establishing a connection with a better peer // establishing a connection with a better peer
boost::posix_time::ptime m_last_optimistic_disconnect; ptime m_last_optimistic_disconnect;
}; };
} }

View File

@ -51,12 +51,15 @@ POSSIBILITY OF SUCH DAMAGE.
#include <asio/deadline_timer.hpp> #include <asio/deadline_timer.hpp>
#include <asio/write.hpp> #include <asio/write.hpp>
#include <asio/strand.hpp> #include <asio/strand.hpp>
#include <asio/time_traits.hpp>
#include <asio/basic_deadline_timer.hpp>
#ifdef __OBJC__ #ifdef __OBJC__
#undef Protocol #undef Protocol
#endif #endif
#include "libtorrent/io.hpp" #include "libtorrent/io.hpp"
#include "libtorrent/time.hpp"
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
@ -64,6 +67,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent namespace libtorrent
{ {
/* /*
namespace asio = boost::asio; namespace asio = boost::asio;
@ -91,7 +95,8 @@ namespace libtorrent
typedef asio::io_service io_service; typedef asio::io_service io_service;
using asio::async_write; using asio::async_write;
using asio::deadline_timer;
typedef asio::basic_deadline_timer<libtorrent::ptime> deadline_timer;
namespace detail namespace detail
{ {

303
include/libtorrent/time.hpp Normal file
View File

@ -0,0 +1,303 @@
/*
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
#if (!defined (__MACH__) && !defined (_WIN32)) || defined (TORRENT_USE_BOOST_DATE_TIME)
#include <boost/date_time/posix_time/posix_time.hpp>
namespace libtorrent
{
typedef boost::posix_time::ptime ptime;
typedef boost::posix_time::time_duration time_duration;
inline ptime time_now()
{ 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(); }
}
#else
#include <asio/time_traits.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/cstdint.hpp>
namespace libtorrent
{
// libtorrent time_duration type
struct time_duration
{
time_duration() {}
explicit time_duration(boost::int64_t d) : diff(d) {}
boost::int64_t diff;
};
inline bool is_negative(time_duration dt) { return dt.diff < 0; }
inline bool operator<(time_duration lhs, time_duration rhs)
{ return lhs.diff < rhs.diff; }
inline bool operator>(time_duration lhs, time_duration rhs)
{ return lhs.diff > rhs.diff; }
// libtorrent time type
struct ptime
{
ptime() {}
explicit ptime(boost::int64_t t): time(t) {}
boost::int64_t 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 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); }
ptime time_now();
inline ptime min_time() { return ptime(0); }
inline ptime max_time() { return ptime(std::numeric_limits<boost::int64_t>::max()); }
int total_seconds(time_duration td);
int total_milliseconds(time_duration td);
boost::int64_t total_microseconds(time_duration td);
}
// asio time_traits
namespace asio
{
template<>
struct time_traits<libtorrent::ptime>
{
typedef libtorrent::ptime time_type;
typedef libtorrent::time_duration duration_type;
static time_type now()
{ return time_type(libtorrent::time_now()); }
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)); }
};
}
#if defined(__MACH__)
#include <mach/mach_time.h>
#include <boost/cstdint.hpp>
// high precision timer for darwin intel and ppc
namespace libtorrent
{
namespace aux
{
inline boost::int64_t absolutetime_to_microseconds(boost::int64_t at)
{
static mach_timebase_info_data_t timebase_info = {0,0};
if (timebase_info.denom == 0)
mach_timebase_info(&timebase_info);
// make sure we don't overflow
assert((at >= 0 && at >= at / 1000 * timebase_info.numer / timebase_info.denom)
|| (at < 0 && at < at / 1000 * timebase_info.numer / timebase_info.denom));
return at / 1000 * timebase_info.numer / timebase_info.denom;
}
inline boost::int64_t microseconds_to_absolutetime(boost::int64_t ms)
{
static mach_timebase_info_data_t timebase_info = {0,0};
if (timebase_info.denom == 0)
{
mach_timebase_info(&timebase_info);
assert(timebase_info.numer > 0);
assert(timebase_info.denom > 0);
}
// make sure we don't overflow
assert((ms >= 0 && ms <= ms * timebase_info.denom / timebase_info.numer * 1000)
|| (ms < 0 && ms > ms * timebase_info.denom / timebase_info.numer * 1000));
return ms * timebase_info.denom / timebase_info.numer * 1000;
}
}
inline int total_seconds(time_duration td)
{
return aux::absolutetime_to_microseconds(td.diff)
/ 1000000;
}
inline int total_milliseconds(time_duration td)
{
return aux::absolutetime_to_microseconds(td.diff)
/ 1000;
}
inline boost::int64_t total_microseconds(time_duration td)
{
return aux::absolutetime_to_microseconds(td.diff);
}
inline ptime time_now() { return ptime(mach_absolute_time()); }
inline time_duration microsec(boost::int64_t s)
{
return time_duration(aux::microseconds_to_absolutetime(s));
}
inline time_duration milliseconds(boost::int64_t s)
{
return time_duration(aux::microseconds_to_absolutetime(s * 1000));
}
inline time_duration seconds(boost::int64_t s)
{
return time_duration(aux::microseconds_to_absolutetime(s * 1000000));
}
inline time_duration minutes(boost::int64_t s)
{
return time_duration(aux::microseconds_to_absolutetime(s * 1000000 * 60));
}
inline time_duration hours(boost::int64_t s)
{
return time_duration(aux::microseconds_to_absolutetime(s * 1000000 * 60 * 60));
}
}
#elif defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
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);
return pc * 1000000 / performace_counter_frequency.QuadPart;
}
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);
return ms * performace_counter_frequency.QuadPart / 1000000;
}
}
inline int total_seconds(time_duration td)
{
return aux::performance_counter_to_microseconds(td.diff)
/ 1000000;
}
inline int total_milliseconds(time_duration td)
{
return aux::performance_counter_to_microseconds(td.diff)
/ 1000;
}
inline boost::int64_t total_microseconds(time_duration td)
{
return aux::performance_counter_to_microseconds(td.diff);
}
inline ptime time_now()
{
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));
}
}
#endif
#endif
#endif

View File

@ -299,7 +299,7 @@ namespace libtorrent
// returns the absolute time when the next tracker // returns the absolute time when the next tracker
// announce will take place. // announce will take place.
boost::posix_time::ptime next_announce() const; ptime next_announce() const;
// returns true if it is time for this torrent to make another // returns true if it is time for this torrent to make another
// tracker request // tracker request
@ -307,7 +307,7 @@ namespace libtorrent
// forcefully sets next_announce to the current time // forcefully sets next_announce to the current time
void force_tracker_request(); void force_tracker_request();
void force_tracker_request(boost::posix_time::ptime); void force_tracker_request(ptime);
// sets the username and password that will be sent to // sets the username and password that will be sent to
// the tracker // the tracker
@ -523,7 +523,7 @@ namespace libtorrent
boost::scoped_ptr<piece_manager> m_storage; boost::scoped_ptr<piece_manager> m_storage;
// the time of next tracker request // the time of next tracker request
boost::posix_time::ptime m_next_request; ptime m_next_request;
// ----------------------------- // -----------------------------
// DATA FROM TRACKER RESPONSE // DATA FROM TRACKER RESPONSE
@ -705,20 +705,18 @@ namespace libtorrent
#endif #endif
}; };
inline boost::posix_time::ptime torrent::next_announce() const inline ptime torrent::next_announce() const
{ {
return m_next_request; return m_next_request;
} }
inline void torrent::force_tracker_request() inline void torrent::force_tracker_request()
{ {
using boost::posix_time::second_clock; m_next_request = time_now();
m_next_request = second_clock::universal_time();
} }
inline void torrent::force_tracker_request(boost::posix_time::ptime t) inline void torrent::force_tracker_request(ptime t)
{ {
namespace time = boost::posix_time;
m_next_request = t; m_next_request = t;
} }

View File

@ -49,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_info.hpp" #include "libtorrent/peer_info.hpp"
#include "libtorrent/piece_picker.hpp" #include "libtorrent/piece_picker.hpp"
#include "libtorrent/torrent_info.hpp" #include "libtorrent/torrent_info.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
namespace libtorrent namespace libtorrent
@ -288,7 +289,7 @@ namespace libtorrent
// This overrides the default announce interval, and no // This overrides the default announce interval, and no
// announce will take place until the given time has // announce will take place until the given time has
// timed out. // timed out.
void force_reannounce(boost::posix_time::time_duration) const; void force_reannounce(time_duration) const;
// returns the name of this torrent, in case it doesn't // returns the name of this torrent, in case it doesn't
// have metadata it returns the name assigned to it // have metadata it returns the name assigned to it

View File

@ -57,9 +57,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/size_type.hpp" #include "libtorrent/size_type.hpp"
#include "libtorrent/peer_request.hpp" #include "libtorrent/peer_request.hpp"
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
#include "libtorrent/time.hpp"
namespace libtorrent namespace libtorrent
{ {
namespace pt = boost::posix_time;
namespace gr = boost::gregorian;
struct TORRENT_EXPORT file_entry struct TORRENT_EXPORT file_entry
{ {
@ -154,8 +157,7 @@ namespace libtorrent
return m_piece_hash[index]; return m_piece_hash[index];
} }
boost::optional<boost::posix_time::ptime> boost::optional<pt::ptime> creation_date() const;
creation_date() const;
const std::string& creator() const const std::string& creator() const
{ return m_created_by; } { return m_created_by; }
@ -211,7 +213,7 @@ namespace libtorrent
// if a creation date is found in the torrent file // if a creation date is found in the torrent file
// this will be set to that, otherwise it'll be // this will be set to that, otherwise it'll be
// 1970, Jan 1 // 1970, Jan 1
boost::posix_time::ptime m_creation_date; pt::ptime m_creation_date;
// if a comment is found in the torrent file // if a comment is found in the torrent file
// this will be set to that comment // this will be set to that comment

View File

@ -61,6 +61,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_id.hpp" #include "libtorrent/peer_id.hpp"
#include "libtorrent/peer.hpp" #include "libtorrent/peer.hpp"
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
#include "libtorrent/time.hpp"
namespace libtorrent namespace libtorrent
{ {
@ -177,11 +178,11 @@ namespace libtorrent
asio::strand& m_strand; asio::strand& m_strand;
// used for timeouts // used for timeouts
// this is set when the request has been sent // this is set when the request has been sent
boost::posix_time::ptime m_start_time; ptime m_start_time;
// this is set every time something is received // this is set every time something is received
boost::posix_time::ptime m_read_time; ptime m_read_time;
// the asio async operation // the asio async operation
asio::deadline_timer m_timeout; deadline_timer m_timeout;
int m_completion_timeout; int m_completion_timeout;
int m_read_timeout; int m_read_timeout;

View File

@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp" #include "libtorrent/socket.hpp"
#include "libtorrent/http_connection.hpp" #include "libtorrent/http_connection.hpp"
#include <boost/date_time/posix_time/ptime.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
@ -107,7 +107,7 @@ private:
{} {}
// the time the port mapping will expire // the time the port mapping will expire
boost::posix_time::ptime expires; ptime expires;
bool need_update; bool need_update;

View File

@ -39,7 +39,7 @@ namespace libtorrent {
alert::alert(severity_t severity, const std::string& msg) alert::alert(severity_t severity, const std::string& msg)
: m_msg(msg) : m_msg(msg)
, m_severity(severity) , m_severity(severity)
, m_timestamp(boost::posix_time::second_clock::universal_time()) , m_timestamp(time_now())
{ {
} }
@ -47,7 +47,7 @@ namespace libtorrent {
{ {
} }
boost::posix_time::ptime alert::timestamp() const ptime alert::timestamp() const
{ {
return m_timestamp; return m_timestamp;
} }

View File

@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/invariant_check.hpp" #include "libtorrent/invariant_check.hpp"
#include "libtorrent/bandwidth_manager.hpp" #include "libtorrent/bandwidth_manager.hpp"
#include "libtorrent/peer_connection.hpp" #include "libtorrent/peer_connection.hpp"
#include "libtorrent/time.hpp"
#if defined TORRENT_LOGGING || defined TORRENT_VERBOSE_LOGGING #if defined TORRENT_LOGGING || defined TORRENT_VERBOSE_LOGGING
#include "libtorrent/aux_/session_impl.hpp" #include "libtorrent/aux_/session_impl.hpp"
#endif #endif
@ -43,11 +45,11 @@ namespace libtorrent
{ {
namespace namespace
{ {
const pt::time_duration window_size = pt::seconds(1); const time_duration window_size = seconds(1);
} }
history_entry::history_entry(intrusive_ptr<peer_connection> p history_entry::history_entry(intrusive_ptr<peer_connection> p
, weak_ptr<torrent> t, int a, pt::ptime exp) , weak_ptr<torrent> t, int a, ptime exp)
: expires_at(exp), amount(a), peer(p), tor(t) : expires_at(exp), amount(a), peer(p), tor(t)
{} {}
@ -145,7 +147,7 @@ namespace libtorrent
assert(!m_history.empty()); assert(!m_history.empty());
pt::ptime now(pt::microsec_clock::universal_time()); ptime now(time_now());
while (!m_history.empty() && m_history.back().expires_at <= now) while (!m_history.empty() && m_history.back().expires_at <= now)
{ {
history_entry e = m_history.back(); history_entry e = m_history.back();
@ -182,7 +184,7 @@ namespace libtorrent
// (*m_ses->m_logger) << "hand out bw [" << m_channel << "]\n"; // (*m_ses->m_logger) << "hand out bw [" << m_channel << "]\n";
#endif #endif
pt::ptime now(pt::microsec_clock::universal_time()); ptime now(time_now());
mutex_t::scoped_lock l(m_mutex); mutex_t::scoped_lock l(m_mutex);
int limit = m_limit; int limit = m_limit;

View File

@ -167,7 +167,7 @@ namespace libtorrent
INVARIANT_CHECK; INVARIANT_CHECK;
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " ==> DHT_PORT [ " << listen_port << " ]\n"; << " ==> DHT_PORT [ " << listen_port << " ]\n";
#endif #endif
buffer::interval packet = allocate_send_buffer(7); buffer::interval packet = allocate_send_buffer(7);
@ -302,7 +302,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " ==> HANDSHAKE\n"; << " ==> HANDSHAKE\n";
#endif #endif
setup_send(); setup_send();
@ -353,7 +353,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== KEEPALIVE\n"; << " <== KEEPALIVE\n";
#endif #endif
incoming_keepalive(); incoming_keepalive();
@ -826,7 +826,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " ==> BITFIELD "; << " ==> BITFIELD ";
for (int i = 0; i < (int)get_bitfield().size(); ++i) for (int i = 0; i < (int)get_bitfield().size(); ++i)
@ -863,7 +863,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " ==> EXTENSIONS\n"; << " ==> EXTENSIONS\n";
#endif #endif
assert(m_supports_extensions); assert(m_supports_extensions);

View File

@ -51,7 +51,7 @@ namespace libtorrent
if (i != pt.end()) if (i != pt.end())
{ {
lru_file_entry e = *i; lru_file_entry e = *i;
e.last_use = pt::second_clock::universal_time(); e.last_use = time_now();
// if you hit this assert, you probably have more than one // if you hit this assert, you probably have more than one
// storage/torrent using the same file at the same time! // storage/torrent using the same file at the same time!

View File

@ -30,19 +30,17 @@ POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "http_connection.hpp" #include "libtorrent/http_connection.hpp"
#include <boost/date_time/posix_time/posix_time_duration.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <asio/ip/tcp.hpp> #include <asio/ip/tcp.hpp>
using boost::posix_time::second_clock;
using boost::posix_time::millisec;
using boost::bind; using boost::bind;
namespace libtorrent namespace libtorrent
{ {
void http_connection::get(std::string const& url, boost::posix_time::time_duration timeout) void http_connection::get(std::string const& url, time_duration timeout)
{ {
std::string protocol; std::string protocol;
std::string hostname; std::string hostname;
@ -59,7 +57,7 @@ void http_connection::get(std::string const& url, boost::posix_time::time_durati
} }
void http_connection::start(std::string const& hostname, std::string const& port void http_connection::start(std::string const& hostname, std::string const& port
, boost::posix_time::time_duration timeout) , time_duration timeout)
{ {
m_timeout = timeout; m_timeout = timeout;
m_timer.expires_from_now(m_timeout); m_timer.expires_from_now(m_timeout);
@ -91,7 +89,7 @@ void http_connection::on_timeout(boost::weak_ptr<http_connection> p
if (!c) return; if (!c) return;
if (c->m_bottled && c->m_called) return; if (c->m_bottled && c->m_called) return;
if (c->m_last_receive + c->m_timeout < second_clock::universal_time()) if (c->m_last_receive + c->m_timeout < time_now())
{ {
c->m_called = true; c->m_called = true;
c->m_handler(asio::error::timed_out, c->m_parser, 0, 0); c->m_handler(asio::error::timed_out, c->m_parser, 0, 0);
@ -131,7 +129,7 @@ void http_connection::on_connect(asio::error_code const& e
{ {
if (!e) if (!e)
{ {
m_last_receive = second_clock::universal_time(); m_last_receive = time_now();
asio::async_write(m_sock, asio::buffer(sendbuffer) asio::async_write(m_sock, asio::buffer(sendbuffer)
, bind(&http_connection::on_write, shared_from_this(), _1)); , bind(&http_connection::on_write, shared_from_this(), _1));
} }
@ -223,7 +221,7 @@ void http_connection::on_read(asio::error_code const& e
m_handler(e, m_parser, &m_recvbuffer[0] + m_parser.body_start() m_handler(e, m_parser, &m_recvbuffer[0] + m_parser.body_start()
, m_read_pos - m_parser.body_start()); , m_read_pos - m_parser.body_start());
m_read_pos = 0; m_read_pos = 0;
m_last_receive = second_clock::universal_time(); m_last_receive = time_now();
} }
else if (m_bottled && m_parser.finished()) else if (m_bottled && m_parser.finished())
{ {
@ -238,7 +236,7 @@ void http_connection::on_read(asio::error_code const& e
assert(!m_bottled); assert(!m_bottled);
m_handler(e, m_parser, &m_recvbuffer[0], m_read_pos); m_handler(e, m_parser, &m_recvbuffer[0], m_read_pos);
m_read_pos = 0; m_read_pos = 0;
m_last_receive = second_clock::universal_time(); m_last_receive = time_now();
} }
if (int(m_recvbuffer.size()) == m_read_pos) if (int(m_recvbuffer.size()) == m_read_pos)
@ -287,7 +285,7 @@ void http_connection::on_assign_bandwidth(asio::error_code const& e)
, shared_from_this(), _1, _2)); , shared_from_this(), _1, _2));
m_limiter_timer_active = true; m_limiter_timer_active = true;
m_limiter_timer.expires_from_now(millisec(250)); m_limiter_timer.expires_from_now(milliseconds(250));
m_limiter_timer.async_wait(bind(&http_connection::on_assign_bandwidth m_limiter_timer.async_wait(bind(&http_connection::on_assign_bandwidth
, shared_from_this(), _1)); , shared_from_this(), _1));
} }
@ -297,7 +295,7 @@ void http_connection::rate_limit(int limit)
if (!m_limiter_timer_active) if (!m_limiter_timer_active)
{ {
m_limiter_timer_active = true; m_limiter_timer_active = true;
m_limiter_timer.expires_from_now(millisec(250)); m_limiter_timer.expires_from_now(milliseconds(250));
m_limiter_timer.async_wait(bind(&http_connection::on_assign_bandwidth m_limiter_timer.async_wait(bind(&http_connection::on_assign_bandwidth
, shared_from_this(), _1)); , shared_from_this(), _1));
} }

View File

@ -37,8 +37,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <numeric> #include <numeric>
#include <stdexcept> #include <stdexcept>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/date_time/posix_time/ptime.hpp>
#include <boost/ref.hpp> #include <boost/ref.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
@ -54,14 +52,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/io.hpp" #include "libtorrent/io.hpp"
#include "libtorrent/version.hpp" #include "libtorrent/version.hpp"
using boost::posix_time::ptime;
using boost::posix_time::time_duration;
using boost::posix_time::second_clock;
using boost::posix_time::microsec_clock;
using boost::posix_time::seconds;
using boost::posix_time::minutes;
using boost::posix_time::hours;
using boost::posix_time::milliseconds;
using boost::ref; using boost::ref;
using boost::lexical_cast; using boost::lexical_cast;
using libtorrent::dht::node_impl; using libtorrent::dht::node_impl;
@ -157,7 +147,7 @@ namespace libtorrent { namespace dht
, m_dht(bind(&dht_tracker::send_packet, this, _1), settings , m_dht(bind(&dht_tracker::send_packet, this, _1), settings
, read_id(bootstrap)) , read_id(bootstrap))
, m_buffer(0) , m_buffer(0)
, m_last_refresh(second_clock::universal_time() - hours(1)) , m_last_refresh(time_now() - hours(1))
, m_timer(ios) , m_timer(ios)
, m_connection_timer(ios) , m_connection_timer(ios)
, m_refresh_timer(ios) , m_refresh_timer(ios)
@ -307,6 +297,7 @@ namespace libtorrent { namespace dht
{ {
first = false; first = false;
using boost::posix_time::to_simple_string; using boost::posix_time::to_simple_string;
using boost::posix_time::second_clock;
pc << "\n\n ***** starting log at " << to_simple_string( pc << "\n\n ***** starting log at " << to_simple_string(
second_clock::universal_time()) << " *****\n\n" second_clock::universal_time()) << " *****\n\n"
<< "minute:active nodes:passive nodes" << "minute:active nodes:passive nodes"

View File

@ -52,11 +52,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/kademlia/find_data.hpp" #include "libtorrent/kademlia/find_data.hpp"
using boost::bind; using boost::bind;
using boost::posix_time::second_clock;
using boost::posix_time::seconds;
using boost::posix_time::minutes;
using boost::posix_time::ptime;
using boost::posix_time::time_duration;
namespace libtorrent { namespace dht namespace libtorrent { namespace dht
{ {
@ -101,7 +96,7 @@ void purge_peers(std::set<peer_entry>& peers)
, end(peers.end()); i != end;) , end(peers.end()); i != end;)
{ {
// the peer has timed out // the peer has timed out
if (i->added + minutes(int(announce_interval * 1.5f)) < second_clock::universal_time()) if (i->added + minutes(int(announce_interval * 1.5f)) < time_now())
{ {
#ifdef TORRENT_DHT_VERBOSE_LOGGING #ifdef TORRENT_DHT_VERBOSE_LOGGING
TORRENT_LOG(node) << "peer timed out at: " << i->addr.address(); TORRENT_LOG(node) << "peer timed out at: " << i->addr.address();
@ -122,7 +117,7 @@ node_impl::node_impl(boost::function<void(msg const&)> const& f
, m_table(m_id, 8, settings) , m_table(m_id, 8, settings)
, m_rpc(bind(&node_impl::incoming_request, this, _1) , m_rpc(bind(&node_impl::incoming_request, this, _1)
, m_id, m_table, f) , m_id, m_table, f)
, m_last_tracker_tick(boost::posix_time::second_clock::universal_time()) , m_last_tracker_tick(time_now())
{ {
m_secret[0] = std::rand(); m_secret[0] = std::rand();
m_secret[1] = std::rand(); m_secret[1] = std::rand();
@ -379,7 +374,7 @@ void node_impl::announce(sha1_hash const& info_hash, int listen_port
time_duration node_impl::refresh_timeout() time_duration node_impl::refresh_timeout()
{ {
int refresh = -1; int refresh = -1;
ptime now = second_clock::universal_time(); ptime now = time_now();
ptime next = now + minutes(15); ptime next = now + minutes(15);
try try
{ {
@ -414,7 +409,7 @@ time_duration node_impl::connection_timeout()
time_duration d = m_rpc.tick(); time_duration d = m_rpc.tick();
try try
{ {
ptime now(second_clock::universal_time()); ptime now(time_now());
if (now - m_last_tracker_tick < minutes(10)) return d; if (now - m_last_tracker_tick < minutes(10)) return d;
m_last_tracker_tick = now; m_last_tracker_tick = now;
@ -457,7 +452,7 @@ void node_impl::on_announce(msg const& m, msg& reply)
torrent_entry& v = m_map[m.info_hash]; torrent_entry& v = m_map[m.info_hash];
peer_entry e; peer_entry e;
e.addr = tcp::endpoint(m.addr.address(), m.addr.port()); e.addr = tcp::endpoint(m.addr.address(), m.addr.port());
e.added = second_clock::universal_time(); e.added = time_now();
std::set<peer_entry>::iterator i = v.peers.find(e); std::set<peer_entry>::iterator i = v.peers.find(e);
if (i != v.peers.end()) v.peers.erase(i++); if (i != v.peers.end()) v.peers.erase(i++);
v.peers.insert(i, e); v.peers.insert(i, e);

View File

@ -39,7 +39,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <numeric> #include <numeric>
#include <boost/cstdint.hpp> #include <boost/cstdint.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "libtorrent/kademlia/routing_table.hpp" #include "libtorrent/kademlia/routing_table.hpp"
#include "libtorrent/kademlia/node_id.hpp" #include "libtorrent/kademlia/node_id.hpp"
@ -48,13 +47,6 @@ POSSIBILITY OF SUCH DAMAGE.
using boost::bind; using boost::bind;
using boost::uint8_t; using boost::uint8_t;
using boost::posix_time::second_clock;
using boost::posix_time::minutes;
using boost::posix_time::seconds;
using boost::posix_time::hours;
namespace pt = boost::posix_time;
namespace libtorrent { namespace dht namespace libtorrent { namespace dht
{ {
@ -71,7 +63,7 @@ routing_table::routing_table(node_id const& id, int bucket_size
// distribute the refresh times for the buckets in an // distribute the refresh times for the buckets in an
// attempt do even out the network load // attempt do even out the network load
for (int i = 0; i < 160; ++i) for (int i = 0; i < 160; ++i)
m_bucket_activity[i] = second_clock::universal_time() - seconds(15*60 - i*5); m_bucket_activity[i] = time_now() - seconds(15*60 - i*5);
} }
boost::tuple<int, int> routing_table::size() const boost::tuple<int, int> routing_table::size() const
@ -127,7 +119,6 @@ void routing_table::print_state(std::ostream& os) const
{ {
int bucket_index = int(i - m_buckets.begin()); int bucket_index = int(i - m_buckets.begin());
os << "bucket " << bucket_index << " " os << "bucket " << bucket_index << " "
<< to_simple_string(m_bucket_activity[bucket_index])
<< " " << (bucket_index >= m_lowest_active_bucket?"active":"inactive") << " " << (bucket_index >= m_lowest_active_bucket?"active":"inactive")
<< "\n"; << "\n";
for (bucket_t::const_iterator j = i->first.begin() for (bucket_t::const_iterator j = i->first.begin()
@ -141,17 +132,17 @@ void routing_table::print_state(std::ostream& os) const
void routing_table::touch_bucket(int bucket) void routing_table::touch_bucket(int bucket)
{ {
m_bucket_activity[bucket] = second_clock::universal_time(); m_bucket_activity[bucket] = time_now();
} }
boost::posix_time::ptime routing_table::next_refresh(int bucket) ptime routing_table::next_refresh(int bucket)
{ {
assert(bucket < 160); assert(bucket < 160);
assert(bucket >= 0); assert(bucket >= 0);
// lower than or equal to since a refresh of bucket 0 will // lower than or equal to since a refresh of bucket 0 will
// effectively refresh the lowest active bucket as well // effectively refresh the lowest active bucket as well
if (bucket <= m_lowest_active_bucket && bucket > 0) if (bucket <= m_lowest_active_bucket && bucket > 0)
return second_clock::universal_time() + minutes(15); return time_now() + minutes(15);
return m_bucket_activity[bucket] + minutes(15); return m_bucket_activity[bucket] + minutes(15);
} }
@ -252,7 +243,7 @@ bool routing_table::node_seen(node_id const& id, udp::endpoint addr)
bool ret = need_bootstrap(); bool ret = need_bootstrap();
m_bucket_activity[bucket_index] = second_clock::universal_time(); m_bucket_activity[bucket_index] = time_now();
if (i != b.end()) if (i != b.end())
{ {

View File

@ -31,9 +31,8 @@ POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include "libtorrent/socket.hpp"
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/date_time/posix_time/ptime.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <libtorrent/io.hpp> #include <libtorrent/io.hpp>
@ -45,11 +44,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <fstream> #include <fstream>
using boost::posix_time::ptime;
using boost::posix_time::time_duration;
using boost::posix_time::microsec_clock;
using boost::posix_time::seconds;
using boost::posix_time::milliseconds;
using boost::shared_ptr; using boost::shared_ptr;
using boost::bind; using boost::bind;
@ -72,7 +66,7 @@ rpc_manager::rpc_manager(fun const& f, node_id const& our_id
, m_send(sf) , m_send(sf)
, m_our_id(our_id) , m_our_id(our_id)
, m_table(table) , m_table(table)
, m_timer(boost::posix_time::microsec_clock::universal_time()) , m_timer(time_now())
, m_random_number(generate_id()) , m_random_number(generate_id())
, m_destructing(false) , m_destructing(false)
{ {
@ -201,8 +195,6 @@ time_duration rpc_manager::tick()
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
using boost::posix_time::microsec_clock;
const int timeout_ms = 10 * 1000; const int timeout_ms = 10 * 1000;
// look for observers that has timed out // look for observers that has timed out
@ -220,8 +212,7 @@ time_duration rpc_manager::tick()
boost::shared_ptr<observer> o = m_transactions[m_oldest_transaction_id]; boost::shared_ptr<observer> o = m_transactions[m_oldest_transaction_id];
if (!o) continue; if (!o) continue;
time_duration diff = o->sent + milliseconds(timeout_ms) time_duration diff = o->sent + milliseconds(timeout_ms) - time_now();
- microsec_clock::universal_time();
if (diff > seconds(0)) if (diff > seconds(0))
{ {
if (diff < seconds(1)) return seconds(1); if (diff < seconds(1)) return seconds(1);
@ -317,7 +308,7 @@ void rpc_manager::invoke(int message_id, udp::endpoint target_addr
o->send(m); o->send(m);
o->sent = boost::posix_time::microsec_clock::universal_time(); o->sent = time_now();
o->target_addr = target_addr; o->target_addr = target_addr;
#ifdef TORRENT_DHT_VERBOSE_LOGGING #ifdef TORRENT_DHT_VERBOSE_LOGGING
@ -385,7 +376,7 @@ void rpc_manager::reply_with_ping(msg& m, msg const& reply_to)
boost::shared_ptr<observer> o(new dummy_observer); boost::shared_ptr<observer> o(new dummy_observer);
assert(!m_transactions[m_next_transaction_id]); assert(!m_transactions[m_next_transaction_id]);
o->sent = boost::posix_time::microsec_clock::universal_time(); o->sent = time_now();
o->target_addr = m.addr; o->target_addr = m.addr;
m_send(m); m_send(m);

View File

@ -73,7 +73,7 @@ namespace libtorrent { namespace
void log_timestamp() void log_timestamp()
{ {
using namespace boost::posix_time; using namespace boost::posix_time;
std::string now(to_simple_string(second_clock::universal_time())); std::string now(to_simple_string(second_clock::local_time()));
m_file << now << ": "; m_file << now << ": ";
} }

View File

@ -40,7 +40,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/convenience.hpp> #include <boost/filesystem/convenience.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(pop)
@ -58,8 +57,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/extensions.hpp" #include "libtorrent/extensions.hpp"
#include "libtorrent/extensions/metadata_transfer.hpp" #include "libtorrent/extensions/metadata_transfer.hpp"
using boost::posix_time::second_clock;
namespace libtorrent { namespace namespace libtorrent { namespace
{ {
int div_round_up(int numerator, int denominator) int div_round_up(int numerator, int denominator)
@ -245,12 +242,8 @@ namespace libtorrent { namespace
: m_waiting_metadata_request(false) : m_waiting_metadata_request(false)
, m_message_index(0) , m_message_index(0)
, m_metadata_progress(0) , m_metadata_progress(0)
, m_no_metadata( , m_no_metadata(min_time())
boost::gregorian::date(1970, boost::date_time::Jan, 1) , m_metadata_request(min_time())
, boost::posix_time::seconds(0))
, m_metadata_request(
boost::gregorian::date(1970, boost::date_time::Jan, 1)
, boost::posix_time::seconds(0))
, m_torrent(t) , m_torrent(t)
, m_pc(pc) , m_pc(pc)
, m_tp(tp) , m_tp(tp)
@ -413,7 +406,7 @@ namespace libtorrent { namespace
} }
break; break;
case 2: // have no data case 2: // have no data
m_no_metadata = second_clock::universal_time(); m_no_metadata = time_now();
if (m_waiting_metadata_request) if (m_waiting_metadata_request)
m_tp.cancel_metadata_request(m_last_metadata_request); m_tp.cancel_metadata_request(m_last_metadata_request);
m_waiting_metadata_request = false; m_waiting_metadata_request = false;
@ -439,14 +432,13 @@ namespace libtorrent { namespace
m_last_metadata_request = m_tp.metadata_request(); m_last_metadata_request = m_tp.metadata_request();
write_metadata_request(m_last_metadata_request); write_metadata_request(m_last_metadata_request);
m_waiting_metadata_request = true; m_waiting_metadata_request = true;
m_metadata_request = second_clock::universal_time(); m_metadata_request = time_now();
} }
} }
bool has_metadata() const bool has_metadata() const
{ {
using namespace boost::posix_time; return time_now() - m_no_metadata > minutes(5);
return second_clock::universal_time() - m_no_metadata > minutes(5);
} }
private: private:
@ -469,11 +461,11 @@ namespace libtorrent { namespace
// this is set to the current time each time we get a // this is set to the current time each time we get a
// "I don't have metadata" message. // "I don't have metadata" message.
boost::posix_time::ptime m_no_metadata; ptime m_no_metadata;
// this is set to the time when we last sent // this is set to the time when we last sent
// a request for metadata to this peer // a request for metadata to this peer
boost::posix_time::ptime m_metadata_request; ptime m_metadata_request;
// if we're waiting for a metadata request // if we're waiting for a metadata request
// this was the request we sent // this was the request we sent

View File

@ -35,12 +35,13 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/natpmp.hpp> #include <libtorrent/natpmp.hpp>
#include <libtorrent/io.hpp> #include <libtorrent/io.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <asio/ip/host_name.hpp> #include <asio/ip/host_name.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
using boost::posix_time::microsec_clock;
using boost::bind; using boost::bind;
using namespace libtorrent; using namespace libtorrent;
using boost::posix_time::microsec_clock;
enum { num_mappings = 2 }; enum { num_mappings = 2 };
@ -169,7 +170,6 @@ void natpmp::update_mapping(int i, int port)
void natpmp::send_map_request(int i) try void natpmp::send_map_request(int i) try
{ {
using namespace libtorrent::detail; using namespace libtorrent::detail;
using boost::posix_time::milliseconds;
assert(m_currently_mapping == -1 assert(m_currently_mapping == -1
|| m_currently_mapping == i); || m_currently_mapping == i);
@ -205,15 +205,13 @@ catch (std::exception& e)
void natpmp::resend_request(int i, asio::error_code const& e) void natpmp::resend_request(int i, asio::error_code const& e)
{ {
using boost::posix_time::hours;
if (e) return; if (e) return;
if (m_currently_mapping != i) return; if (m_currently_mapping != i) return;
if (m_retry_count >= 9) if (m_retry_count >= 9)
{ {
m_mappings[i].need_update = false; m_mappings[i].need_update = false;
// try again in two hours // try again in two hours
m_mappings[i].expires m_mappings[i].expires = time_now() + hours(2);
= boost::posix_time::second_clock::universal_time() + hours(2);
return; return;
} }
send_map_request(i); send_map_request(i);
@ -223,7 +221,6 @@ void natpmp::on_reply(asio::error_code const& e
, std::size_t bytes_transferred) , std::size_t bytes_transferred)
{ {
using namespace libtorrent::detail; using namespace libtorrent::detail;
using boost::posix_time::seconds;
if (e) return; if (e) return;
try try
@ -289,8 +286,7 @@ void natpmp::on_reply(asio::error_code const& e
} }
else else
{ {
m.expires = boost::posix_time::second_clock::universal_time() m.expires = time_now() + seconds(int(lifetime * 0.7f));
+ seconds(int(lifetime * 0.7f));
m.external_port = public_port; m.external_port = public_port;
} }
@ -324,10 +320,8 @@ void natpmp::on_reply(asio::error_code const& e
} }
catch (std::exception& e) catch (std::exception& e)
{ {
using boost::posix_time::hours;
// try again in two hours // try again in two hours
m_mappings[m_currently_mapping].expires m_mappings[m_currently_mapping].expires = time_now() + hours(2);
= boost::posix_time::second_clock::universal_time() + hours(2);
m_callback(0, 0, e.what()); m_callback(0, 0, e.what());
} }
int i = m_currently_mapping; int i = m_currently_mapping;
@ -340,9 +334,8 @@ void natpmp::on_reply(asio::error_code const& e
void natpmp::update_expiration_timer() void natpmp::update_expiration_timer()
{ {
using boost::posix_time::seconds; ptime now = time_now();
boost::posix_time::ptime now = boost::posix_time::second_clock::universal_time(); ptime min_expire = now + seconds(3600);
boost::posix_time::ptime min_expire = now + seconds(3600);
int min_index = -1; int min_index = -1;
for (int i = 0; i < num_mappings; ++i) for (int i = 0; i < num_mappings; ++i)
if (m_mappings[i].expires < min_expire if (m_mappings[i].expires < min_expire

View File

@ -81,20 +81,19 @@ namespace libtorrent
, tcp::endpoint const& proxy) , tcp::endpoint const& proxy)
: :
#ifndef NDEBUG #ifndef NDEBUG
m_last_choke(boost::posix_time::second_clock::universal_time() m_last_choke(time_now() - hours(1))
- hours(1))
, ,
#endif #endif
m_ses(ses) m_ses(ses)
, m_max_out_request_queue(m_ses.settings().max_out_request_queue) , m_max_out_request_queue(m_ses.settings().max_out_request_queue)
, m_timeout(m_ses.settings().peer_timeout) , m_timeout(m_ses.settings().peer_timeout)
, m_last_piece(second_clock::universal_time()) , m_last_piece(time_now())
, m_packet_size(0) , m_packet_size(0)
, m_recv_pos(0) , m_recv_pos(0)
, m_current_send_buffer(0) , m_current_send_buffer(0)
, m_write_pos(0) , m_write_pos(0)
, m_last_receive(second_clock::universal_time()) , m_last_receive(time_now())
, m_last_sent(second_clock::universal_time()) , m_last_sent(time_now())
, m_socket(s) , m_socket(s)
, m_remote(remote) , m_remote(remote)
, m_remote_proxy(proxy) , m_remote_proxy(proxy)
@ -112,8 +111,8 @@ namespace libtorrent
, m_assume_fifo(false) , m_assume_fifo(false)
, m_num_invalid_requests(0) , m_num_invalid_requests(0)
, m_disconnecting(false) , m_disconnecting(false)
, m_became_uninterested(second_clock::universal_time()) , m_became_uninterested(time_now())
, m_became_uninteresting(second_clock::universal_time()) , m_became_uninteresting(time_now())
, m_connecting(true) , m_connecting(true)
, m_queued(true) , m_queued(true)
, m_writing(false) , m_writing(false)
@ -148,20 +147,19 @@ namespace libtorrent
, boost::shared_ptr<stream_socket> s) , boost::shared_ptr<stream_socket> s)
: :
#ifndef NDEBUG #ifndef NDEBUG
m_last_choke(boost::posix_time::second_clock::universal_time() m_last_choke(time_now() - hours(1))
- hours(1))
, ,
#endif #endif
m_ses(ses) m_ses(ses)
, m_max_out_request_queue(m_ses.settings().max_out_request_queue) , m_max_out_request_queue(m_ses.settings().max_out_request_queue)
, m_timeout(m_ses.settings().peer_timeout) , m_timeout(m_ses.settings().peer_timeout)
, m_last_piece(second_clock::universal_time()) , m_last_piece(time_now())
, m_packet_size(0) , m_packet_size(0)
, m_recv_pos(0) , m_recv_pos(0)
, m_current_send_buffer(0) , m_current_send_buffer(0)
, m_write_pos(0) , m_write_pos(0)
, m_last_receive(second_clock::universal_time()) , m_last_receive(time_now())
, m_last_sent(second_clock::universal_time()) , m_last_sent(time_now())
, m_socket(s) , m_socket(s)
, m_active(false) , m_active(false)
, m_peer_interested(false) , m_peer_interested(false)
@ -176,8 +174,8 @@ namespace libtorrent
, m_assume_fifo(false) , m_assume_fifo(false)
, m_num_invalid_requests(0) , m_num_invalid_requests(0)
, m_disconnecting(false) , m_disconnecting(false)
, m_became_uninterested(second_clock::universal_time()) , m_became_uninterested(time_now())
, m_became_uninteresting(second_clock::universal_time()) , m_became_uninteresting(time_now())
, m_connecting(false) , m_connecting(false)
, m_queued(false) , m_queued(false)
, m_writing(false) , m_writing(false)
@ -297,7 +295,7 @@ namespace libtorrent
using namespace boost::posix_time; using namespace boost::posix_time;
if (m_logger) if (m_logger)
{ {
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " *** CONNECTION CLOSED\n"; << " *** CONNECTION CLOSED\n";
} }
#endif #endif
@ -315,7 +313,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " ==> HAVE [ piece: " << index << "]\n"; << " ==> HAVE [ piece: " << index << "]\n";
#endif #endif
write_have(index); write_have(index);
@ -516,7 +514,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== KEEPALIVE\n"; << " <== KEEPALIVE\n";
#endif #endif
} }
@ -542,7 +540,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== CHOKE\n"; << " <== CHOKE\n";
#endif #endif
m_peer_choked = true; m_peer_choked = true;
@ -592,7 +590,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== UNCHOKE\n"; << " <== UNCHOKE\n";
#endif #endif
m_peer_choked = false; m_peer_choked = false;
@ -620,7 +618,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== INTERESTED\n"; << " <== INTERESTED\n";
#endif #endif
m_peer_interested = true; m_peer_interested = true;
@ -643,7 +641,7 @@ namespace libtorrent
} }
#endif #endif
m_became_uninterested = second_clock::universal_time(); m_became_uninterested = time_now();
// clear the request queue if the client isn't interested // clear the request queue if the client isn't interested
m_requests.clear(); m_requests.clear();
@ -651,7 +649,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== NOT_INTERESTED\n"; << " <== NOT_INTERESTED\n";
#endif #endif
@ -683,7 +681,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== HAVE [ piece: " << index << "]\n"; << " <== HAVE [ piece: " << index << "]\n";
#endif #endif
@ -750,7 +748,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== BITFIELD "; << " <== BITFIELD ";
for (int i = 0; i < int(bitfield.size()); ++i) for (int i = 0; i < int(bitfield.size()); ++i)
@ -846,7 +844,7 @@ namespace libtorrent
// we shouldn't get a request // we shouldn't get a request
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== UNEXPECTED_REQUEST [ " << " <== UNEXPECTED_REQUEST [ "
"piece: " << r.piece << " | " "piece: " << r.piece << " | "
"s: " << r.start << " | " "s: " << r.start << " | "
@ -866,7 +864,7 @@ namespace libtorrent
// is making too many of them. // is making too many of them.
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== TOO MANY REQUESTS [ " << " <== TOO MANY REQUESTS [ "
"piece: " << r.piece << " | " "piece: " << r.piece << " | "
"s: " << r.start << " | " "s: " << r.start << " | "
@ -892,7 +890,7 @@ namespace libtorrent
{ {
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== REQUEST [ piece: " << r.piece << " | s: " << r.start << " | l: " << r.length << " ]\n"; << " <== REQUEST [ piece: " << r.piece << " | s: " << r.start << " | l: " << r.length << " ]\n";
#endif #endif
// if we have choked the client // if we have choked the client
@ -907,7 +905,7 @@ namespace libtorrent
{ {
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== INVALID_REQUEST [ " << " <== INVALID_REQUEST [ "
"piece: " << r.piece << " | " "piece: " << r.piece << " | "
"s: " << r.start << " | " "s: " << r.start << " | "
@ -934,7 +932,7 @@ namespace libtorrent
void peer_connection::incoming_piece_fragment() void peer_connection::incoming_piece_fragment()
{ {
m_last_piece = second_clock::universal_time(); m_last_piece = time_now();
} }
#ifndef NDEBUG #ifndef NDEBUG
@ -993,7 +991,7 @@ namespace libtorrent
#endif #endif
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== PIECE [ piece: " << p.piece << " | " << " <== PIECE [ piece: " << p.piece << " | "
"s: " << p.start << " | " "s: " << p.start << " | "
"l: " << p.length << " | " "l: " << p.length << " | "
@ -1005,7 +1003,7 @@ namespace libtorrent
{ {
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== INVALID_PIECE [ piece: " << p.piece << " | " << " <== INVALID_PIECE [ piece: " << p.piece << " | "
"start: " << p.start << " | " "start: " << p.start << " | "
"length: " << p.length << " ]\n"; "length: " << p.length << " ]\n";
@ -1051,7 +1049,7 @@ namespace libtorrent
i != b; ++i) i != b; ++i)
{ {
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " *** SKIPPED_PIECE [ piece: " << i->piece_index << " | " << " *** SKIPPED_PIECE [ piece: " << i->piece_index << " | "
"b: " << i->block_index << " ] ***\n"; "b: " << i->block_index << " ] ***\n";
#endif #endif
@ -1248,7 +1246,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== CANCEL [ piece: " << r.piece << " | s: " << r.start << " | l: " << r.length << " ]\n"; << " <== CANCEL [ piece: " << r.piece << " | s: " << r.start << " | l: " << r.length << " ]\n";
#endif #endif
@ -1263,7 +1261,7 @@ namespace libtorrent
{ {
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " *** GOT CANCEL NOT IN THE QUEUE\n"; << " *** GOT CANCEL NOT IN THE QUEUE\n";
#endif #endif
} }
@ -1279,7 +1277,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " <== DHT_PORT [ p: " << listen_port << " ]\n"; << " <== DHT_PORT [ p: " << listen_port << " ]\n";
#endif #endif
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
@ -1356,7 +1354,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " ==> CANCEL [ piece: " << block.piece_index << " | s: " << " ==> CANCEL [ piece: " << block.piece_index << " | s: "
<< block_offset << " | l: " << block_size << " | " << block.block_index << " ]\n"; << block_offset << " | l: " << block_size << " | " << block.block_index << " ]\n";
#endif #endif
@ -1372,12 +1370,12 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " ==> CHOKE\n"; << " ==> CHOKE\n";
#endif #endif
#ifndef NDEBUG #ifndef NDEBUG
using namespace boost::posix_time; using namespace boost::posix_time;
m_last_choke = second_clock::universal_time(); m_last_choke = time_now();
#endif #endif
m_num_invalid_requests = 0; m_num_invalid_requests = 0;
m_requests.clear(); m_requests.clear();
@ -1393,7 +1391,7 @@ namespace libtorrent
// this condition cannot be guaranteed since if peers disconnect // this condition cannot be guaranteed since if peers disconnect
// a new one will be unchoked ignoring when it was last choked // a new one will be unchoked ignoring when it was last choked
using namespace boost::posix_time; using namespace boost::posix_time;
//assert(second_clock::universal_time() - m_last_choke > seconds(9)); //assert(time_now() - m_last_choke > seconds(9));
#endif #endif
if (!m_choked) return; if (!m_choked) return;
@ -1402,7 +1400,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " ==> UNCHOKE\n"; << " ==> UNCHOKE\n";
#endif #endif
} }
@ -1417,7 +1415,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " ==> INTERESTED\n"; << " ==> INTERESTED\n";
#endif #endif
} }
@ -1430,11 +1428,11 @@ namespace libtorrent
write_not_interested(); write_not_interested();
m_interesting = false; m_interesting = false;
m_became_uninteresting = second_clock::universal_time(); m_became_uninteresting = time_now();
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " ==> NOT_INTERESTED\n"; << " ==> NOT_INTERESTED\n";
#endif #endif
} }
@ -1472,7 +1470,7 @@ namespace libtorrent
m_download_queue.push_back(block); m_download_queue.push_back(block);
/* /*
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " *** REQUEST-QUEUE** [ " << " *** REQUEST-QUEUE** [ "
"piece: " << block.piece_index << " | " "piece: " << block.piece_index << " | "
"block: " << block.block_index << " ]\n"; "block: " << block.block_index << " ]\n";
@ -1491,7 +1489,7 @@ namespace libtorrent
m_download_queue.push_back(block); m_download_queue.push_back(block);
/* /*
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " *** REQUEST-QUEUE** [ " << " *** REQUEST-QUEUE** [ "
"piece: " << block.piece_index << " | " "piece: " << block.piece_index << " | "
"block: " << block.block_index << " ]\n"; "block: " << block.block_index << " ]\n";
@ -1524,7 +1522,7 @@ namespace libtorrent
using namespace boost::posix_time; using namespace boost::posix_time;
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " ==> REQUEST [ " << " ==> REQUEST [ "
"piece: " << r.piece << " | " "piece: " << r.piece << " | "
"s: " << r.start << " | " "s: " << r.start << " | "
@ -1533,7 +1531,7 @@ namespace libtorrent
"qs: " << m_desired_queue_size << " ]\n"; "qs: " << m_desired_queue_size << " ]\n";
#endif #endif
} }
m_last_piece = second_clock::universal_time(); m_last_piece = time_now();
} }
@ -1642,7 +1640,7 @@ namespace libtorrent
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
ptime now(second_clock::universal_time()); ptime now(time_now());
boost::shared_ptr<torrent> t = m_torrent.lock(); boost::shared_ptr<torrent> t = m_torrent.lock();
assert(t); assert(t);
@ -1688,9 +1686,9 @@ namespace libtorrent
// in this case we'll clear our download queue and // in this case we'll clear our download queue and
// re-request the blocks. // re-request the blocks.
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << to_simple_string(now) (*m_logger) << to_simple_string(second_clock::local_time())
<< " *** PIECE_REQUESTS TIMED OUT [ " << (int)m_download_queue.size() << " *** PIECE_REQUESTS TIMED OUT [ " << (int)m_download_queue.size()
<< " " << to_simple_string(now - m_last_piece) << "] ***\n"; << " " << total_seconds(now - m_last_piece) << "] ***\n";
#endif #endif
if (t->is_seed()) if (t->is_seed())
@ -1829,7 +1827,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< " ==> PIECE [ piece: " << r.piece << " | s: " << r.start << " ==> PIECE [ piece: " << r.piece << " | s: " << r.start
<< " | l: " << r.length << " ]\n"; << " | l: " << r.length << " ]\n";
#endif #endif
@ -2070,7 +2068,7 @@ namespace libtorrent
assert(m_packet_size > 0); assert(m_packet_size > 0);
assert(bytes_transferred > 0); assert(bytes_transferred > 0);
m_last_receive = second_clock::universal_time(); m_last_receive = time_now();
m_recv_pos += bytes_transferred; m_recv_pos += bytes_transferred;
assert(m_recv_pos <= int(m_recv_buffer.size())); assert(m_recv_pos <= int(m_recv_buffer.size()));
@ -2185,7 +2183,7 @@ namespace libtorrent
} }
if (m_disconnecting) return; if (m_disconnecting) return;
m_last_receive = second_clock::universal_time(); m_last_receive = time_now();
// this means the connection just succeeded // this means the connection just succeeded
@ -2251,7 +2249,7 @@ namespace libtorrent
m_write_pos = 0; m_write_pos = 0;
} }
m_last_sent = second_clock::universal_time(); m_last_sent = time_now();
on_sent(error, bytes_transferred); on_sent(error, bytes_transferred);
fill_send_buffer(); fill_send_buffer();
@ -2352,7 +2350,7 @@ namespace libtorrent
using namespace boost::posix_time; using namespace boost::posix_time;
ptime now(second_clock::universal_time()); ptime now(time_now());
// if the socket is still connecting, don't // if the socket is still connecting, don't
// consider it timed out. Because Windows XP SP2 // consider it timed out. Because Windows XP SP2
@ -2362,7 +2360,7 @@ namespace libtorrent
// if the peer hasn't said a thing for a certain // if the peer hasn't said a thing for a certain
// time, it is considered to have timed out // time, it is considered to have timed out
time_duration d; time_duration d;
d = second_clock::universal_time() - m_last_receive; d = time_now() - m_last_receive;
if (d > seconds(m_timeout)) return true; if (d > seconds(m_timeout)) return true;
// if the peer hasn't become interested and we haven't // if the peer hasn't become interested and we haven't
@ -2389,9 +2387,9 @@ namespace libtorrent
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
boost::posix_time::time_duration d; time_duration d;
d = second_clock::universal_time() - m_last_sent; d = time_now() - m_last_sent;
if (d.total_seconds() < m_timeout / 2) return; if (total_seconds(d) < m_timeout / 2) return;
if (m_connecting) return; if (m_connecting) return;

View File

@ -38,7 +38,6 @@ POSSIBILITY OF SUCH DAMAGE.
#pragma warning(push, 1) #pragma warning(push, 1)
#endif #endif
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#ifdef _MSC_VER #ifdef _MSC_VER
@ -52,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp" #include "libtorrent/socket.hpp"
#include "libtorrent/alert_types.hpp" #include "libtorrent/alert_types.hpp"
#include "libtorrent/invariant_check.hpp" #include "libtorrent/invariant_check.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/aux_/session_impl.hpp" #include "libtorrent/aux_/session_impl.hpp"
namespace libtorrent namespace libtorrent
@ -59,7 +59,6 @@ namespace libtorrent
class peer_connection; class peer_connection;
} }
using namespace boost::posix_time;
using boost::bind; using boost::bind;
namespace namespace
@ -376,7 +375,7 @@ namespace libtorrent
: m_torrent(t) : m_torrent(t)
, m_num_unchoked(0) , m_num_unchoked(0)
, m_available_free_upload(0) , m_available_free_upload(0)
, m_last_optimistic_disconnect(boost::gregorian::date(1970,boost::gregorian::Jan,1)) , m_last_optimistic_disconnect(min_time())
{ assert(t); } { assert(t); }
// finds the peer that has the worst download rate // finds the peer that has the worst download rate
// and returns it. May return 0 if all peers are // and returns it. May return 0 if all peers are
@ -435,11 +434,8 @@ namespace libtorrent
if (m_num_unchoked == m_torrent->num_peers()) if (m_num_unchoked == m_torrent->num_peers())
return 0; return 0;
using namespace boost::posix_time;
using namespace boost::gregorian;
peer* unchoke_peer = 0; peer* unchoke_peer = 0;
ptime min_time(date(9999,Jan,1)); ptime min_time = libtorrent::min_time();
float max_down_speed = 0.f; float max_down_speed = 0.f;
// TODO: make this selection better // TODO: make this selection better
@ -468,8 +464,7 @@ namespace libtorrent
peer *disconnect_peer = 0; peer *disconnect_peer = 0;
double slowest_transfer_rate = std::numeric_limits<double>::max(); double slowest_transfer_rate = std::numeric_limits<double>::max();
boost::posix_time::ptime local_time ptime local_time = time_now();
= second_clock::universal_time();
for (std::vector<peer>::iterator i = m_peers.begin(); for (std::vector<peer>::iterator i = m_peers.begin();
i != m_peers.end(); ++i) i != m_peers.end(); ++i)
@ -483,13 +478,11 @@ namespace libtorrent
double transferred_amount double transferred_amount
= (double)c->statistics().total_payload_download(); = (double)c->statistics().total_payload_download();
boost::posix_time::time_duration connected_time time_duration connected_time
= local_time - i->connected; = local_time - i->connected;
double connected_time_in_seconds double connected_time_in_seconds
= connected_time.seconds() = total_seconds(connected_time);
+ connected_time.minutes()*60.0
+ connected_time.hours()*60.0*60.0;
double transfer_rate double transfer_rate
= transferred_amount / (connected_time_in_seconds+1); = transferred_amount / (connected_time_in_seconds+1);
@ -505,8 +498,8 @@ namespace libtorrent
policy::peer *policy::find_connect_candidate() policy::peer *policy::find_connect_candidate()
{ {
boost::posix_time::ptime local_time = second_clock::universal_time(); ptime now = time_now();
boost::posix_time::ptime ptime(local_time); ptime ptime(now);
policy::peer* candidate = 0; policy::peer* candidate = 0;
for (std::vector<peer>::iterator i = m_peers.begin(); for (std::vector<peer>::iterator i = m_peers.begin();
@ -517,9 +510,9 @@ namespace libtorrent
if (i->type == peer::not_connectable) continue; if (i->type == peer::not_connectable) continue;
if (i->seed && m_torrent->is_seed()) continue; if (i->seed && m_torrent->is_seed()) continue;
assert(i->connected <= local_time); assert(i->connected <= now);
boost::posix_time::ptime next_connect = i->connected; libtorrent::ptime next_connect = i->connected;
if (next_connect <= ptime) if (next_connect <= ptime)
{ {
@ -528,7 +521,7 @@ namespace libtorrent
} }
} }
assert(ptime <= local_time); assert(ptime <= now);
return candidate; return candidate;
} }
@ -541,13 +534,10 @@ namespace libtorrent
// first choice candidate. // first choice candidate.
// it is a candidate we owe nothing to and which has been unchoked // it is a candidate we owe nothing to and which has been unchoked
// the longest. // the longest.
using namespace boost::posix_time;
using namespace boost::gregorian;
peer* candidate = 0; peer* candidate = 0;
// not valid when candidate == 0 // not valid when candidate == 0
ptime last_unchoke = ptime(date(1970, Jan, 1)); ptime last_unchoke = min_time();
// second choice candidate. // second choice candidate.
// if there is no first choice candidate, this candidate will be chosen. // if there is no first choice candidate, this candidate will be chosen.
@ -596,8 +586,7 @@ namespace libtorrent
INVARIANT_CHECK; INVARIANT_CHECK;
peer* candidate = 0; peer* candidate = 0;
boost::posix_time::ptime last_unchoke ptime last_unchoke = time_now();
= second_clock::universal_time();
for (std::vector<peer>::iterator i = m_peers.begin(); for (std::vector<peer>::iterator i = m_peers.begin();
i != m_peers.end(); ++i) i != m_peers.end(); ++i)
@ -623,8 +612,7 @@ namespace libtorrent
{ {
assert(p->connection->is_choked()); assert(p->connection->is_choked());
p->connection->send_unchoke(); p->connection->send_unchoke();
p->last_optimistically_unchoked p->last_optimistically_unchoked = time_now();
= second_clock::universal_time();
++m_num_unchoked; ++m_num_unchoked;
} }
return p != 0; return p != 0;
@ -649,8 +637,6 @@ namespace libtorrent
if (m_torrent->is_paused()) return; if (m_torrent->is_paused()) return;
using namespace boost::posix_time;
// remove old disconnected peers from the list // remove old disconnected peers from the list
m_peers.erase( m_peers.erase(
std::remove_if(m_peers.begin() std::remove_if(m_peers.begin()
@ -682,8 +668,8 @@ namespace libtorrent
{ {
// every minute, disconnect the worst peer in hope of finding a better peer // every minute, disconnect the worst peer in hope of finding a better peer
boost::posix_time::ptime local_time = second_clock::universal_time(); ptime local_time = time_now();
if (m_last_optimistic_disconnect + boost::posix_time::seconds(120) <= local_time if (m_last_optimistic_disconnect + seconds(120) <= local_time
&& find_connect_candidate()) && find_connect_candidate())
{ {
m_last_optimistic_disconnect = local_time; m_last_optimistic_disconnect = local_time;
@ -693,7 +679,7 @@ namespace libtorrent
else else
{ {
// don't do a disconnect earlier than 1 minute after some peer was connected // don't do a disconnect earlier than 1 minute after some peer was connected
m_last_optimistic_disconnect = second_clock::universal_time(); m_last_optimistic_disconnect = time_now();
} }
while (num_connected_peers > max_connections) while (num_connected_peers > max_connections)
@ -968,9 +954,6 @@ namespace libtorrent
} }
else else
{ {
using namespace boost::posix_time;
using namespace boost::gregorian;
// we don't have ny info about this peer. // we don't have ny info about this peer.
// add a new entry // add a new entry
assert((c.proxy() == tcp::endpoint() && c.remote() == c.get_socket()->remote_endpoint()) assert((c.proxy() == tcp::endpoint() && c.remote() == c.get_socket()->remote_endpoint())
@ -987,8 +970,8 @@ namespace libtorrent
i->prev_amount_upload = 0; i->prev_amount_upload = 0;
i->connection = &c; i->connection = &c;
assert(i->connection); assert(i->connection);
i->connected = second_clock::universal_time(); i->connected = time_now();
m_last_optimistic_disconnect = second_clock::universal_time(); m_last_optimistic_disconnect = time_now();
} }
void policy::peer_from_tracker(const tcp::endpoint& remote, const peer_id& pid void policy::peer_from_tracker(const tcp::endpoint& remote, const peer_id& pid
@ -1020,9 +1003,6 @@ namespace libtorrent
if (i == m_peers.end()) if (i == m_peers.end())
{ {
using namespace boost::posix_time;
using namespace boost::gregorian;
// we don't have any info about this peer. // we don't have any info about this peer.
// add a new entry // add a new entry
peer p(remote, peer::connectable); peer p(remote, peer::connectable);
@ -1206,7 +1186,7 @@ namespace libtorrent
assert(p->connection->is_choked()); assert(p->connection->is_choked());
p->connection->send_unchoke(); p->connection->send_unchoke();
p->last_optimistically_unchoked = second_clock::universal_time(); p->last_optimistically_unchoked = time_now();
++m_num_unchoked; ++m_num_unchoked;
return true; return true;
} }
@ -1248,7 +1228,7 @@ namespace libtorrent
p->prev_amount_upload = 0; p->prev_amount_upload = 0;
p->connected = p->connected =
m_last_optimistic_disconnect = m_last_optimistic_disconnect =
second_clock::universal_time(); time_now();
return true; return true;
} }
catch (std::exception& e) catch (std::exception& e)
@ -1287,7 +1267,7 @@ namespace libtorrent
if (i == m_peers.end()) return; if (i == m_peers.end()) return;
assert(i->connection == &c); assert(i->connection == &c);
i->connected = second_clock::universal_time(); i->connected = time_now();
if (!i->connection->is_choked() && !m_torrent->is_aborted()) if (!i->connection->is_choked() && !m_torrent->is_aborted())
{ {
unchoked = true; unchoked = true;
@ -1296,7 +1276,7 @@ namespace libtorrent
if (c.failed()) if (c.failed())
{ {
if (++i->failcount > 3) erase = true; if (++i->failcount > 3) erase = true;
i->connected = second_clock::universal_time(); i->connected = time_now();
} }
// if the share ratio is 0 (infinite), the // if the share ratio is 0 (infinite), the
@ -1414,15 +1394,14 @@ namespace libtorrent
, type(t) , type(t)
, failcount(0) , failcount(0)
, seed(false) , seed(false)
, last_optimistically_unchoked( , last_optimistically_unchoked(min_time())
boost::gregorian::date(1970,boost::gregorian::Jan,1)) , connected(min_time())
, connected(boost::gregorian::date(1970,boost::gregorian::Jan,1))
, prev_amount_upload(0) , prev_amount_upload(0)
, prev_amount_download(0) , prev_amount_download(0)
, banned(false) , banned(false)
, connection(0) , connection(0)
{ {
assert(connected < second_clock::universal_time()); assert(connected < time_now());
} }
size_type policy::peer::total_download() const size_type policy::peer::total_download() const

View File

@ -489,7 +489,7 @@ namespace libtorrent { namespace detail
, m_half_open_limit(-1) , m_half_open_limit(-1)
, m_incoming_connection(false) , m_incoming_connection(false)
, m_files(40) , m_files(40)
, m_last_tick(microsec_clock::universal_time()) , m_last_tick(time_now())
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
, m_dht_same_port(true) , m_dht_same_port(true)
, m_external_udp_port(0) , m_external_udp_port(0)
@ -509,7 +509,7 @@ namespace libtorrent { namespace detail
m_logger = create_log("main_session", listen_port(), false); m_logger = create_log("main_session", listen_port(), false);
using boost::posix_time::second_clock; using boost::posix_time::second_clock;
using boost::posix_time::to_simple_string; using boost::posix_time::to_simple_string;
(*m_logger) << to_simple_string(second_clock::universal_time()) << "\n"; (*m_logger) << to_simple_string(second_clock::local_time()) << "\n";
m_stats_logger = create_log("session_stats", listen_port(), false); m_stats_logger = create_log("session_stats", listen_port(), false);
(*m_stats_logger) << (*m_stats_logger) <<
@ -920,9 +920,8 @@ namespace libtorrent { namespace detail
} }
if (m_abort) return; if (m_abort) return;
float tick_interval = (microsec_clock::universal_time() float tick_interval = total_microseconds(time_now() - m_last_tick) / 1000000.f;
- m_last_tick).total_milliseconds() / 1000.f; m_last_tick = time_now();
m_last_tick = microsec_clock::universal_time();
m_timer.expires_from_now(seconds(1)); m_timer.expires_from_now(seconds(1));
m_timer.async_wait(m_strand.wrap( m_timer.async_wait(m_strand.wrap(
@ -1061,7 +1060,7 @@ namespace libtorrent { namespace detail
open_listen_port(); open_listen_port();
} }
boost::posix_time::ptime timer = second_clock::universal_time(); ptime timer = time_now();
do do
{ {
@ -1115,14 +1114,14 @@ namespace libtorrent { namespace detail
} }
} }
ptime start(microsec_clock::universal_time()); ptime start(time_now());
l.unlock(); l.unlock();
while (microsec_clock::universal_time() - start < seconds( while (time_now() - start < seconds(
m_settings.stop_tracker_timeout) m_settings.stop_tracker_timeout)
&& !m_tracker_manager.empty()) && !m_tracker_manager.empty())
{ {
tracker_timer.expires_from_now(boost::posix_time::milliseconds(100)); tracker_timer.expires_from_now(milliseconds(100));
tracker_timer.async_wait(m_strand.wrap( tracker_timer.async_wait(m_strand.wrap(
bind(&io_service::stop, &m_io_service))); bind(&io_service::stop, &m_io_service)));
@ -1491,7 +1490,7 @@ namespace libtorrent { namespace detail
m_logger = create_log("main_session", listen_port(), false); m_logger = create_log("main_session", listen_port(), false);
using boost::posix_time::second_clock; using boost::posix_time::second_clock;
using boost::posix_time::to_simple_string; using boost::posix_time::to_simple_string;
(*m_logger) << to_simple_string(second_clock::universal_time()) << "\n"; (*m_logger) << to_simple_string(second_clock::local_time()) << "\n";
#endif #endif
return m_listen_socket; return m_listen_socket;
@ -1517,7 +1516,7 @@ namespace libtorrent { namespace detail
if (!t) return; if (!t) return;
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::local_time())
<< ": added peer from local discovery: " << peer << "\n"; << ": added peer from local discovery: " << peer << "\n";
#endif #endif
t->get_policy().peer_from_tracker(peer, peer_id(0)); t->get_policy().peer_from_tracker(peer, peer_id(0));

View File

@ -91,8 +91,8 @@ namespace libtorrent
{ {
namespace namespace
{ {
using boost::posix_time::ptime; using ptime;
using boost::posix_time::time_duration; using time_duration;
using boost::posix_time::microsec_clock; using boost::posix_time::microsec_clock;
std::vector<std::pair<ptime, std::string> > checkpoints; std::vector<std::pair<ptime, std::string> > checkpoints;
} }
@ -238,7 +238,7 @@ namespace libtorrent
, m_event(tracker_request::started) , m_event(tracker_request::started)
, m_block_size(0) , m_block_size(0)
, m_storage(0) , m_storage(0)
, m_next_request(second_clock::universal_time()) , m_next_request(time_now())
, m_duration(1800) , m_duration(1800)
, m_complete(-1) , m_complete(-1)
, m_incomplete(-1) , m_incomplete(-1)
@ -322,7 +322,7 @@ namespace libtorrent
, m_event(tracker_request::started) , m_event(tracker_request::started)
, m_block_size(0) , m_block_size(0)
, m_storage(0) , m_storage(0)
, m_next_request(second_clock::universal_time()) , m_next_request(time_now())
, m_duration(1800) , m_duration(1800)
, m_complete(-1) , m_complete(-1)
, m_incomplete(-1) , m_incomplete(-1)
@ -468,7 +468,7 @@ namespace libtorrent
{ {
if (e) return; if (e) return;
m_announce_timer.expires_from_now(boost::posix_time::minutes(30)); m_announce_timer.expires_from_now(minutes(30));
m_announce_timer.async_wait(m_ses.m_strand.wrap( m_announce_timer.async_wait(m_ses.m_strand.wrap(
bind(&torrent::on_announce, this, _1))); bind(&torrent::on_announce, this, _1)));
@ -528,8 +528,7 @@ namespace libtorrent
m_just_paused = false; m_just_paused = false;
return true; return true;
} }
return !m_paused && return !m_paused && m_next_request < time_now();
m_next_request < second_clock::universal_time();
} }
void torrent::tracker_warning(std::string const& msg) void torrent::tracker_warning(std::string const& msg)
@ -565,7 +564,10 @@ namespace libtorrent
m_currently_trying_tracker = 0; m_currently_trying_tracker = 0;
m_duration = interval; m_duration = interval;
m_next_request = second_clock::universal_time() + boost::posix_time::seconds(m_duration); m_next_request = time_now() + seconds(m_duration);
std::cerr << "next announce: " << next_announce().time
<< " time: " << time_now().time
<< " duration: " << libtorrent::seconds(m_duration).diff << std::endl;
if (complete >= 0) m_complete = complete; if (complete >= 0) m_complete = complete;
if (incomplete >= 0) m_incomplete = incomplete; if (incomplete >= 0) m_incomplete = incomplete;
@ -1264,9 +1266,7 @@ namespace libtorrent
assert(!m_trackers.empty()); assert(!m_trackers.empty());
m_next_request m_next_request = time_now() + seconds(tracker_retry_delay_max);
= second_clock::universal_time()
+ boost::posix_time::seconds(tracker_retry_delay_max);
tracker_request req; tracker_request req;
req.info_hash = m_torrent_file.info_hash(); req.info_hash = m_torrent_file.info_hash();
@ -1335,7 +1335,7 @@ namespace libtorrent
INVARIANT_CHECK; INVARIANT_CHECK;
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
std::string now(to_simple_string(second_clock::universal_time())); std::string now(to_simple_string(second_clock::local_time()));
(*m_ses.m_logger) << now << " resolving: " << url << "\n"; (*m_ses.m_logger) << now << " resolving: " << url << "\n";
#endif #endif
@ -1373,7 +1373,7 @@ namespace libtorrent
INVARIANT_CHECK; INVARIANT_CHECK;
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
std::string now(to_simple_string(second_clock::universal_time())); std::string now(to_simple_string(second_clock::local_time()));
(*m_ses.m_logger) << now << " completed resolve proxy hostname for: " << url << "\n"; (*m_ses.m_logger) << now << " completed resolve proxy hostname for: " << url << "\n";
#endif #endif
@ -1427,7 +1427,7 @@ namespace libtorrent
INVARIANT_CHECK; INVARIANT_CHECK;
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
std::string now(to_simple_string(second_clock::universal_time())); std::string now(to_simple_string(second_clock::local_time()));
(*m_ses.m_logger) << now << " completed resolve: " << url << "\n"; (*m_ses.m_logger) << now << " completed resolve: " << url << "\n";
#endif #endif
@ -2158,13 +2158,13 @@ namespace libtorrent
++m_failed_trackers; ++m_failed_trackers;
// if we've looped the tracker list, wait a bit before retrying // if we've looped the tracker list, wait a bit before retrying
m_currently_trying_tracker = 0; m_currently_trying_tracker = 0;
m_next_request = second_clock::universal_time() + seconds(delay); m_next_request = time_now() + seconds(delay);
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
// only start the announce if we want to announce with the dht // only start the announce if we want to announce with the dht
if (should_announce_dht()) if (should_announce_dht())
{ {
m_announce_timer.expires_from_now(boost::posix_time::seconds(1)); m_announce_timer.expires_from_now(seconds(1));
m_announce_timer.async_wait(m_ses.m_strand.wrap( m_announce_timer.async_wait(m_ses.m_strand.wrap(
bind(&torrent::on_announce, this, _1))); bind(&torrent::on_announce, this, _1)));
} }
@ -2174,7 +2174,7 @@ namespace libtorrent
else else
{ {
// don't delay before trying the next tracker // don't delay before trying the next tracker
m_next_request = second_clock::universal_time(); m_next_request = time_now();
} }
} }
@ -2712,10 +2712,11 @@ namespace libtorrent
st.download_payload_rate = m_stat.download_payload_rate(); st.download_payload_rate = m_stat.download_payload_rate();
st.upload_payload_rate = m_stat.upload_payload_rate(); st.upload_payload_rate = m_stat.upload_payload_rate();
st.next_announce = next_announce() st.next_announce = boost::posix_time::seconds(
- second_clock::universal_time(); total_seconds(next_announce() - time_now()));
if (st.next_announce.is_negative()) st.next_announce if (st.next_announce.is_negative())
= boost::posix_time::seconds(0); st.next_announce = boost::posix_time::seconds(0);
st.announce_interval = boost::posix_time::seconds(m_duration); st.announce_interval = boost::posix_time::seconds(m_duration);
if (m_last_working_tracker >= 0) if (m_last_working_tracker >= 0)

View File

@ -640,7 +640,7 @@ namespace libtorrent
} }
void torrent_handle::force_reannounce( void torrent_handle::force_reannounce(
boost::posix_time::time_duration duration) const time_duration duration) const
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
@ -651,7 +651,7 @@ namespace libtorrent
if (!t) throw_invalid_handle(); if (!t) throw_invalid_handle();
using boost::posix_time::second_clock; using boost::posix_time::second_clock;
t->force_tracker_request(second_clock::universal_time() t->force_tracker_request(time_now()
+ duration); + duration);
} }

View File

@ -59,6 +59,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/hasher.hpp" #include "libtorrent/hasher.hpp"
#include "libtorrent/entry.hpp" #include "libtorrent/entry.hpp"
namespace pt = boost::posix_time;
namespace gr = boost::gregorian;
using namespace libtorrent; using namespace libtorrent;
using namespace boost::filesystem; using namespace boost::filesystem;
@ -220,7 +223,7 @@ namespace libtorrent
// standard constructor that parses a torrent file // standard constructor that parses a torrent file
torrent_info::torrent_info(const entry& torrent_file) torrent_info::torrent_info(const entry& torrent_file)
: m_creation_date(date(not_a_date_time)) : m_creation_date(pt::ptime(pt::not_a_date_time))
, m_multifile(false) , m_multifile(false)
, m_private(false) , m_private(false)
, m_extra_info(entry::dictionary_t) , m_extra_info(entry::dictionary_t)
@ -244,7 +247,7 @@ namespace libtorrent
, m_total_size(0) , m_total_size(0)
, m_info_hash(info_hash) , m_info_hash(info_hash)
, m_name() , m_name()
, m_creation_date(second_clock::universal_time()) , m_creation_date(pt::second_clock::universal_time())
, m_multifile(false) , m_multifile(false)
, m_private(false) , m_private(false)
, m_extra_info(entry::dictionary_t) , m_extra_info(entry::dictionary_t)
@ -256,7 +259,7 @@ namespace libtorrent
, m_total_size(0) , m_total_size(0)
, m_info_hash(0) , m_info_hash(0)
, m_name() , m_name()
, m_creation_date(second_clock::universal_time()) , m_creation_date(pt::second_clock::universal_time())
, m_multifile(false) , m_multifile(false)
, m_private(false) , m_private(false)
, m_extra_info(entry::dictionary_t) , m_extra_info(entry::dictionary_t)
@ -455,8 +458,8 @@ namespace libtorrent
// extract creation date // extract creation date
try try
{ {
m_creation_date = ptime(date(1970, Jan, 1)) m_creation_date = pt::ptime(gr::date(1970, gr::Jan, 1))
+ seconds(long(torrent_file["creation date"].integer())); + pt::seconds(long(torrent_file["creation date"].integer()));
} }
catch (type_error) {} catch (type_error) {}
@ -494,14 +497,14 @@ namespace libtorrent
parse_info_section(torrent_file["info"]); parse_info_section(torrent_file["info"]);
} }
boost::optional<ptime> boost::optional<pt::ptime>
torrent_info::creation_date() const torrent_info::creation_date() const
{ {
if (m_creation_date != ptime(date(not_a_date_time))) if (m_creation_date != pt::ptime(gr::date(pt::not_a_date_time)))
{ {
return boost::optional<ptime>(m_creation_date); return boost::optional<pt::ptime>(m_creation_date);
} }
return boost::optional<ptime>(); return boost::optional<pt::ptime>();
} }
void torrent_info::add_tracker(std::string const& url, int tier) void torrent_info::add_tracker(std::string const& url, int tier)
@ -696,7 +699,7 @@ namespace libtorrent
dict["comment"] = m_comment; dict["comment"] = m_comment;
dict["creation date"] = dict["creation date"] =
(m_creation_date - ptime(date(1970, Jan, 1))).total_seconds(); (m_creation_date - pt::ptime(gr::date(1970, gr::Jan, 1))).total_seconds();
if (!m_created_by.empty()) if (!m_created_by.empty())
dict["created by"] = m_created_by; dict["created by"] = m_created_by;
@ -750,7 +753,7 @@ namespace libtorrent
} }
if (!m_comment.empty()) if (!m_comment.empty())
os << "comment: " << m_comment << "\n"; os << "comment: " << m_comment << "\n";
if (m_creation_date != ptime(date(not_a_date_time))) if (m_creation_date != pt::ptime(gr::date(pt::not_a_date_time)))
os << "creation date: " << to_simple_string(m_creation_date) << "\n"; os << "creation date: " << to_simple_string(m_creation_date) << "\n";
os << "private: " << (m_private?"yes":"no") << "\n"; os << "private: " << (m_private?"yes":"no") << "\n";
os << "number of pieces: " << num_pieces() << "\n"; os << "number of pieces: " << num_pieces() << "\n";

View File

@ -81,11 +81,6 @@ namespace
namespace libtorrent 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 // returns -1 if gzip header is invalid or the header size in bytes
int gzip_header(const char* buf, int size) int gzip_header(const char* buf, int size)
{ {
@ -318,8 +313,8 @@ namespace libtorrent
timeout_handler::timeout_handler(asio::strand& str) timeout_handler::timeout_handler(asio::strand& str)
: m_strand(str) : m_strand(str)
, m_start_time(second_clock::universal_time()) , m_start_time(time_now())
, m_read_time(second_clock::universal_time()) , m_read_time(time_now())
, m_timeout(str.io_service()) , m_timeout(str.io_service())
, m_completion_timeout(0) , m_completion_timeout(0)
, m_read_timeout(0) , m_read_timeout(0)
@ -330,8 +325,8 @@ namespace libtorrent
{ {
m_completion_timeout = completion_timeout; m_completion_timeout = completion_timeout;
m_read_timeout = read_timeout; m_read_timeout = read_timeout;
m_start_time = second_clock::universal_time(); m_start_time = time_now();
m_read_time = second_clock::universal_time(); m_read_time = time_now();
m_timeout.expires_at(std::min( m_timeout.expires_at(std::min(
m_read_time + seconds(m_read_timeout) m_read_time + seconds(m_read_timeout)
@ -342,7 +337,7 @@ namespace libtorrent
void timeout_handler::restart_read_timeout() void timeout_handler::restart_read_timeout()
{ {
m_read_time = second_clock::universal_time(); m_read_time = time_now();
} }
void timeout_handler::cancel() void timeout_handler::cancel()
@ -356,14 +351,14 @@ namespace libtorrent
if (error) return; if (error) return;
if (m_completion_timeout == 0) 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 receive_timeout = now - m_read_time;
time_duration completion_timeout = now - m_start_time; time_duration completion_timeout = now - m_start_time;
if (m_read_timeout if (m_read_timeout
< receive_timeout.total_seconds() < total_seconds(receive_timeout)
|| m_completion_timeout || m_completion_timeout
< completion_timeout.total_seconds()) < total_seconds(completion_timeout))
{ {
on_timeout(); on_timeout();
return; return;

View File

@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/pch.hpp" #include "libtorrent/pch.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/upnp.hpp" #include "libtorrent/upnp.hpp"
#include "libtorrent/io.hpp" #include "libtorrent/io.hpp"
#include "libtorrent/http_tracker_connection.hpp" #include "libtorrent/http_tracker_connection.hpp"
@ -44,13 +45,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
#include <cstdlib> #include <cstdlib>
using boost::posix_time::microsec_clock;
using boost::bind; using boost::bind;
using namespace libtorrent; using namespace libtorrent;
using boost::posix_time::microsec_clock;
using boost::posix_time::milliseconds;
using boost::posix_time::seconds;
using boost::posix_time::second_clock;
using boost::posix_time::ptime;
namespace namespace
{ {
@ -728,11 +725,11 @@ void upnp::on_upnp_map_response(asio::error_code const& e
m_callback(tcp, udp, ""); m_callback(tcp, udp, "");
if (d.lease_duration > 0) if (d.lease_duration > 0)
{ {
d.mapping[mapping].expires = second_clock::universal_time() d.mapping[mapping].expires = time_now()
+ seconds(int(d.lease_duration * 0.75f)); + seconds(int(d.lease_duration * 0.75f));
ptime next_expire = m_refresh_timer.expires_at(); ptime next_expire = m_refresh_timer.expires_at();
if (next_expire == ptime(boost::date_time::not_a_date_time) if (next_expire == ptime(boost::date_time::not_a_date_time)
|| next_expire < second_clock::universal_time() || next_expire < time_now()
|| next_expire > d.mapping[mapping].expires) || next_expire > d.mapping[mapping].expires)
{ {
m_refresh_timer.expires_at(d.mapping[mapping].expires); m_refresh_timer.expires_at(d.mapping[mapping].expires);
@ -741,7 +738,7 @@ void upnp::on_upnp_map_response(asio::error_code const& e
} }
else else
{ {
d.mapping[mapping].expires = ptime(boost::date_time::not_a_date_time); d.mapping[mapping].expires = max_time();
} }
} }
@ -805,8 +802,8 @@ void upnp::on_expire(asio::error_code const& e)
{ {
if (e) return; if (e) return;
ptime now = second_clock::universal_time(); ptime now = time_now();
ptime next_expire = ptime(boost::date_time::not_a_date_time); ptime next_expire = max_time();
boost::mutex::scoped_lock l(m_mutex); boost::mutex::scoped_lock l(m_mutex);
for (std::set<rootdevice>::iterator i = m_devices.begin() for (std::set<rootdevice>::iterator i = m_devices.begin()
@ -815,22 +812,21 @@ void upnp::on_expire(asio::error_code const& e)
rootdevice& d = const_cast<rootdevice&>(*i); rootdevice& d = const_cast<rootdevice&>(*i);
for (int m = 0; m < num_mappings; ++m) for (int m = 0; m < num_mappings; ++m)
{ {
if (d.mapping[m].expires != ptime(boost::date_time::not_a_date_time)) if (d.mapping[m].expires != max_time())
continue; continue;
if (d.mapping[m].expires < now) if (d.mapping[m].expires < now)
{ {
d.mapping[m].expires = ptime(boost::date_time::not_a_date_time); d.mapping[m].expires = max_time();
map_port(d, m); map_port(d, m);
} }
else if (next_expire == ptime(boost::date_time::not_a_date_time) else if (d.mapping[m].expires < next_expire)
|| d.mapping[m].expires < next_expire)
{ {
next_expire = d.mapping[m].expires; next_expire = d.mapping[m].expires;
} }
} }
} }
if (next_expire != ptime(boost::date_time::not_a_date_time)) if (next_expire != max_time())
{ {
m_refresh_timer.expires_at(next_expire); m_refresh_timer.expires_at(next_expire);
m_refresh_timer.async_wait(bind(&upnp::on_expire, this, _1)); m_refresh_timer.async_wait(bind(&upnp::on_expire, this, _1));

View File

@ -1,10 +1,8 @@
#include "libtorrent/upnp.hpp" #include "libtorrent/upnp.hpp"
#include "libtorrent/socket.hpp" #include "libtorrent/socket.hpp"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/ref.hpp> #include <boost/ref.hpp>
using boost::posix_time::seconds;
using namespace libtorrent; using namespace libtorrent;
void callback(int tcp, int udp, std::string const& err) void callback(int tcp, int udp, std::string const& err)