deprecate the ptime type and related time types. just use boost::chrono / std::chrono

This commit is contained in:
Arvid Norberg 2015-03-12 04:34:54 +00:00
parent a70960c26f
commit c1dc982f4f
85 changed files with 551 additions and 499 deletions

View File

@ -1,3 +1,5 @@
* deprecate time functions, expose typedefs of boost::chrono in the libtorrent
namespace instead
* deprecate file_base feature in file_storage/torrent_info
* improve piece picker support for reverse picking (used for snubbed peers)
to not cause priority inversion for regular peers

View File

@ -84,7 +84,6 @@ category_mapping = {
'lazy_entry.hpp': 'Bencoding',
'entry.hpp': 'Bencoding',
'time.hpp': 'Time',
'ptime.hpp': 'Time',
'escape_string.hpp': 'String',
'string_util.hpp': 'String',
'utf8.hpp': 'String',

View File

@ -127,7 +127,7 @@ bool sleep_and_input(int* c, int sleep)
// sets the terminal to single-character mode
// and resets when destructed
set_keypress s;
libtorrent::ptime start = libtorrent::time_now_hires();
libtorrent::time_point start = libtorrent::clock_type::now();
int ret = 0;
retry:
fd_set set;
@ -142,7 +142,7 @@ retry:
}
if (errno == EINTR)
{
if (total_milliseconds(libtorrent::time_now_hires() - start) < sleep)
if (total_milliseconds(libtorrent::clock_type::now() - start) < sleep)
goto retry;
return false;
}
@ -1188,7 +1188,7 @@ void print_piece(libtorrent::partial_piece_info* pp
char const* cache_kind_str[] = {"read", "write", "read-volatile"};
snprintf(str, sizeof(str), " %3d cache age: %-5.1f state: %s%s\n"
, cs ? cs->next_to_hash : 0
, cs ? (total_milliseconds(time_now() - cs->last_use) / 1000.f) : 0.f
, cs ? (total_milliseconds(clock_type::now() - cs->last_use) / 1000.f) : 0.f
, cs ? cache_kind_str[cs->kind] : "N/A"
, ts && ts->pieces.size() ? (ts->pieces[piece] ? " have" : " dont-have") : "");
out += str;
@ -1296,7 +1296,7 @@ int main(int argc, char* argv[])
std::deque<std::string> events;
ptime next_dir_scan = time_now();
time_point next_dir_scan = clock_type::now();
// the string is the filename of the .torrent file, but only if
// it was added through the directory monitor. It is used to
@ -2055,7 +2055,7 @@ int main(int argc, char* argv[])
if (print_trackers)
{
std::vector<announce_entry> tr = h.trackers();
ptime now = time_now();
time_point now = clock_type::now();
for (std::vector<announce_entry>::iterator i = tr.begin()
, end(tr.end()); i != end; ++i)
{
@ -2263,12 +2263,12 @@ int main(int argc, char* argv[])
fflush(stdout);
if (!monitor_dir.empty()
&& next_dir_scan < time_now())
&& next_dir_scan < clock_type::now())
{
scan_dir(monitor_dir, ses, files, non_files
, allocation_mode, save_path, torrent_upload_limit
, torrent_download_limit);
next_dir_scan = time_now() + seconds(poll_interval);
next_dir_scan = clock_type::now() + seconds(poll_interval);
}
}

View File

@ -153,7 +153,7 @@ struct peer_conn
, blocks_received(0)
, blocks_sent(0)
, num_pieces(num_pieces)
, start_time(time_now_hires())
, start_time(clock_type::now())
, churn(churn_)
, corrupt(corrupt_)
, endpoint(ep)
@ -222,8 +222,8 @@ struct peer_conn
int blocks_received;
int blocks_sent;
int num_pieces;
ptime start_time;
ptime end_time;
time_point start_time;
time_point end_time;
int churn;
bool corrupt;
tcp::endpoint endpoint;
@ -408,7 +408,7 @@ struct peer_conn
void close(char const* fmt, error_code const& ec)
{
end_time = time_now_hires();
end_time = clock_type::now();
char tmp[1024];
snprintf(tmp, sizeof(tmp), fmt, ec.message().c_str());
int time = total_milliseconds(end_time - start_time);

View File

@ -147,13 +147,15 @@ nobase_include_HEADERS = \
web_peer_connection.hpp \
xml_parse.hpp \
\
$(GEOIP_H) \
tommath.h \
tommath_class.h \
tommath_superclass.h \
tommath.h \
tommath_class.h \
tommath_superclass.h \
\
aux_/session_impl.hpp \
aux_/session_settings.hpp\
aux_/session_call.hpp \
aux_/session_impl.hpp \
aux_/session_settings.hpp \
aux_/session_interface.hpp \
aux_/time.hpp \
\
extensions/lt_trackers.hpp \
extensions/metadata_transfer.hpp \

View File

@ -197,7 +197,7 @@ namespace libtorrent {
virtual ~alert();
// a timestamp is automatically created in the constructor
ptime timestamp() const;
time_point timestamp() const;
// returns an integer that is unique to this alert type. It can be
// compared against a specific alert by querying a static constant called ``alert_type``
@ -256,7 +256,7 @@ namespace libtorrent {
virtual std::auto_ptr<alert> clone() const = 0;
private:
ptime m_timestamp;
time_point m_timestamp;
};
#ifndef BOOST_NO_EXCEPTIONS

View File

@ -950,18 +950,18 @@ namespace libtorrent
void recalculate_unchoke_slots();
void recalculate_optimistic_unchoke_slots();
ptime m_created;
boost::int64_t session_time() const { return total_seconds(time_now() - m_created); }
time_point m_created;
boost::int64_t session_time() const { return total_seconds(aux::time_now() - m_created); }
ptime m_last_tick;
ptime m_last_second_tick;
time_point m_last_tick;
time_point m_last_second_tick;
// the last time we went through the peers
// to decide which ones to choke/unchoke
ptime m_last_choke;
time_point m_last_choke;
// the time when the next rss feed needs updating
ptime m_next_rss_update;
time_point m_next_rss_update;
// update any rss feeds that need updating and
// recalculate m_next_rss_update

View File

@ -0,0 +1,56 @@
/*
Copyright (c) 2015, 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_AUX_TIME_HPP
#define TORRENT_AUX_TIME_HPP
#include "libtorrent/config.hpp"
#include "libtorrent/time.hpp"
#include <string>
#include <boost/cstdint.hpp>
namespace libtorrent { namespace aux
{
// TODO: 3 this is only used for debug logging. It should probably not
// be included unconditionally
TORRENT_EXTRA_EXPORT char const* time_now_string();
std::string log_time();
// returns the current time, as represented by time_point. The
// resolution of this timer is about 100 ms.
time_point const& time_now();
} }
#endif

View File

@ -98,7 +98,7 @@ private:
#ifdef TORRENT_VERBOSE_BANDWIDTH_LIMIT
std::ofstream m_log;
ptime m_start;
time_point m_start;
#endif
};

View File

@ -211,7 +211,7 @@ namespace libtorrent
// plus the minimum amount of time the block is guaranteed
// to stay in the cache
//TODO: make this 32 bits and to count seconds since the block cache was created
ptime expire;
time_point expire;
boost::uint64_t piece:22;

View File

@ -256,7 +256,7 @@ namespace libtorrent
#if TORRENT_USE_INVARIANT_CHECKS
void check_invariant() const;
ptime m_last_choke;
time_point m_last_choke;
#endif
private:

View File

@ -74,7 +74,7 @@ namespace libtorrent
// timestamp -> operation
struct wakeup_t
{
ptime timestamp;
time_point timestamp;
boost::uint64_t context_switches;
char const* operation;
};
@ -117,7 +117,7 @@ namespace libtorrent
{
_wakeups.push_back(wakeup_t());
wakeup_t& w = _wakeups.back();
w.timestamp = time_now_hires();
w.timestamp = clock_type::now();
#ifdef __MACH__
task_events_info teinfo;
mach_msg_type_number_t t_info_count = TASK_EVENTS_INFO_COUNT;

View File

@ -75,7 +75,7 @@ namespace libtorrent
// the time when a block was last written to this piece. The older
// a piece is, the more likely it is to be flushed to disk.
ptime last_use;
time_point last_use;
// The index of the next block that needs to be hashed.
// Blocks are hashed as they are downloaded in order to not
@ -520,9 +520,9 @@ namespace libtorrent
void* m_userdata;
// the last time we expired write blocks from the cache
ptime m_last_cache_expiry;
time_point m_last_cache_expiry;
ptime m_last_file_check;
time_point m_last_file_check;
// LRU cache of open files
file_pool m_file_pool;
@ -583,7 +583,7 @@ namespace libtorrent
tailqueue m_queued_hash_jobs;
// used to rate limit disk performance warnings
ptime m_last_disk_aio_performance_warning;
time_point m_last_disk_aio_performance_warning;
// function to be posted to the network thread to post
// an alert (used for performance warnings)

View File

@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/time.hpp"
#include "libtorrent/thread.hpp"
#include "libtorrent/file_storage.hpp"
#include "libtorrent/aux_/time.hpp"
namespace libtorrent
{
@ -48,7 +49,7 @@ namespace libtorrent
int file_index;
// a (high precision) timestamp of when the file was last used.
ptime last_use;
time_point last_use;
// ``open_mode`` is a bitmask of the file flags this file is currently opened with. These
// are the flags used in the ``file::open()`` function. This enum is defined as a member
@ -126,10 +127,10 @@ namespace libtorrent
struct lru_file_entry
{
lru_file_entry(): key(0), last_use(time_now()), mode(0) {}
lru_file_entry(): key(0), last_use(aux::time_now()), mode(0) {}
mutable file_handle file_ptr;
void* key;
ptime last_use;
time_point last_use;
int mode;
};

View File

@ -176,8 +176,8 @@ private:
// as all the quota was used.
deadline_timer m_limiter_timer;
ptime m_last_receive;
ptime m_start_time;
time_point m_last_receive;
time_point m_start_time;
// specifies whether or not the connection is
// configured to use a proxy

View File

@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <vector>
#include "libtorrent/address.hpp"
#include "libtorrent/bloom_filter.hpp"
#include "libtorrent/time.hpp" // for ptime
#include "libtorrent/time.hpp" // for time_point
namespace libtorrent
{
@ -101,7 +101,7 @@ namespace libtorrent
// the last time we rotated this ip_voter. i.e. threw
// away all the votes and started from scratch, in case
// our IP has changed
ptime m_last_rotate;
time_point m_last_rotate;
};
// this keeps track of multiple external IPs (for now, just IPv6 and IPv4, but

View File

@ -146,7 +146,7 @@ namespace libtorrent { namespace dht
std::vector<char> m_send_buf;
dos_blocker m_blocker;
ptime m_last_new_key;
time_point m_last_new_key;
deadline_timer m_timer;
deadline_timer m_connection_timer;
deadline_timer m_refresh_timer;

View File

@ -50,7 +50,7 @@ namespace libtorrent { namespace dht
// called every time we receive an incoming packet. Returns
// true if we should let the packet through, and false if
// it's blocked
bool incoming(address addr, ptime now);
bool incoming(address addr, time_point now);
void set_rate_limit(int l)
{
@ -71,7 +71,7 @@ namespace libtorrent { namespace dht
{
node_ban_entry(): count(0) {}
address src;
ptime limit;
time_point limit;
int count;
};

View File

@ -107,7 +107,7 @@ bool TORRENT_EXTRA_EXPORT verify_message(lazy_entry const* msg, key_desc_t const
// to remove stale peers
struct peer_entry
{
ptime added;
time_point added;
tcp::endpoint addr;
bool seed;
};
@ -129,7 +129,7 @@ struct dht_immutable_item
// popularity if we reach the limit of items to store
bloom_filter<128> ips;
// the last time we heard about this
ptime last_seen;
time_point last_seen;
// number of IPs in the bloom filter
int num_announcers;
// size of malloced space pointed to by value
@ -322,11 +322,11 @@ private:
dht_immutable_table_t m_immutable_table;
dht_mutable_table_t m_mutable_table;
ptime m_last_tracker_tick;
time_point m_last_tracker_tick;
// the last time we issued a bootstrap or a refresh on our own ID, to expand
// the routing table buckets close to us.
ptime m_last_self_refresh;
time_point m_last_self_refresh;
// secret random numbers used to create write tokens
int m_secret[2];

View File

@ -37,11 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp"
#include "libtorrent/address.hpp"
#include "libtorrent/union_endpoint.hpp"
#include "libtorrent/time.hpp" // for time_now()
#ifdef TORRENT_DHT_VERBOSE_LOGGING
#include "libtorrent/time.hpp"
#endif
#include "libtorrent/aux_/time.hpp" // for aux::time_now()
namespace libtorrent { namespace dht
{
@ -50,7 +46,7 @@ struct node_entry
{
node_entry(node_id const& id_, udp::endpoint ep, int roundtriptime = 0xffff
, bool pinged = false)
: last_queried(pinged ? time_now() : min_time())
: last_queried(pinged ? aux::time_now() : min_time())
, id(id_)
, a(ep.address().to_v4().to_bytes())
, p(ep.port())
@ -58,7 +54,7 @@ struct node_entry
, timeout_count(pinged ? 0 : 0xff)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
first_seen = time_now();
first_seen = aux::time_now();
#endif
}
@ -71,7 +67,7 @@ struct node_entry
, timeout_count(0xff)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
first_seen = time_now();
first_seen = aux::time_now();
#endif
}
@ -83,7 +79,7 @@ struct node_entry
, timeout_count(0xff)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
first_seen = time_now();
first_seen = aux::time_now();
#endif
}
@ -106,11 +102,11 @@ struct node_entry
int port() const { return p; }
#ifdef TORRENT_DHT_VERBOSE_LOGGING
ptime first_seen;
time_point first_seen;
#endif
// the time we last received a response for a request to this peer
ptime last_queried;
time_point last_queried;
node_id id;

View File

@ -98,7 +98,7 @@ struct observer : boost::noncopyable
// is being destructed
void abort();
ptime sent() const { return m_sent; }
time_point sent() const { return m_sent; }
void set_target(udp::endpoint const& ep);
address target_addr() const;
@ -130,7 +130,7 @@ protected:
void done();
ptime m_sent;
time_point m_sent;
const boost::intrusive_ptr<traversal_algorithm> m_algorithm;

View File

@ -218,7 +218,7 @@ private:
// the last time we refreshed our own bucket
// refreshed every 15 minutes
mutable ptime m_last_self_refresh;
mutable time_point m_last_self_refresh;
// this is a set of all the endpoints that have
// been identified as router nodes. They will

View File

@ -123,7 +123,7 @@ private:
udp_socket_interface* m_sock;
routing_table& m_table;
ptime m_timer;
time_point m_timer;
node_id m_our_id;
boost::uint32_t m_allocated_observers:31;
boost::uint32_t m_destructing:1;

View File

@ -105,7 +105,7 @@ private:
int action;
// the time the port mapping will expire
ptime expires;
time_point expires;
// the local port for this mapping. If this is set
// to 0, the mapping is not in use

View File

@ -479,8 +479,8 @@ namespace libtorrent
std::vector<int> const& allowed_fast();
std::vector<int> const& suggested_pieces() const { return m_suggested_pieces; }
ptime connected_time() const { return m_connect; }
ptime last_received() const { return m_last_receive; }
time_point connected_time() const { return m_connect; }
time_point last_received() const { return m_last_receive; }
// this will cause this peer_connection to be disconnected.
virtual void disconnect(error_code const& ec
@ -555,9 +555,9 @@ namespace libtorrent
#endif
#if defined TORRENT_LOGGING
ptime m_connect_time;
ptime m_bitfield_time;
ptime m_unchoke_time;
time_point m_connect_time;
time_point m_bitfield_time;
time_point m_unchoke_time;
#endif
// the message handlers are called
@ -714,7 +714,7 @@ namespace libtorrent
{ return m_statistics.total_payload_upload() - m_uploaded_at_last_unchoke; }
// the time we last unchoked this peer
ptime time_of_last_unchoke() const
time_point time_of_last_unchoke() const
{ return m_last_unchoke; }
// called when the disk write buffer is drained again, and we can
@ -813,7 +813,7 @@ namespace libtorrent
int preferred_caching() const;
void fill_send_buffer();
void on_disk_read_complete(disk_io_job const* j, peer_request r
, ptime issue_time);
, time_point issue_time);
void on_disk_write_complete(disk_io_job const* j
, peer_request r, boost::shared_ptr<torrent> t);
void on_seed_mode_hashed(disk_io_job const* j);
@ -913,29 +913,29 @@ namespace libtorrent
// the time when we last got a part of a
// piece packet from this peer
ptime m_last_piece;
time_point m_last_piece;
// the time we sent a request to
// this peer the last time
ptime m_last_request;
time_point m_last_request;
// the time we received the last
// piece request from the peer
ptime m_last_incoming_request;
time_point m_last_incoming_request;
// the time when we unchoked this peer
ptime m_last_unchoke;
time_point m_last_unchoke;
// if we're unchoked by this peer, this
// was the time
ptime m_last_unchoked;
time_point m_last_unchoked;
// the time we last choked this peer. min_time() in
// case we never unchoked it
ptime m_last_choke;
time_point m_last_choke;
// timeouts
ptime m_last_receive;
ptime m_last_sent;
time_point m_last_receive;
time_point m_last_sent;
// the time when the first entry in the request queue was requested. Used
// for request timeout. it doesn't necessarily represent the time when a
@ -944,23 +944,23 @@ namespace libtorrent
// Once we get that response, we set it to the current time.
// for more information, see the blog post at:
// http://blog.libtorrent.org/2011/11/block-request-time-outs/
ptime m_requested;
time_point m_requested;
// a timestamp when the remote download rate
// was last updated
ptime m_remote_dl_update;
time_point m_remote_dl_update;
// the time when async_connect was called
// or when the incoming connection was established
ptime m_connect;
time_point m_connect;
// the time when this peer sent us a not_interested message
// the last time.
ptime m_became_uninterested;
time_point m_became_uninterested;
// the time when we sent a not_interested message to
// this peer the last time.
ptime m_became_uninteresting;
time_point m_became_uninteresting;
// the total payload download bytes
// at the last unchoke round. This is used to

View File

@ -62,7 +62,7 @@ private:
struct dns_cache_entry
{
ptime last_seen;
time_point last_seen;
std::vector<address> addresses;
};

View File

@ -128,8 +128,10 @@ namespace libtorrent
TORRENT_EXPORT void high_performance_seed(settings_pack& set);
#ifndef TORRENT_NO_DEPRECATE
TORRENT_EXPORT session_settings min_memory_usage();
TORRENT_EXPORT session_settings high_performance_seed();
TORRENT_DEPRECATED_PREFIX
TORRENT_EXPORT session_settings min_memory_usage() TORRENT_DEPRECATED;
TORRENT_DEPRECATED_PREFIX
TORRENT_EXPORT session_settings high_performance_seed() TORRENT_DEPRECATED;
#endif
#ifndef TORRENT_CFG

View File

@ -33,7 +33,6 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_TIME_HPP_INCLUDED
#define TORRENT_TIME_HPP_INCLUDED
#include <boost/version.hpp>
#include "libtorrent/config.hpp"
#include <boost/cstdint.hpp>
@ -43,31 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/chrono.hpp>
#endif
#include <string>
// OVERVIEW
//
// This section contains fundamental time types used internally by
// libtorrent and exposed through various places in the API. The two
// basic types are ``ptime`` and ``time_duration``. The first represents
// a point in time and the second the difference between two points
// in time.
//
// The internal representation of these types is implementation defined
// and they can only be constructed via one of the construction functions
// that take a well defined time unit (seconds, minutes, etc.). They can
// only be turned into well defined time units by the accessor functions
// (total_microseconds(), etc.).
//
// .. note::
// In a future version of libtorrent, these types will be replaced
// by the standard timer types from ``std::chrono``.
//
namespace libtorrent
{
TORRENT_EXTRA_EXPORT char const* time_now_string();
std::string log_time();
namespace libtorrent {
#if defined BOOST_ASIO_HAS_STD_CHRONO
typedef std::chrono::high_resolution_clock clock_type;
@ -75,23 +50,9 @@ namespace libtorrent
typedef boost::chrono::high_resolution_clock clock_type;
#endif
typedef clock_type::time_point ptime;
typedef clock_type::time_point time_point;
typedef clock_type::duration time_duration;
// returns the current time, as represented by ptime. The
// resolution of this timer is about 100 ms.
TORRENT_EXPORT ptime const& time_now();
// returns the current time as represented by ptime. This is
// more expensive than time_now(), but provides as high resolution
// as the operating system can provide.
inline ptime time_now_hires() { return clock_type::now(); }
// the earliest and latest possible time points
// representable by ptime.
inline ptime min_time() { return (clock_type::time_point::min)(); }
inline ptime max_time() { return (clock_type::time_point::max)(); }
#if defined BOOST_ASIO_HAS_STD_CHRONO
using std::chrono::seconds;
using std::chrono::milliseconds;
@ -108,6 +69,9 @@ namespace libtorrent
using boost::chrono::duration_cast;
#endif
inline time_point min_time() { return (time_point::min)(); }
inline time_point max_time() { return (time_point::max)(); }
template<class T>
boost::int64_t total_seconds(T td)
{ return duration_cast<seconds>(td).count(); }
@ -120,6 +84,24 @@ namespace libtorrent
boost::int64_t total_microseconds(T td)
{ return duration_cast<microseconds>(td).count(); }
#ifndef TORRENT_NO_DEPRECATE
TORRENT_DEPRECATED_PREFIX
time_point time_now() TORRENT_DEPRECATED;
TORRENT_DEPRECATED_PREFIX
time_point time_now_hires() TORRENT_DEPRECATED;
inline time_point time_now()
{ return clock_type::now(); }
inline time_point time_now_hires()
{ return clock_type::now(); }
typedef time_point ptime TORRENT_DEPRECATED;
#endif
}
#endif // TORRENT_TIME_HPP_INCLUDED

View File

@ -122,11 +122,11 @@ namespace libtorrent
struct time_critical_piece
{
// when this piece was first requested
ptime first_requested;
time_point first_requested;
// when this piece was last requested
ptime last_requested;
time_point last_requested;
// by what time we want this piece
ptime deadline;
time_point deadline;
// 1 = send alert with piece data when available
int flags;
// how many peers it's been requested from
@ -151,7 +151,7 @@ namespace libtorrent
, web_seed_entry::headers_t const& extra_headers_ = web_seed_entry::headers_t());
// if this is > now, we can't reconnect yet
ptime retry;
time_point retry;
// if the hostname of the web seed has been resolved,
// these are its IP addresses
@ -729,10 +729,10 @@ namespace libtorrent
// returns the absolute time when the next tracker
// announce will take place.
ptime next_announce() const;
time_point next_announce() const;
// forcefully sets next_announce to the current time
void force_tracker_request(ptime, int tracker_idx);
void force_tracker_request(time_point, int tracker_idx);
void scrape_tracker();
void announce_with_tracker(boost::uint8_t e
= tracker_request::none
@ -1029,7 +1029,7 @@ namespace libtorrent
#if defined TORRENT_LOGGING
virtual void debug_log(const char* fmt, ...) const;
void log_to_all_peers(char const* message);
ptime m_dht_start_time;
time_point m_dht_start_time;
#endif
// DEBUG
@ -1181,7 +1181,7 @@ namespace libtorrent
void update_peer_interest(bool was_finished);
void prioritize_udp_trackers();
void update_tracker_timer(ptime now);
void update_tracker_timer(time_point now);
static void on_tracker_announce_disp(boost::weak_ptr<torrent> p
, error_code const& e);

View File

@ -116,10 +116,10 @@ namespace libtorrent
int min_announce_in() const;
// the time of next tracker announce
ptime next_announce;
time_point next_announce;
// no announces before this time
ptime min_announce;
time_point min_announce;
// TODO: include the number of peers received from this tracker, at last
// announce
@ -196,7 +196,7 @@ namespace libtorrent
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.0
TORRENT_DEPRECATED_PREFIX
bool will_announce(ptime now) const TORRENT_DEPRECATED
bool will_announce(time_point now) const TORRENT_DEPRECATED
{
return now <= next_announce
&& (fails < fail_limit || fail_limit == 0)
@ -209,7 +209,7 @@ namespace libtorrent
// argument is necessary because once we become a seed, we
// need to announce right away, even if the re-announce timer
// hasn't expired yet.
bool can_announce(ptime now, bool is_seed) const;
bool can_announce(time_point now, bool is_seed) const;
// returns true if the last time we tried to announce to this
// tracker succeeded, or if we haven't tried yet.

View File

@ -262,10 +262,10 @@ namespace libtorrent
// used for timeouts
// this is set when the request has been sent
ptime m_start_time;
time_point m_start_time;
// this is set every time something is received
ptime m_read_time;
time_point m_read_time;
// the asio async operation
deadline_timer m_timeout;

View File

@ -278,7 +278,7 @@ namespace libtorrent
int m_rate_limit;
int m_quota;
ptime m_last_tick;
time_point m_last_tick;
};
}

View File

@ -124,7 +124,7 @@ namespace libtorrent
struct connection_cache_entry
{
boost::int64_t connection_id;
ptime expires;
time_point expires;
};
static std::map<address, connection_cache_entry> m_connection_cache;

View File

@ -232,7 +232,7 @@ private:
{}
// the time the port mapping will expire
ptime expires;
time_point expires;
int action;
@ -375,7 +375,7 @@ private:
// cache of interfaces
mutable std::vector<ip_interface> m_interfaces;
mutable ptime m_last_if_update;
mutable time_point m_last_if_update;
};
}

View File

@ -64,7 +64,7 @@ namespace libtorrent
virtual void socket_drained();
void tick(ptime now);
void tick(time_point now);
tcp::endpoint local_endpoint(address const& remote, error_code& ec) const;
int local_port(error_code& ec) const;
@ -139,11 +139,11 @@ namespace libtorrent
// the timestamp for the last time we updated
// the routing table
mutable ptime m_last_route_update;
mutable time_point m_last_route_update;
// cache of interfaces
mutable std::vector<ip_interface> m_interfaces;
mutable ptime m_last_if_update;
mutable time_point m_last_if_update;
// the buffer size of the socket. This is used
// to now lower the buffer size

View File

@ -149,10 +149,10 @@ utp_socket_impl* construct_utp_impl(boost::uint16_t recv_id
void detach_utp_impl(utp_socket_impl* s);
void delete_utp_impl(utp_socket_impl* s);
bool should_delete(utp_socket_impl* s);
void tick_utp_impl(utp_socket_impl* s, ptime now);
void tick_utp_impl(utp_socket_impl* s, time_point now);
void utp_init_mtu(utp_socket_impl* s, int link_mtu, int utp_mtu);
bool utp_incoming_packet(utp_socket_impl* s, char const* p
, int size, udp::endpoint const& ep, ptime receive_time);
, int size, udp::endpoint const& ep, time_point receive_time);
bool utp_match(utp_socket_impl* s, udp::endpoint const& ep, boost::uint16_t id);
udp::endpoint utp_remote_endpoint(utp_socket_impl* s);
boost::uint16_t utp_receive_id(utp_socket_impl* s);

View File

@ -42,13 +42,14 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/escape_string.hpp"
#include "libtorrent/extensions.hpp"
#include "libtorrent/torrent.hpp"
#include "libtorrent/aux_/time.hpp"
#include <boost/bind.hpp>
namespace libtorrent {
alert::alert() : m_timestamp(time_now()) {}
alert::alert() : m_timestamp(aux::time_now()) {}
alert::~alert() {}
ptime alert::timestamp() const { return m_timestamp; }
time_point alert::timestamp() const { return m_timestamp; }
torrent_alert::torrent_alert(torrent_handle const& h)
: handle(h)

View File

@ -48,7 +48,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_BANDWIDTH_LIMIT
if (log)
m_log.open("bandwidth_limiter.log", std::ios::trunc);
m_start = time_now();
m_start = aux::time_now();
#endif
}

View File

@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/alloca.hpp"
#include "libtorrent/alert_dispatcher.hpp"
#include "libtorrent/performance_counters.hpp"
#include "libtorrent/aux_/time.hpp"
#ifdef TORRENT_DEBUG
#include "libtorrent/random.hpp"
@ -323,7 +324,7 @@ void block_cache::bump_lru(cached_piece_entry* p)
// move to the back (MRU) of the list
lru_list->erase(p);
lru_list->push_back(p);
p->expire = time_now();
p->expire = aux::time_now();
}
// this is called for pieces that we're reading from, when they
@ -397,7 +398,7 @@ void block_cache::cache_hit(cached_piece_entry* p, void* requester, bool volatil
m_lru[p->cache_state].erase(p);
m_lru[target_queue].push_back(p);
p->cache_state = target_queue;
p->expire = time_now();
p->expire = aux::time_now();
#if TORRENT_USE_ASSERTS
switch (p->cache_state)
{
@ -435,7 +436,7 @@ void block_cache::update_cache_state(cached_piece_entry* p)
src->erase(p);
dst->push_back(p);
p->expire = time_now();
p->expire = aux::time_now();
p->cache_state = desired_state;
#if TORRENT_USE_ASSERTS
switch (p->cache_state)
@ -475,7 +476,7 @@ cached_piece_entry* block_cache::allocate_piece(disk_io_job const* j, int cache_
cached_piece_entry pe;
pe.piece = j->piece;
pe.storage = j->storage;
pe.expire = time_now();
pe.expire = aux::time_now();
pe.blocks_in_piece = blocks_in_piece;
pe.blocks.reset(new (std::nothrow) cached_block_entry[blocks_in_piece]);
pe.cache_state = cache_state;
@ -542,7 +543,7 @@ cached_piece_entry* block_cache::allocate_piece(disk_io_job const* j, int cache_
m_lru[p->cache_state].erase(p);
p->cache_state = cache_state;
m_lru[p->cache_state].push_back(p);
p->expire = time_now();
p->expire = aux::time_now();
#if TORRENT_USE_ASSERTS
switch (p->cache_state)
{
@ -1480,7 +1481,7 @@ void block_cache::check_invariant() const
for (int i = 0; i < cached_piece_entry::num_lrus; ++i)
{
ptime timeout = min_time();
time_point timeout = min_time();
for (list_iterator p = m_lru[i].iterate(); p.get(); p.next())
{

View File

@ -163,7 +163,7 @@ namespace libtorrent
, m_num_running_threads(0)
, m_userdata(userdata)
, m_last_cache_expiry(min_time())
, m_last_file_check(time_now_hires())
, m_last_file_check(clock_type::now())
, m_file_pool(40)
, m_disk_cache(block_size, ios, boost::bind(&disk_io_thread::trigger_cache_trim, this), alert_disp)
, m_stats_counters(cnt)
@ -628,7 +628,7 @@ namespace libtorrent
TORRENT_PIECE_ASSERT(num_blocks > 0, pe);
m_stats_counters.inc_stats_counter(counters::num_writing_threads, 1);
ptime start_time = time_now_hires();
time_point start_time = clock_type::now();
int block_size = m_disk_cache.block_size();
#if DEBUG_DISK_THREAD
@ -662,7 +662,7 @@ namespace libtorrent
if (!failed)
{
TORRENT_PIECE_ASSERT(!error, pe);
boost::uint32_t write_time = total_microseconds(time_now_hires() - start_time);
boost::uint32_t write_time = total_microseconds(clock_type::now() - start_time);
m_write_time.add_sample(write_time / num_blocks);
m_stats_counters.inc_stats_counter(counters::num_blocks_written, num_blocks);
@ -976,11 +976,11 @@ namespace libtorrent
{
DLOG("flush_expired_write_blocks\n");
ptime now = time_now();
time_point now = aux::time_now();
time_duration expiration_limit = seconds(m_settings.get_int(settings_pack::cache_expiry));
#if TORRENT_USE_ASSERTS
ptime timeout = min_time();
time_point timeout = min_time();
#endif
cached_piece_entry** to_flush = TORRENT_ALLOCA(cached_piece_entry*, 200);
@ -1139,7 +1139,7 @@ namespace libtorrent
TORRENT_ASSERT(j->action < sizeof(job_functions)/sizeof(job_functions[0]));
ptime start_time = time_now_hires();
time_point start_time = clock_type::now();
m_stats_counters.inc_stats_counter(counters::num_running_disk_jobs, 1);
@ -1190,7 +1190,7 @@ namespace libtorrent
j->ret = ret;
ptime now = time_now_hires();
time_point now = clock_type::now();
m_job_time.add_sample(total_microseconds(now - start_time));
completed_jobs.push_back(j);
}
@ -1205,7 +1205,7 @@ namespace libtorrent
return -1;
}
ptime start_time = time_now_hires();
time_point start_time = clock_type::now();
int file_flags = file_flags_for_job(j);
file::iovec_t b = { j->buffer, size_t(j->d.io.buffer_size) };
@ -1217,7 +1217,7 @@ namespace libtorrent
if (!j->error.ec)
{
boost::uint32_t read_time = total_microseconds(time_now_hires() - start_time);
boost::uint32_t read_time = total_microseconds(clock_type::now() - start_time);
m_read_time.add_sample(read_time);
m_stats_counters.inc_stats_counter(counters::num_read_back);
@ -1313,14 +1313,14 @@ namespace libtorrent
// disk operations.
int file_flags = file_flags_for_job(j);
ptime start_time = time_now_hires();
time_point start_time = clock_type::now();
ret = j->storage->get_storage_impl()->readv(iov, iov_len
, j->piece, adjusted_offset, file_flags, j->error);
if (!j->error.ec)
{
boost::uint32_t read_time = total_microseconds(time_now_hires() - start_time);
boost::uint32_t read_time = total_microseconds(clock_type::now() - start_time);
m_read_time.add_sample(read_time / iov_len);
m_stats_counters.inc_stats_counter(counters::num_blocks_read, iov_len);
@ -1461,7 +1461,7 @@ namespace libtorrent
int disk_io_thread::do_uncached_write(disk_io_job* j)
{
ptime start_time = time_now_hires();
time_point start_time = clock_type::now();
file::iovec_t b = { j->buffer, size_t(j->d.io.buffer_size) };
int file_flags = file_flags_for_job(j);
@ -1476,7 +1476,7 @@ namespace libtorrent
if (!j->error.ec)
{
boost::uint32_t write_time = total_microseconds(time_now_hires() - start_time);
boost::uint32_t write_time = total_microseconds(clock_type::now() - start_time);
m_write_time.add_sample(write_time);
m_stats_counters.inc_stats_counter(counters::num_blocks_written);
@ -2188,7 +2188,7 @@ namespace libtorrent
l.unlock();
ptime start_time = time_now_hires();
time_point start_time = clock_type::now();
for (int i = cursor; i < end; ++i)
{
@ -2198,7 +2198,7 @@ namespace libtorrent
ph->offset += size;
}
boost::uint64_t hash_time = total_microseconds(time_now_hires() - start_time);
boost::uint64_t hash_time = total_microseconds(clock_type::now() - start_time);
l.lock();
@ -2277,7 +2277,7 @@ namespace libtorrent
DLOG("do_hash: (uncached) reading (piece: %d block: %d)\n"
, int(j->piece), i);
ptime start_time = time_now_hires();
time_point start_time = clock_type::now();
iov.iov_len = (std::min)(block_size, piece_size - offset);
ret = j->storage->get_storage_impl()->readv(&iov, 1, j->piece
@ -2286,7 +2286,7 @@ namespace libtorrent
if (!j->error.ec)
{
boost::uint32_t read_time = total_microseconds(time_now_hires() - start_time);
boost::uint32_t read_time = total_microseconds(clock_type::now() - start_time);
m_read_time.add_sample(read_time);
m_stats_counters.inc_stats_counter(counters::num_blocks_read);
@ -2474,7 +2474,7 @@ namespace libtorrent
DLOG("do_hash: reading (piece: %d block: %d)\n", int(pe->piece), i);
ptime start_time = time_now_hires();
time_point start_time = clock_type::now();
TORRENT_PIECE_ASSERT(ph->offset == i * block_size, pe);
ret = j->storage->get_storage_impl()->readv(&iov, 1, j->piece
@ -2502,7 +2502,7 @@ namespace libtorrent
if (!j->error.ec)
{
boost::uint32_t read_time = total_microseconds(time_now_hires() - start_time);
boost::uint32_t read_time = total_microseconds(clock_type::now() - start_time);
m_read_time.add_sample(read_time);
m_stats_counters.inc_stats_counter(counters::num_read_back);
@ -2720,7 +2720,7 @@ namespace libtorrent
DLOG("do_cache_piece: reading (piece: %d block: %d)\n"
, int(pe->piece), i);
ptime start_time = time_now_hires();
time_point start_time = clock_type::now();
ret = j->storage->get_storage_impl()->readv(&iov, 1, j->piece
, offset, file_flags, j->error);
@ -2733,7 +2733,7 @@ namespace libtorrent
if (!j->error.ec)
{
boost::uint32_t read_time = total_microseconds(time_now_hires() - start_time);
boost::uint32_t read_time = total_microseconds(clock_type::now() - start_time);
m_read_time.add_sample(read_time);
m_stats_counters.inc_stats_counter(counters::num_blocks_read);
@ -3218,7 +3218,7 @@ namespace libtorrent
if (thread_id == 0)
{
// there's no need for all threads to be doing this
ptime now = time_now_hires();
time_point now = clock_type::now();
if (now > m_last_cache_expiry + seconds(5))
{
mutex::scoped_lock l2(m_cache_mutex);

View File

@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/file_pool.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/file_storage.hpp" // for file_entry
#include "libtorrent/aux_/time.hpp"
namespace libtorrent
{
@ -143,7 +144,7 @@ namespace libtorrent
if (i != m_files.end())
{
lru_file_entry& e = i->second;
e.last_use = time_now();
e.last_use = aux::time_now();
if (e.key != st && ((e.mode & file::rw_mask) != file::read_only
|| (m & file::rw_mask) != file::read_only))

View File

@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket_type.hpp" // for async_shutdown
#include "libtorrent/resolver_interface.hpp"
#include "libtorrent/settings_pack.hpp"
#include "libtorrent/aux_/time.hpp"
#if defined TORRENT_ASIO_DEBUGGING
#include "libtorrent/debug.hpp"
@ -75,8 +76,8 @@ http_connection::http_connection(io_service& ios
, m_filter_handler(fh)
, m_timer(ios)
, m_limiter_timer(ios)
, m_last_receive(time_now())
, m_start_time(time_now())
, m_last_receive(aux::time_now())
, m_start_time(aux::time_now())
, m_read_pos(0)
, m_redirects(5)
, m_max_bottled_buffer_size(max_bottled_buffer_size)
@ -414,7 +415,7 @@ void http_connection::on_timeout(boost::weak_ptr<http_connection> p
if (c->m_abort) return;
ptime now = time_now_hires();
time_point now = clock_type::now();
if (c->m_start_time + c->m_completion_timeout < now
|| c->m_last_receive + c->m_read_timeout < now)
@ -597,7 +598,7 @@ void http_connection::on_connect(error_code const& e)
TORRENT_ASSERT(m_connecting);
m_connecting = false;
m_last_receive = time_now_hires();
m_last_receive = clock_type::now();
m_start_time = m_last_receive;
if (!e)
{
@ -812,7 +813,7 @@ void http_connection::on_read(error_code const& e
callback(e, &m_recvbuffer[0] + m_parser.body_start()
, m_read_pos - m_parser.body_start());
m_read_pos = 0;
m_last_receive = time_now_hires();
m_last_receive = clock_type::now();
}
else if (m_bottled && m_parser.finished())
{
@ -826,7 +827,7 @@ void http_connection::on_read(error_code const& e
TORRENT_ASSERT(!m_bottled);
callback(e, &m_recvbuffer[0], m_read_pos);
m_read_pos = 0;
m_last_receive = time_now_hires();
m_last_receive = clock_type::now();
}
// if we've hit the limit, double the buffer size

View File

@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/broadcast_socket.hpp" // for is_any() etc.
#include "libtorrent/socket_io.hpp" // for hash_address
#include "libtorrent/random.hpp" // for random()
#include "libtorrent/time.hpp" // for time_now()
#include "libtorrent/aux_/time.hpp" // for aux::time_now()
#include <boost/bind.hpp>
@ -43,14 +43,14 @@ namespace libtorrent
ip_voter::ip_voter()
: m_total_votes(0)
, m_valid_external(false)
, m_last_rotate(time_now())
, m_last_rotate(aux::time_now())
{
}
// returns true if our external IP changed
bool ip_voter::maybe_rotate()
{
ptime now = time_now();
time_point now = aux::time_now();
// if we have more than or equal to 50 votes,
// we rotate. Also, if it's been more than 5 minutes

View File

@ -141,7 +141,7 @@ namespace libtorrent { namespace dht
, m_dht(&ses, this, settings, extract_node_id(state)
, ses.external_address().external_address(address_v4()), &ses, cnt)
, m_sock(sock)
, m_last_new_key(time_now() - minutes(int(key_refresh)))
, m_last_new_key(aux::time_now() - minutes(int(key_refresh)))
, m_timer(sock.get_io_service())
, m_connection_timer(sock.get_io_service())
, m_refresh_timer(sock.get_io_service())
@ -250,7 +250,7 @@ namespace libtorrent { namespace dht
m_timer.expires_from_now(minutes(tick_period), ec);
m_timer.async_wait(boost::bind(&dht_tracker::tick, self(), _1));
ptime now = time_now();
time_point now = aux::time_now();
if (now - minutes(int(key_refresh)) > m_last_new_key)
{
m_last_new_key = now;
@ -383,7 +383,7 @@ namespace libtorrent { namespace dht
return true;
}
if (!m_blocker.incoming(ep.address(), time_now()))
if (!m_blocker.incoming(ep.address(), aux::time_now()))
return true;
using libtorrent::entry;

View File

@ -54,7 +54,7 @@ namespace libtorrent { namespace dht
}
}
bool dos_blocker::incoming(address addr, ptime now)
bool dos_blocker::incoming(address addr, time_point now)
{
node_ban_entry* match = 0;
node_ban_entry* min = m_ban_nodes;

View File

@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/kademlia/logging.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/aux_/time.hpp"
namespace libtorrent { namespace dht
{
@ -39,7 +40,7 @@ namespace libtorrent { namespace dht
: log_(log)
{
if (log_.enabled())
log_ << time_now_string() << " [" << log.id() << "] ";
log_ << libtorrent::aux::time_now_string() << " [" << log.id() << "] ";
}
log_event::~log_event()

View File

@ -78,7 +78,7 @@ void purge_peers(std::set<peer_entry>& peers)
, end(peers.end()); i != end;)
{
// the peer has timed out
if (i->added + minutes(int(announce_interval * 1.5f)) < time_now())
if (i->added + minutes(int(announce_interval * 1.5f)) < aux::time_now())
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
TORRENT_LOG(node) << "peer timed out at: " << i->addr;
@ -102,7 +102,7 @@ node_impl::node_impl(alert_dispatcher* alert_disp
, m_table(m_id, 8, settings)
, m_rpc(m_id, m_table, sock)
, m_observer(observer)
, m_last_tracker_tick(time_now())
, m_last_tracker_tick(aux::time_now())
, m_last_self_refresh(min_time())
, m_post_alert(alert_disp)
, m_sock(sock)
@ -178,7 +178,7 @@ void node_impl::bootstrap(std::vector<udp::endpoint> const& nodes
make_id_secret(target);
boost::intrusive_ptr<dht::bootstrap> r(new dht::bootstrap(*this, target, f));
m_last_self_refresh = time_now();
m_last_self_refresh = aux::time_now();
#ifdef TORRENT_DHT_VERBOSE_LOGGING
int count = 0;
@ -453,7 +453,7 @@ void node_impl::tick()
{
// every now and then we refresh our own ID, just to keep
// expanding the routing table buckets closer to us.
ptime now = time_now();
time_point now = aux::time_now();
if (m_last_self_refresh + minutes(10) < now)
{
node_id target = m_id;
@ -521,7 +521,7 @@ void node_impl::send_single_refresh(udp::endpoint const& ep, int bucket
time_duration node_impl::connection_timeout()
{
time_duration d = m_rpc.tick();
ptime now(time_now());
time_point now(aux::time_now());
if (now - minutes(2) < m_last_tracker_tick) return d;
m_last_tracker_tick = now;
@ -1008,7 +1008,7 @@ void node_impl::incoming_request(msg const& m, entry& e)
peer_entry peer;
peer.addr = tcp::endpoint(m.addr.address(), port);
peer.added = time_now();
peer.added = aux::time_now();
peer.seed = msg_keys[4] && msg_keys[4]->int_value();
std::set<peer_entry>::iterator i = v->peers.find(peer);
if (i != v->peers.end()) v->peers.erase(i++);
@ -1231,7 +1231,7 @@ void node_impl::incoming_request(msg const& m, entry& e)
m_table.node_seen(id, m.addr, 0xffff);
f->last_seen = time_now();
f->last_seen = aux::time_now();
// maybe increase num_announcers if we haven't seen this IP before
sha1_hash iphash;

View File

@ -215,7 +215,7 @@ void routing_table::print_state(std::ostream& os) const
os << "\n";
}
ptime now = time_now();
time_point now = aux::time_now();
os << "\nnodes:";
int bucket_index = 0;
@ -366,7 +366,7 @@ out:
// make sure we don't pick the same node again next time we want to refresh
// the routing table
if (candidate)
candidate->last_queried = time_now();
candidate->last_queried = aux::time_now();
return candidate;
}
@ -988,7 +988,7 @@ void routing_table::node_failed(node_id const& nid, udp::endpoint const& ep)
" ip: " << j->ep() <<
" fails: " << j->fail_count() <<
" pinged: " << j->pinged() <<
" up-time: " << total_seconds(time_now() - j->first_seen);
" up-time: " << total_seconds(aux::time_now() - j->first_seen);
#endif
return;
}
@ -1008,7 +1008,7 @@ void routing_table::node_failed(node_id const& nid, udp::endpoint const& ep)
" ip: " << j->ep() <<
" fails: " << j->fail_count() <<
" pinged: " << j->pinged() <<
" up-time: " << total_seconds(time_now() - j->first_seen);
" up-time: " << total_seconds(aux::time_now() - j->first_seen);
#endif
// if this node has failed too many times, or if this node

View File

@ -85,9 +85,9 @@ void observer::set_target(udp::endpoint const& ep)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
// use high resolution timers for logging
m_sent = time_now_hires();
m_sent = clock_type::now();
#else
m_sent = time_now();
m_sent = aux::time_now();
#endif
m_port = ep.port();
@ -168,7 +168,7 @@ rpc_manager::rpc_manager(node_id const& our_id
: m_pool_allocator(observer_size, 10)
, m_sock(sock)
, m_table(table)
, m_timer(time_now())
, m_timer(aux::time_now())
, m_our_id(our_id)
, m_allocated_observers(0)
, m_destructing(false)
@ -316,7 +316,7 @@ bool rpc_manager::incoming(msg const& m, node_id* id, libtorrent::dht_settings c
return false;
}
ptime now = time_now_hires();
time_point now = clock_type::now();
#ifdef TORRENT_DHT_VERBOSE_LOGGING
std::ofstream reply_stats("round_trip_ms.log", std::ios::app);
@ -388,7 +388,7 @@ time_duration rpc_manager::tick()
std::vector<observer_ptr> short_timeouts;
time_duration ret = seconds(short_timeout);
ptime now = time_now();
time_point now = aux::time_now();
for (transactions_t::iterator i = m_transactions.begin();
i != m_transactions.end();)

View File

@ -503,7 +503,7 @@ void traversal_algorithm::status(dht_lookup& l)
l.first_timeout = 0;
int last_sent = INT_MAX;
ptime now = time_now();
time_point now = aux::time_now();
for (std::vector<observer_ptr>::iterator i = m_results.begin()
, end(m_results.end()); i != end; ++i)
{

View File

@ -227,7 +227,7 @@ namespace libtorrent { namespace
#ifdef TORRENT_LOGGING
std::stringstream log_line;
log_line << time_now_string() << " <== LT_TEX [ "
log_line << aux::time_now_string() << " <== LT_TEX [ "
"added: ";
#endif
@ -332,7 +332,7 @@ namespace libtorrent { namespace
#ifdef TORRENT_LOGGING
std::stringstream log_line;
log_line << time_now_string() << " ==> LT_TEX [ "
log_line << aux::time_now_string() << " ==> LT_TEX [ "
"added: ";
#endif
entry tex;

View File

@ -466,7 +466,7 @@ namespace libtorrent { namespace
}
break;
case 2: // have no data
m_no_metadata = time_now();
m_no_metadata = aux::time_now();
if (m_waiting_metadata_request)
m_tp.cancel_metadata_request(m_last_metadata_request);
m_waiting_metadata_request = false;
@ -498,13 +498,13 @@ namespace libtorrent { namespace
m_last_metadata_request = m_tp.metadata_request();
write_metadata_request(m_last_metadata_request);
m_waiting_metadata_request = true;
m_metadata_request = time_now();
m_metadata_request = aux::time_now();
}
}
bool has_metadata() const
{
return time_now() - minutes(5) > m_no_metadata;
return aux::time_now() - minutes(5) > m_no_metadata;
}
private:
@ -527,11 +527,11 @@ namespace libtorrent { namespace
// this is set to the current time each time we get a
// "I don't have metadata" message.
ptime m_no_metadata;
time_point m_no_metadata;
// this is set to the time when we last sent
// a request for metadata to this peer
ptime m_metadata_request;
time_point m_metadata_request;
// if we're waiting for a metadata request
// this was the request we sent

View File

@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/enum_net.hpp"
#include "libtorrent/socket_io.hpp"
#include "libtorrent/io_service.hpp"
//#include "libtorrent/random.hpp"
#include "libtorrent/aux_/time.hpp"
#if BOOST_VERSION < 103500
#include <asio/ip/host_name.hpp>
@ -233,7 +233,7 @@ int natpmp::add_mapping(protocol_type p, int external_port, int local_port)
int mapping_index = i - m_mappings.begin();
#ifdef NATPMP_LOG
ptime now = time_now();
time_point now = aux::time_now();
for (std::vector<mapping_t>::iterator m = m_mappings.begin()
, end(m_mappings.end()); m != end; ++m)
{
@ -254,7 +254,7 @@ int natpmp::add_mapping(protocol_type p, int external_port, int local_port)
void natpmp::try_next_mapping(int i, mutex::scoped_lock& l)
{
#ifdef NATPMP_LOG
ptime now = time_now();
time_point now = aux::time_now();
for (std::vector<mapping_t>::iterator m = m_mappings.begin()
, end(m_mappings.end()); m != end; ++m)
{
@ -399,7 +399,7 @@ void natpmp::resend_request(int i, error_code const& e)
m_currently_mapping = -1;
m_mappings[i].action = mapping_t::action_none;
// try again in two hours
m_mappings[i].expires = time_now() + hours(2);
m_mappings[i].expires = aux::time_now() + hours(2);
try_next_mapping(i, l);
return;
}
@ -543,7 +543,7 @@ void natpmp::on_reply(error_code const& e
}
else
{
m->expires = time_now() + seconds(int(lifetime * 0.7f));
m->expires = aux::time_now() + seconds(int(lifetime * 0.7f));
m->external_port = public_port;
}
@ -560,7 +560,7 @@ void natpmp::on_reply(error_code const& e
int ev = errors::no_error;
if (result >= 1 && result <= 5) ev = errors[result - 1];
m->expires = time_now() + hours(2);
m->expires = aux::time_now() + hours(2);
l.unlock();
m_callback(index, address(), 0, error_code(ev, get_libtorrent_category()));
l.lock();
@ -586,7 +586,7 @@ void natpmp::update_expiration_timer(mutex::scoped_lock& l)
{
if (m_abort) return;
ptime now = time_now() + milliseconds(100);
time_point now = aux::time_now() + milliseconds(100);
#ifdef NATPMP_LOG
std::cout << time_now_string() << " update_expiration_timer " << std::endl;
for (std::vector<mapping_t>::iterator i = m_mappings.begin()
@ -601,7 +601,7 @@ void natpmp::update_expiration_timer(mutex::scoped_lock& l)
<< " ]" << std::endl;
}
#endif
ptime min_expire = now + seconds(3600);
time_point min_expire = now + seconds(3600);
int min_index = -1;
for (std::vector<mapping_t>::iterator i = m_mappings.begin()
, end(m_mappings.end()); i != end; ++i)
@ -633,7 +633,7 @@ void natpmp::update_expiration_timer(mutex::scoped_lock& l)
#ifdef NATPMP_LOG
std::cout << time_now_string() << " next expiration ["
" i: " << min_index
<< " ttl: " << total_seconds(min_expire - time_now())
<< " ttl: " << total_seconds(min_expire - aux::time_now())
<< " ]" << std::endl;
#endif
error_code ec;
@ -675,7 +675,7 @@ void natpmp::close_impl(mutex::scoped_lock& l)
log("closing", l);
#ifdef NATPMP_LOG
std::cout << time_now_string() << " close" << std::endl;
ptime now = time_now();
time_point now = aux::time_now();
#endif
if (m_disabled) return;
for (std::vector<mapping_t>::iterator i = m_mappings.begin()

View File

@ -71,6 +71,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/ip_filter.hpp"
#include "libtorrent/kademlia/node_id.hpp"
#include "libtorrent/close_reason.hpp"
#include "libtorrent/aux_/time.hpp"
#ifdef TORRENT_DEBUG
#include <set>
@ -111,7 +112,7 @@ namespace libtorrent
// uint32_t length
char event[32];
char* ptr = event;
detail::write_uint64(time_now_hires().time_since_epoch().count(), ptr);
detail::write_uint64(clock_type::now().time_since_epoch().count(), ptr);
memcpy(ptr, &ih[0], 8);
ptr += 8;
detail::write_uint32(uintptr_t(p) & 0xffffffff, ptr);
@ -151,19 +152,19 @@ namespace libtorrent
, m_allocator(*pack.allocator)
, m_ios(*pack.ios)
, m_work(m_ios)
, m_last_piece(time_now())
, m_last_request(time_now())
, m_last_piece(aux::time_now())
, m_last_request(aux::time_now())
, m_last_incoming_request(min_time())
, m_last_unchoke(time_now())
, m_last_unchoked(time_now())
, m_last_unchoke(aux::time_now())
, m_last_unchoked(aux::time_now())
, m_last_choke(min_time())
, m_last_receive(time_now())
, m_last_sent(time_now())
, m_last_receive(aux::time_now())
, m_last_sent(aux::time_now())
, m_requested(min_time())
, m_remote_dl_update(time_now())
, m_connect(time_now())
, m_became_uninterested(time_now())
, m_became_uninteresting(time_now())
, m_remote_dl_update(aux::time_now())
, m_connect(aux::time_now())
, m_became_uninterested(aux::time_now())
, m_became_uninteresting(aux::time_now())
, m_downloaded_at_last_round(0)
, m_uploaded_at_last_round(0)
, m_uploaded_at_last_unchoke(0)
@ -416,7 +417,7 @@ namespace libtorrent
m_socket->async_connect(m_remote
, boost::bind(&peer_connection::on_connection_complete, self(), _1));
m_connect = time_now_hires();
m_connect = clock_type::now();
sent_syn(m_remote.address().is_v6());
@ -1000,11 +1001,11 @@ namespace libtorrent
// if we haven't received any data recently, the current download rate
// is not representative
if (time_now() - m_last_piece > seconds(30) && m_download_rate_peak > 0)
if (aux::time_now() - m_last_piece > seconds(30) && m_download_rate_peak > 0)
{
rate = m_download_rate_peak;
}
else if (time_now() - m_last_unchoked < seconds(5)
else if (aux::time_now() - m_last_unchoked < seconds(5)
&& m_statistics.total_payload_upload() < 2 * 0x4000)
{
// if we're have only been unchoked for a short period of time,
@ -1165,7 +1166,7 @@ namespace libtorrent
INVARIANT_CHECK;
#if defined TORRENT_LOGGING
m_connect_time = time_now_hires();
m_connect_time = clock_type::now();
peer_log("*** attached to torrent");
#endif
@ -1567,7 +1568,7 @@ namespace libtorrent
TORRENT_ASSERT(t);
#if defined TORRENT_LOGGING
m_unchoke_time = time_now_hires();
m_unchoke_time = clock_type::now();
t->debug_log("UNCHOKE [%p] (%d ms)", this, int(total_milliseconds(m_unchoke_time - m_bitfield_time)));
#endif
@ -1586,7 +1587,7 @@ namespace libtorrent
m_counters.inc_stats_counter(counters::num_peers_down_unchoked);
m_peer_choked = false;
m_last_unchoked = time_now();
m_last_unchoked = aux::time_now();
if (is_disconnecting()) return;
if (is_interesting())
@ -1717,7 +1718,7 @@ namespace libtorrent
}
#endif
m_became_uninterested = time_now();
m_became_uninterested = aux::time_now();
#if defined TORRENT_LOGGING
peer_log("<== NOT_INTERESTED");
@ -2025,7 +2026,7 @@ namespace libtorrent
m_bitfield_received = true;
#if defined TORRENT_LOGGING
m_bitfield_time = time_now_hires();
m_bitfield_time = clock_type::now();
t->debug_log("HANDSHAKE [%p] (%d ms)", this, int(total_milliseconds(m_bitfield_time - m_connect_time)));
#endif
// if we don't have metadata yet
@ -2337,7 +2338,7 @@ namespace libtorrent
// allow peers to send request up to 2 seconds after getting choked,
// then disconnect them
if (time_now() - seconds(2) > m_last_choke
if (aux::time_now() - seconds(2) > m_last_choke
&& can_disconnect(error_code(errors::too_many_requests_when_choked, get_libtorrent_category())))
{
disconnect(errors::too_many_requests_when_choked, op_bittorrent, 2);
@ -2359,7 +2360,7 @@ namespace libtorrent
if (log)
write_request_log(log, t->info_hash(), this, r);
#endif
m_last_incoming_request = time_now();
m_last_incoming_request = aux::time_now();
fill_send_buffer();
}
}
@ -2384,7 +2385,7 @@ namespace libtorrent
void peer_connection::incoming_piece_fragment(int bytes)
{
TORRENT_ASSERT(is_single_thread());
m_last_piece = time_now();
m_last_piece = aux::time_now();
TORRENT_ASSERT(m_outstanding_bytes >= bytes);
m_outstanding_bytes -= bytes;
if (m_outstanding_bytes < 0) m_outstanding_bytes = 0;
@ -2629,7 +2630,7 @@ namespace libtorrent
return;
}
ptime now = time_now_hires();
time_point now = clock_type::now();
t->need_picker();
@ -2727,7 +2728,7 @@ namespace libtorrent
#if defined TORRENT_LOGGING
t->debug_log("PIECE [%p] (%d ms) (%d)", this
, int(total_milliseconds(time_now_hires() - m_unchoke_time)), t->num_have());
, int(total_milliseconds(clock_type::now() - m_unchoke_time)), t->num_have());
peer_log("*** FILE ASYNC WRITE [ piece: %d | s: %x | l: %x ]"
, p.piece, p.start, p.length);
@ -3064,7 +3065,7 @@ namespace libtorrent
m_bitfield_received = true;
#if defined TORRENT_LOGGING
m_bitfield_time = time_now_hires();
m_bitfield_time = clock_type::now();
t->debug_log("HANDSHAKE [%p] (%d ms)", this, int(total_milliseconds(m_bitfield_time - m_connect_time)));
#endif
@ -3136,7 +3137,7 @@ namespace libtorrent
m_bitfield_received = true;
#if defined TORRENT_LOGGING
m_bitfield_time = time_now_hires();
m_bitfield_time = clock_type::now();
t->debug_log("HANDSHAKE [%p] (%d ms)", this, int(total_milliseconds(m_bitfield_time - m_connect_time)));
#endif
m_have_piece.clear_all();
@ -3166,7 +3167,7 @@ namespace libtorrent
#if defined TORRENT_LOGGING
{
ptime now = time_now_hires();
time_point now = clock_type::now();
t->debug_log("ALLOW FAST [%p] (%d ms)", this, int(total_milliseconds(now - m_connect_time)));
if (m_peer_choked) m_unchoke_time = now;
}
@ -3526,7 +3527,7 @@ namespace libtorrent
m_counters.inc_stats_counter(counters::num_peers_up_unchoked, -1);
m_choked = true;
m_last_choke = time_now();
m_last_choke = aux::time_now();
m_num_invalid_requests = 0;
// reject the requests we have in the queue
@ -3582,7 +3583,7 @@ namespace libtorrent
m_sent_suggests = true;
}
m_last_unchoke = time_now();
m_last_unchoke = aux::time_now();
write_unchoke();
m_counters.inc_stats_counter(counters::num_peers_up_unchoked_all);
if (!ignore_unchoke_slots())
@ -3635,7 +3636,7 @@ namespace libtorrent
write_not_interested();
m_became_uninteresting = time_now();
m_became_uninteresting = aux::time_now();
#if defined TORRENT_LOGGING
peer_log("==> NOT_INTERESTED");
@ -3811,7 +3812,7 @@ namespace libtorrent
#endif
{
write_request(r);
m_last_request = time_now();
m_last_request = aux::time_now();
}
#if defined TORRENT_LOGGING
@ -3822,7 +3823,7 @@ namespace libtorrent
, m_request_large_blocks?"large":"single");
#endif
}
m_last_piece = time_now();
m_last_piece = aux::time_now();
if (!m_download_queue.empty()
&& empty_download_queue)
@ -3830,10 +3831,10 @@ namespace libtorrent
// This means we just added a request to this connection that
// previously did not have a request. That's when we start the
// request timeout.
m_requested = time_now();
m_requested = aux::time_now();
#if defined TORRENT_LOGGING
t->debug_log("REQUEST [%p] (%d ms)", this
, int(total_milliseconds(time_now_hires() - m_unchoke_time)));
, int(total_milliseconds(clock_type::now() - m_unchoke_time)));
#endif
}
}
@ -4225,7 +4226,7 @@ namespace libtorrent
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(!associated_torrent().expired());
ptime now = time_now();
time_point now = aux::time_now();
p.download_rate_peak = m_download_rate_peak;
p.upload_rate_peak = m_upload_rate_peak;
@ -4485,7 +4486,7 @@ namespace libtorrent
void peer_connection::second_tick(int tick_interval_ms)
{
TORRENT_ASSERT(is_single_thread());
ptime now = time_now();
time_point now = aux::time_now();
boost::shared_ptr<peer_connection> me(self());
// the invariant check must be run before me is destructed
@ -4984,7 +4985,7 @@ namespace libtorrent
t->inc_refcount("async_read");
m_disk_thread.async_read(&t->storage(), r
, boost::bind(&peer_connection::on_disk_read_complete
, self(), _1, r, time_now_hires()), this);
, self(), _1, r, clock_type::now()), this);
}
m_requests.erase(m_requests.begin() + i);
@ -5054,14 +5055,14 @@ namespace libtorrent
}
void peer_connection::on_disk_read_complete(disk_io_job const* j
, peer_request r, ptime issue_time)
, peer_request r, time_point issue_time)
{
TORRENT_ASSERT(is_single_thread());
// return value:
// 0: success, piece passed hash check
// -1: disk failure
int disk_rtt = int(total_microseconds(time_now_hires() - issue_time));
int disk_rtt = int(total_microseconds(clock_type::now() - issue_time));
#if defined TORRENT_LOGGING
peer_log("*** FILE ASYNC READ COMPLETE [ ret: %d | piece: %d | s: %x | l: %x"
@ -5960,7 +5961,7 @@ namespace libtorrent
}
while (bytes_transferred > 0);
m_last_receive = time_now();
m_last_receive = aux::time_now();
if (is_seed())
{
@ -6041,7 +6042,7 @@ namespace libtorrent
#endif
#if defined TORRENT_LOGGING || defined TORRENT_USE_OPENSSL
ptime completed = time_now_hires();
time_point completed = clock_type::now();
#endif
INVARIANT_CHECK;
@ -6085,7 +6086,7 @@ namespace libtorrent
m_counters.inc_stats_counter(counters::num_peers_connected);
if (m_disconnecting) return;
m_last_receive = time_now();
m_last_receive = aux::time_now();
error_code ec;
m_local = m_socket->local_endpoint(ec);
@ -6217,7 +6218,7 @@ namespace libtorrent
m_send_buffer.pop_front(bytes_transferred);
ptime now = time_now_hires();
time_point now = clock_type::now();
for (std::vector<pending_block>::iterator i = m_download_queue.begin()
, end(m_download_queue.end()); i != end; ++i)
@ -6554,7 +6555,7 @@ namespace libtorrent
#endif
time_duration d;
d = time_now() - m_last_sent;
d = aux::time_now() - m_last_sent;
if (total_seconds(d) < timeout() / 2) return;
if (m_connecting) return;
@ -6568,7 +6569,7 @@ namespace libtorrent
peer_log("==> KEEPALIVE");
#endif
m_last_sent = time_now();
m_last_sent = aux::time_now();
write_keepalive();
}

View File

@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/resolver.hpp"
#include <boost/bind.hpp>
#include "libtorrent/debug.hpp"
#include "libtorrent/aux_/time.hpp"
namespace libtorrent
{
@ -58,7 +59,7 @@ namespace libtorrent
}
dns_cache_entry& ce = m_cache[hostname];
ptime now = time_now();
time_point now = aux::time_now();
ce.last_seen = now;
ce.addresses.clear();
while (i != tcp::resolver::iterator())
@ -95,7 +96,7 @@ namespace libtorrent
{
// keep cache entries valid for m_timeout seconds
if ((flags & resolver_interface::prefer_cache)
|| i->second.last_seen + m_timeout >= time_now())
|| i->second.last_seen + m_timeout >= aux::time_now())
{
error_code ec;
m_ios.post(boost::bind(h, ec, i->second.addresses));

View File

@ -383,7 +383,7 @@ namespace aux {
, m_suggest_timer(0)
, m_peak_up_rate(0)
, m_peak_down_rate(0)
, m_created(time_now_hires())
, m_created(clock_type::now())
, m_last_tick(m_created)
, m_last_second_tick(m_created - milliseconds(900))
, m_last_choke(m_created)
@ -2360,7 +2360,7 @@ retry:
#ifdef TORRENT_USE_OPENSSL
// add the current time to the PRNG, to add more unpredictability
boost::uint64_t now = time_now_hires().time_since_epoch().count();
boost::uint64_t now = clock_type::now().time_since_epoch().count();
// assume 12 bits of entropy (i.e. about 8 milliseconds)
RAND_add(&now, 8, 1.5);
#endif
@ -2694,11 +2694,11 @@ retry:
// than a system call and can be
// used where more accurate time
// is not necessary
extern ptime g_current_time;
extern time_point g_current_time;
initialize_timer::initialize_timer()
{
g_current_time = time_now_hires();
g_current_time = clock_type::now();
}
int session_impl::rate_limit(peer_class_t c, int channel) const
@ -2810,7 +2810,7 @@ retry:
// submit all disk jobs when we leave this function
deferred_submit_jobs();
ptime now = time_now_hires();
time_point now = clock_type::now();
aux::g_current_time = now;
// too expensive
// INVARIANT_CHECK;
@ -3252,8 +3252,8 @@ retry:
void session_impl::update_rss_feeds()
{
time_t now_posix = time(0);
ptime min_update = max_time();
ptime now = time_now();
time_point min_update = max_time();
time_point now = aux::time_now();
for (std::vector<boost::shared_ptr<feed> >::iterator i
= m_feeds.begin(), end(m_feeds.end()); i != end; ++i)
{
@ -3262,7 +3262,7 @@ retry:
if (delta <= 0)
delta = f.update_feed();
TORRENT_ASSERT(delta >= 0);
ptime next_update = now + seconds(delta);
time_point next_update = now + seconds(delta);
if (next_update < min_update) min_update = next_update;
}
m_next_rss_update = min_update;
@ -3854,7 +3854,7 @@ retry:
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
ptime now = time_now();
time_point now = aux::time_now();
time_duration unchoke_interval = now - m_last_choke;
m_last_choke = now;
@ -4378,7 +4378,7 @@ retry:
for (int i = 0; i < counters::num_counters; ++i)
values[i] = m_stats_counters[i];
alert->timestamp = total_microseconds(time_now_hires() - m_created);
alert->timestamp = total_microseconds(clock_type::now() - m_created);
m_alerts.post_alert_ptr(alert.release());
}
@ -5628,9 +5628,9 @@ retry:
FILE* f = fopen("wakeups.log", "w+");
if (f != NULL)
{
ptime m = min_time();
time_point m = min_time();
if (_wakeups.size() > 0) m = _wakeups[0].timestamp;
ptime prev = m;
time_point prev = m;
boost::uint64_t prev_csw = 0;
if (_wakeups.size() > 0) prev_csw = _wakeups[0].context_switches;
fprintf(f, "abs. time\trel. time\tctx switch\tidle-wakeup\toperation\n");

View File

@ -115,7 +115,7 @@ namespace libtorrent
op_end = 2
};
void write_access_log(boost::uint64_t offset, boost::uint32_t fileid, int flags, ptime timestamp)
void write_access_log(boost::uint64_t offset, boost::uint32_t fileid, int flags, time_point timestamp)
{
if (g_access_log == NULL) return;
@ -1201,7 +1201,7 @@ namespace libtorrent
#ifdef TORRENT_DISK_STATS
int flags = ((op.mode & file::rw_mask) == file::read_only) ? op_read : op_write;
write_access_log(adjusted_offset, handle->file_id(), op_start | flags, time_now_hires());
write_access_log(adjusted_offset, handle->file_id(), op_start | flags, clock_type::now());
#endif
bytes_transferred = (int)((*handle).*op.op)(adjusted_offset
@ -1211,7 +1211,7 @@ namespace libtorrent
TORRENT_ASSERT(e || bytes_transferred >= 0);
#ifdef TORRENT_DISK_STATS
write_access_log(adjusted_offset + bytes_transferred, handle->file_id(), op_end | flags, time_now_hires());
write_access_log(adjusted_offset + bytes_transferred, handle->file_id(), op_end | flags, clock_type::now());
#endif
TORRENT_ASSERT(bytes_transferred <= bufs_size(tmp_bufs, num_tmp_bufs));
}

View File

@ -42,25 +42,22 @@ POSSIBILITY OF SUCH DAMAGE.
#include <unistd.h>
#endif
namespace libtorrent
namespace libtorrent { namespace aux
{
namespace aux
{
// used to cache the current time
// every 100 ms. This is cheaper
// than a system call and can be
// used where more accurate time
// is not necessary
ptime g_current_time;
}
// used to cache the current time
// every 100 ms. This is cheaper
// than a system call and can be
// used where more accurate time
// is not necessary
time_point g_current_time;
TORRENT_EXPORT ptime const& time_now() { return aux::g_current_time; }
time_point const& time_now() { return aux::g_current_time; }
TORRENT_EXTRA_EXPORT char const* time_now_string()
{
static const ptime start = time_now_hires();
static const time_point start = clock_type::now();
static char ret[200];
int t = total_milliseconds(time_now_hires() - start);
int t = total_milliseconds(clock_type::now() - start);
int h = t / 1000 / 60 / 60;
t -= h * 60 * 60 * 1000;
int m = t / 1000 / 60;
@ -74,10 +71,10 @@ namespace libtorrent
std::string log_time()
{
static const ptime start = time_now_hires();
static const time_point start = clock_type::now();
char ret[200];
snprintf(ret, sizeof(ret), "%" PRId64, total_microseconds(time_now_hires() - start));
snprintf(ret, sizeof(ret), "%" PRId64, total_microseconds(clock_type::now() - start));
return ret;
}
}
} }

View File

@ -124,7 +124,7 @@ namespace libtorrent
web_seed_t::web_seed_t(web_seed_entry const& wse)
: web_seed_entry(wse)
, retry(time_now())
, retry(aux::time_now())
, peer_info(tcp::endpoint(), true, 0)
, supports_keepalive(true)
, resolving(false)
@ -138,7 +138,7 @@ namespace libtorrent
, std::string const& auth_
, web_seed_entry::headers_t const& extra_headers_)
: web_seed_entry(url_, type_, auth_, extra_headers_)
, retry(time_now())
, retry(aux::time_now())
, peer_info(tcp::endpoint(), true, 0)
, supports_keepalive(true)
, resolving(false)
@ -1551,7 +1551,7 @@ namespace libtorrent
// this is needed for openssl < 1.0 to decrypt keys created by openssl 1.0+
OpenSSL_add_all_algorithms();
boost::uint64_t now = time_now_hires().time_since_epoch().count();
boost::uint64_t now = clock_type::now().time_since_epoch().count();
// assume 9 bits of entropy (i.e. about 1 millisecond)
RAND_add(&now, 8, 1.125);
RAND_add(&info_hash()[0], 20, 3);
@ -2805,7 +2805,7 @@ namespace libtorrent
#if defined TORRENT_LOGGING
debug_log("START DHT announce");
m_dht_start_time = time_now_hires();
m_dht_start_time = clock_type::now();
#endif
// if we're a seed, we tell the DHT for better scrape stats
@ -2837,7 +2837,7 @@ namespace libtorrent
#if defined TORRENT_LOGGING
debug_log("END DHT announce (%d ms) (%d peers)"
, int(total_milliseconds(time_now_hires() - m_dht_start_time))
, int(total_milliseconds(clock_type::now() - m_dht_start_time))
, int(peers.size()));
#endif
@ -2930,7 +2930,7 @@ namespace libtorrent
req.num_want = (req.event == tracker_request::stopped)
?0:settings().get_int(settings_pack::num_want);
ptime now = time_now_hires();
time_point now = clock_type::now();
// the tier is kept as INT_MAX until we find the first
// tracker that works, then it's set to that tracker's
@ -3167,7 +3167,7 @@ namespace libtorrent
, aux::session_interface::source_tracker
, *tracker_ips.begin());
ptime now = time_now();
time_point now = aux::time_now();
int interval = resp.interval;
if (interval < settings().get_int(settings_pack::min_announce_interval))
@ -3440,12 +3440,12 @@ namespace libtorrent
if (want_peers()) m_ses.prioritize_connections(shared_from_this());
}
ptime torrent::next_announce() const
time_point torrent::next_announce() const
{
return m_waiting_tracker?m_tracker_timer.expires_at():min_time();
}
void torrent::force_tracker_request(ptime t, int tracker_idx)
void torrent::force_tracker_request(time_point t, int tracker_idx)
{
if (is_paused()) return;
if (tracker_idx == -1)
@ -3462,7 +3462,7 @@ namespace libtorrent
announce_entry& e = m_trackers[tracker_idx];
e.next_announce = (std::max)(t, e.min_announce) + seconds(1);
}
update_tracker_timer(time_now_hires());
update_tracker_timer(clock_type::now());
}
void torrent::set_tracker_login(
@ -4939,7 +4939,7 @@ namespace libtorrent
return;
}
ptime deadline = time_now() + milliseconds(t);
time_point deadline = aux::time_now() + milliseconds(t);
// if we already have the piece, no need to set the deadline.
// however, if the user asked to get the piece data back, we still
@ -5049,7 +5049,7 @@ namespace libtorrent
{
// update the average download time and average
// download time deviation
int dl_time = total_milliseconds(time_now() - i->first_requested);
int dl_time = total_milliseconds(aux::time_now() - i->first_requested);
if (m_average_piece_time == 0)
{
@ -6177,7 +6177,7 @@ namespace libtorrent
#endif
// unavailable, retry in 30 minutes
web->retry = time_now() + minutes(30);
web->retry = aux::time_now() + minutes(30);
return;
}
@ -7891,7 +7891,7 @@ namespace libtorrent
boost::int64_t lhs_transferred = lhs->statistics().total_payload_download();
boost::int64_t rhs_transferred = rhs->statistics().total_payload_download();
ptime now = time_now();
time_point now = aux::time_now();
boost::int64_t lhs_time_connected = total_seconds(now - lhs->connected_time());
boost::int64_t rhs_time_connected = total_seconds(now - rhs->connected_time());
@ -8068,7 +8068,7 @@ namespace libtorrent
std::vector<boost::uint64_t>().swap(m_file_progress);
if (!m_announcing) return;
ptime now = time_now();
time_point now = aux::time_now();
for (std::vector<announce_entry>::iterator i = m_trackers.begin()
, end(m_trackers.end()); i != end; ++i)
{
@ -9329,7 +9329,7 @@ namespace libtorrent
do_connect_boost();
}
void torrent::update_tracker_timer(ptime now)
void torrent::update_tracker_timer(time_point now)
{
TORRENT_ASSERT(is_single_thread());
if (!m_announcing)
@ -9340,7 +9340,7 @@ namespace libtorrent
return;
}
ptime next_announce = max_time();
time_point next_announce = max_time();
int tier = INT_MAX;
bool found_working = false;
@ -9375,7 +9375,7 @@ namespace libtorrent
}
else
{
ptime next_tracker_announce = (std::max)(i->next_announce, i->min_announce);
time_point next_tracker_announce = (std::max)(i->next_announce, i->min_announce);
if (next_tracker_announce < next_announce
&& (!found_working || i->is_working()))
next_announce = next_tracker_announce;
@ -9481,7 +9481,7 @@ namespace libtorrent
m_announcing = false;
ptime now = time_now();
time_point now = aux::time_now();
for (std::vector<announce_entry>::iterator i = m_trackers.begin()
, end(m_trackers.end()); i != end; ++i)
{
@ -9754,7 +9754,7 @@ namespace libtorrent
{
std::list<web_seed_t>::iterator w = i++;
if (w->peer_info.connection) continue;
if (w->retry > time_now()) continue;
if (w->retry > aux::time_now()) continue;
if (w->resolving) continue;
connect_to_url_seed(w);
@ -10073,7 +10073,7 @@ namespace libtorrent
{
using namespace libtorrent;
ptime now = time_now_hires();
time_point now = clock_type::now();
float deadline = 0.f;
float last_request = 0.f;
@ -10211,7 +10211,7 @@ namespace libtorrent
std::vector<piece_block> backup2;
std::vector<int> ignore;
ptime now = time_now();
time_point now = aux::time_now();
// loop until every block has been requested from this piece (i->piece)
do
@ -10434,7 +10434,7 @@ namespace libtorrent
// piece is done
std::vector<peer_connection*> ignore_peers;
ptime now = time_now_hires();
time_point now = clock_type::now();
// now, iterate over all time critical pieces, in order of importance, and
// request them from the peers, in order of responsiveness. i.e. request
@ -10634,7 +10634,7 @@ namespace libtorrent
TORRENT_ASSERT(i != m_web_seeds.end());
if (i == m_web_seeds.end()) return;
if (retry == 0) retry = m_ses.settings().get_int(settings_pack::urlseed_wait_retry);
i->retry = time_now() + seconds(retry);
i->retry = aux::time_now() + seconds(retry);
}
torrent_state torrent::get_policy_state()
@ -11246,7 +11246,7 @@ namespace libtorrent
{
INVARIANT_CHECK;
ptime now = time_now();
time_point now = aux::time_now();
st->handle = get_handle();
st->info_hash = info_hash();
@ -11557,7 +11557,7 @@ namespace libtorrent
// announce to the next working tracker
if ((!m_abort && !is_paused()) || r.event == tracker_request::stopped)
announce_with_tracker(r.event);
update_tracker_timer(time_now());
update_tracker_timer(aux::time_now());
}
#if defined TORRENT_LOGGING

View File

@ -747,7 +747,7 @@ namespace libtorrent
void torrent_handle::force_reannounce(
boost::posix_time::time_duration duration) const
{
TORRENT_ASYNC_CALL2(force_tracker_request, time_now()
TORRENT_ASYNC_CALL2(force_tracker_request, aux::time_now()
+ seconds(duration.total_seconds()), -1);
}
#endif
@ -761,7 +761,7 @@ namespace libtorrent
void torrent_handle::force_reannounce(int s, int idx) const
{
TORRENT_ASYNC_CALL2(force_tracker_request, time_now() + seconds(s), idx);
TORRENT_ASYNC_CALL2(force_tracker_request, aux::time_now() + seconds(s), idx);
}
void torrent_handle::file_status(std::vector<pool_file_status>& status) const

View File

@ -659,10 +659,10 @@ namespace libtorrent
announce_entry::~announce_entry() {}
int announce_entry::next_announce_in() const
{ return total_seconds(next_announce - time_now()); }
{ return total_seconds(next_announce - aux::time_now()); }
int announce_entry::min_announce_in() const
{ return total_seconds(min_announce - time_now()); }
{ return total_seconds(min_announce - aux::time_now()); }
void announce_entry::reset()
{
@ -681,11 +681,11 @@ namespace libtorrent
* tracker_retry_delay_min * sett.get_int(settings_pack::tracker_backoff) / 100
, int(tracker_retry_delay_max));
delay = (std::max)(delay, retry_interval);
next_announce = time_now() + seconds(delay);
next_announce = aux::time_now() + seconds(delay);
updating = false;
}
bool announce_entry::can_announce(ptime now, bool is_seed) const
bool announce_entry::can_announce(time_point now, bool is_seed) const
{
// if we're a seed and we haven't sent a completed
// event, we need to let this announce through

View File

@ -58,7 +58,7 @@ namespace libtorrent
{
timeout_handler::timeout_handler(io_service& ios)
: m_completion_timeout(0)
, m_start_time(time_now_hires())
, m_start_time(clock_type::now())
, m_read_time(m_start_time)
, m_timeout(ios)
, m_read_timeout(0)
@ -69,7 +69,7 @@ namespace libtorrent
{
m_completion_timeout = completion_timeout;
m_read_timeout = read_timeout;
m_start_time = m_read_time = time_now_hires();
m_start_time = m_read_time = clock_type::now();
TORRENT_ASSERT(completion_timeout > 0 || read_timeout > 0);
@ -95,7 +95,7 @@ namespace libtorrent
void timeout_handler::restart_read_timeout()
{
m_read_time = time_now_hires();
m_read_time = clock_type::now();
}
void timeout_handler::cancel()
@ -113,7 +113,7 @@ namespace libtorrent
#endif
if (m_abort) return;
ptime now = time_now_hires();
time_point now = clock_type::now();
time_duration receive_timeout = now - m_read_time;
time_duration completion_timeout = now - m_start_time;

View File

@ -39,6 +39,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/string_util.hpp" // for allocate_string_copy
#include "libtorrent/broadcast_socket.hpp" // for is_any
#include "libtorrent/settings_pack.hpp"
#include "libtorrent/aux_/time.hpp" // for aux::time_now()
#include <stdlib.h>
#include <boost/bind.hpp>
#include <boost/array.hpp>
@ -1332,13 +1334,13 @@ rate_limited_udp_socket::rate_limited_udp_socket(io_service& ios)
: udp_socket(ios)
, m_rate_limit(8000)
, m_quota(8000)
, m_last_tick(time_now())
, m_last_tick(aux::time_now())
{
}
bool rate_limited_udp_socket::has_quota()
{
ptime now = time_now_hires();
time_point now = clock_type::now();
time_duration delta = now - m_last_tick;
m_last_tick = now;
// add any new quota we've accrued since last time
@ -1349,7 +1351,7 @@ bool rate_limited_udp_socket::has_quota()
bool rate_limited_udp_socket::send(udp::endpoint const& ep, char const* p
, int len, error_code& ec, int flags)
{
ptime now = time_now_hires();
time_point now = clock_type::now();
time_duration delta = now - m_last_tick;
m_last_tick = now;

View File

@ -54,6 +54,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/session_settings.hpp"
#include "libtorrent/resolver_interface.hpp"
#include "libtorrent/ip_filter.hpp"
#include "libtorrent/aux_/time.hpp"
#if defined TORRENT_LOGGING
#include "libtorrent/socket_io.hpp"
@ -289,7 +290,7 @@ namespace libtorrent
{
// we found a cached entry! Now, we can only
// use if if it hasn't expired
if (time_now() < cc->second.expires)
if (aux::time_now() < cc->second.expires)
{
if (tracker_req().kind == tracker_request::announce_request)
send_udp_announce();
@ -468,7 +469,7 @@ namespace libtorrent
mutex::scoped_lock l(m_cache_mutex);
connection_cache_entry& cce = m_connection_cache[m_target.address()];
cce.connection_id = connection_id;
cce.expires = time_now() + seconds(m_man.settings().get_int(settings_pack::udp_tracker_token_expiry));
cce.expires = aux::time_now() + seconds(m_man.settings().get_int(settings_pack::udp_tracker_token_expiry));
if (tracker_req().kind == tracker_request::announce_request)
send_udp_announce();

View File

@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/enum_net.hpp"
#include "libtorrent/escape_string.hpp"
#include "libtorrent/random.hpp"
#include "libtorrent/aux_/time.hpp" // for aux::time_now()
#if defined TORRENT_ASIO_DEBUGGING
#include "libtorrent/debug.hpp"
@ -366,7 +367,7 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
*/
error_code ec;
if (time_now_hires() - seconds(60) > m_last_if_update)
if (clock_type::now() - seconds(60) > m_last_if_update)
{
m_interfaces = enum_net_interfaces(m_io_service, ec);
if (ec)
@ -376,7 +377,7 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
, print_endpoint(from).c_str(), convert_from_native(ec.message()).c_str());
log(msg, l);
}
m_last_if_update = time_now();
m_last_if_update = aux::time_now();
}
if (!ec && !in_local_network(m_interfaces, from.address()))
@ -1431,10 +1432,10 @@ void upnp::on_upnp_map_response(error_code const& e
l.lock();
if (d.lease_duration > 0)
{
m.expires = time_now()
m.expires = aux::time_now()
+ seconds(int(d.lease_duration * 0.75f));
ptime next_expire = m_refresh_timer.expires_at();
if (next_expire < time_now()
time_point next_expire = m_refresh_timer.expires_at();
if (next_expire < aux::time_now()
|| next_expire > m.expires)
{
#if defined TORRENT_ASIO_DEBUGGING
@ -1540,8 +1541,8 @@ void upnp::on_expire(error_code const& ec)
#endif
if (ec) return;
ptime now = time_now();
ptime next_expire = max_time();
time_point now = aux::time_now();
time_point next_expire = max_time();
mutex::scoped_lock l(m_mutex);

View File

@ -196,7 +196,7 @@ namespace libtorrent { namespace
{
metadata_piece(): num_requests(0), last_request(min_time()) {}
int num_requests;
ptime last_request;
time_point last_request;
boost::weak_ptr<ut_metadata_peer_plugin> source;
bool operator<(metadata_piece const& rhs) const
{ return num_requests < rhs.num_requests; }
@ -410,7 +410,7 @@ namespace libtorrent { namespace
break;
case 2: // have no data
{
m_request_limit = (std::max)(time_now() + minutes(1), m_request_limit);
m_request_limit = (std::max)(aux::time_now() + minutes(1), m_request_limit);
std::vector<int>::iterator i = std::find(m_sent_requests.begin()
, m_sent_requests.end(), piece);
// unwanted piece?
@ -463,10 +463,10 @@ namespace libtorrent { namespace
bool has_metadata() const
{
return m_pc.has_metadata() || (time_now() > m_request_limit);
return m_pc.has_metadata() || (aux::time_now() > m_request_limit);
}
void failed_hash_check(ptime const& now)
void failed_hash_check(time_point const& now)
{
m_request_limit = now + seconds(20 + (boost::int64_t(random()) * 50) / UINT_MAX);
}
@ -481,7 +481,7 @@ namespace libtorrent { namespace
// again. It is updated every time we get a
// "I don't have metadata" message, but also when
// we receive metadata that fails the infohash check
ptime m_request_limit;
time_point m_request_limit;
// request queues
std::vector<int> m_sent_requests;
@ -521,7 +521,7 @@ namespace libtorrent { namespace
int piece = i - m_requested_metadata.begin();
// don't request the same block more than once every 3 seconds
ptime now = time_now();
time_point now = aux::time_now();
if (m_requested_metadata[piece].last_request != min_time()
&& total_seconds(now - m_requested_metadata[piece].last_request) < 3)
return -1;
@ -606,7 +606,7 @@ namespace libtorrent { namespace
{
if (!m_torrent.valid_metadata())
{
ptime now = time_now();
time_point now = aux::time_now();
// any peer that we downloaded metadata from gets a random time
// penalty, from 5 to 30 seconds or so. During this time we don't
// make any metadata requests from those peers (to mix it up a bit

View File

@ -112,7 +112,7 @@ namespace libtorrent { namespace
// max_peer_entries limits the packet size
virtual void tick()
{
ptime now = time_now();
time_point now = aux::time_now();
if (now - seconds(60) < m_last_msg) return;
m_last_msg = now;
@ -229,7 +229,7 @@ namespace libtorrent { namespace
torrent& m_torrent;
std::set<tcp::endpoint> m_old_peers;
ptime m_last_msg;
time_point m_last_msg;
std::vector<char> m_ut_pex_msg;
int m_peers_in_message;
};
@ -286,7 +286,7 @@ namespace libtorrent { namespace
if (body.left() < length) return true;
ptime now = time_now();
time_point now = aux::time_now();
if (now - seconds(60) < m_last_pex[0])
{
// this client appears to be trying to flood us
@ -433,7 +433,7 @@ namespace libtorrent { namespace
// no handshake yet
if (!m_message_index) return;
ptime now = time_now();
time_point now = aux::time_now();
if (now - seconds(60) < m_last_msg)
{
#ifdef TORRENT_LOGGING
@ -442,7 +442,7 @@ namespace libtorrent { namespace
#endif
return;
}
static ptime global_last = min_time();
static time_point global_last = min_time();
int num_peers = m_torrent.num_peers();
if (num_peers <= 1) return;
@ -636,9 +636,9 @@ namespace libtorrent { namespace
// then once we read from the socket it will look like
// we received them all back to back. That's why
// we look at 6 pex messages back.
ptime m_last_pex[6];
time_point m_last_pex[6];
ptime m_last_msg;
time_point m_last_msg;
int m_message_index;
// this is initialized to true, and set to

View File

@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/broadcast_socket.hpp" // for is_teredo
#include "libtorrent/random.hpp"
#include "libtorrent/performance_counters.hpp"
#include "libtorrent/aux_/time.hpp" // for aux::time_now()
// #define TORRENT_DEBUG_MTU 1135
@ -70,7 +71,7 @@ namespace libtorrent
}
}
void utp_socket_manager::tick(ptime now)
void utp_socket_manager::tick(time_point now)
{
for (socket_map_t::iterator i = m_utp_sockets.begin()
, end(m_utp_sockets.end()); i != end;)
@ -89,9 +90,9 @@ namespace libtorrent
void utp_socket_manager::mtu_for_dest(address const& addr, int& link_mtu, int& utp_mtu)
{
if (time_now() - seconds(60) > m_last_route_update)
if (aux::time_now() - seconds(60) > m_last_route_update)
{
m_last_route_update = time_now();
m_last_route_update = aux::time_now();
error_code ec;
m_routes = enum_routes(m_sock.get_io_service(), ec);
}
@ -198,9 +199,9 @@ namespace libtorrent
tcp::endpoint socket_ep = m_sock.local_endpoint(ec);
// first enumerate the routes in the routing table
if (time_now() - seconds(60) > m_last_route_update)
if (aux::time_now() - seconds(60) > m_last_route_update)
{
m_last_route_update = time_now();
m_last_route_update = aux::time_now();
error_code ec;
m_routes = enum_routes(m_sock.get_io_service(), ec);
if (ec) return socket_ep;
@ -229,9 +230,9 @@ namespace libtorrent
// for this target. Now figure out what the local address
// is for that interface
if (time_now() - seconds(60) > m_last_if_update)
if (aux::time_now() - seconds(60) > m_last_if_update)
{
m_last_if_update = time_now();
m_last_if_update = aux::time_now();
error_code ec;
m_interfaces = enum_net_interfaces(m_sock.get_io_service(), ec);
if (ec) return socket_ep;
@ -262,7 +263,7 @@ namespace libtorrent
if (ph->get_version() != 1) return false;
const ptime receive_time = time_now_hires();
const time_point receive_time = clock_type::now();
// parse out connection ID and look for existing
// connections. If found, forward to the utp_stream.

View File

@ -77,8 +77,8 @@ static struct utp_logger
void utp_log(char const* fmt, ...)
{
mutex::scoped_lock lock(log_file_holder.utp_log_mutex);
static ptime start = time_now_hires();
fprintf(log_file_holder.utp_log_file, "[%012" PRId64 "] ", total_microseconds(time_now_hires() - start));
static time_point start = clock_type::now();
fprintf(log_file_holder.utp_log_file, "[%012" PRId64 "] ", total_microseconds(clock_type::now() - start));
va_list l;
va_start(l, fmt);
vfprintf(log_file_holder.utp_log_file, fmt, l);
@ -142,7 +142,7 @@ TORRENT_EXTRA_EXPORT bool compare_less_wrap(boost::uint32_t lhs, boost::uint32_t
struct packet
{
// the last time this packet was sent
ptime send_time;
time_point send_time;
// the number of bytes actually allocated in 'buf'
boost::uint16_t allocated;
@ -234,8 +234,8 @@ struct utp_socket_impl
, m_write_handler(false)
, m_connect_handler(false)
, m_remote_address()
, m_timeout(time_now_hires() + milliseconds(m_sm->connect_timeout()))
, m_last_history_step(time_now_hires())
, m_timeout(clock_type::now() + milliseconds(m_sm->connect_timeout()))
, m_last_history_step(clock_type::now())
, m_cwnd(TORRENT_ETHERNET_MTU << 16)
, m_ssthres(0)
, m_buffered_incoming_bytes(0)
@ -288,10 +288,10 @@ struct utp_socket_impl
~utp_socket_impl();
void tick(ptime now);
void tick(time_point now);
void init_mtu(int link_mtu, int utp_mtu);
bool incoming_packet(boost::uint8_t const* buf, int size
, udp::endpoint const& ep, ptime receive_time);
, udp::endpoint const& ep, time_point receive_time);
void writable();
bool should_delete() const;
@ -321,14 +321,14 @@ struct utp_socket_impl
bool resend_packet(packet* p, bool fast_resend = false);
void send_reset(utp_header* ph);
void parse_sack(boost::uint16_t packet_ack, boost::uint8_t const* ptr
, int size, int* acked_bytes, ptime const now, boost::uint32_t& min_rtt);
, int size, int* acked_bytes, time_point const now, boost::uint32_t& min_rtt);
void parse_close_reason(boost::uint8_t const* ptr, int size);
void write_payload(boost::uint8_t* ptr, int size);
void maybe_inc_acked_seq_nr();
void ack_packet(packet* p, ptime const& receive_time
void ack_packet(packet* p, time_point const& receive_time
, boost::uint32_t& min_rtt, boost::uint16_t seq_nr);
void write_sack(boost::uint8_t* buf, int size) const;
void incoming(boost::uint8_t const* buf, int size, packet* p, ptime now);
void incoming(boost::uint8_t const* buf, int size, packet* p, time_point now);
void do_ledbat(int acked_bytes, int delay, int in_flight);
int packet_timeout() const;
bool test_socket_state();
@ -336,7 +336,7 @@ struct utp_socket_impl
void maybe_trigger_send_callback();
bool cancel_handlers(error_code const& ec, bool kill);
bool consume_incoming_data(
utp_header const* ph, boost::uint8_t const* ptr, int payload_size, ptime now);
utp_header const* ph, boost::uint8_t const* ptr, int payload_size, time_point now);
void update_mtu_limits();
void experienced_loss(int seq_nr);
@ -441,10 +441,10 @@ public:
// cwnd is set to less than one MSS during congestion control.
// it can also happen if the other end sends an advertized window
// size less than one MSS.
ptime m_timeout;
time_point m_timeout;
// the last time we stepped the timestamp history
ptime m_last_history_step;
time_point m_last_history_step;
// the max number of bytes in-flight. This is a fixed point
// value, to get the true number of bytes, shift right 16 bits
@ -702,7 +702,7 @@ bool should_delete(utp_socket_impl* s)
return s->should_delete();
}
void tick_utp_impl(utp_socket_impl* s, ptime now)
void tick_utp_impl(utp_socket_impl* s, time_point now)
{
s->tick(now);
}
@ -713,7 +713,7 @@ void utp_init_mtu(utp_socket_impl* s, int link_mtu, int utp_mtu)
}
bool utp_incoming_packet(utp_socket_impl* s, char const* p
, int size, udp::endpoint const& ep, ptime receive_time)
, int size, udp::endpoint const& ep, time_point receive_time)
{
return s->incoming_packet((boost::uint8_t const*)p, size, ep, receive_time);
}
@ -1343,7 +1343,7 @@ void utp_socket_impl::send_syn()
h->seq_nr = m_seq_nr;
h->ack_nr = 0;
ptime now = time_now_hires();
time_point now = clock_type::now();
p->send_time = now;
h->timestamp_microseconds = boost::uint32_t(
total_microseconds(now.time_since_epoch()) & 0xffffffff);
@ -1437,7 +1437,7 @@ void utp_socket_impl::send_reset(utp_header* ph)
h.wnd_size = 0;
h.seq_nr = random() & 0xffff;
h.ack_nr = ph->seq_nr;
ptime now = time_now_hires();
time_point now = clock_type::now();
h.timestamp_microseconds = boost::uint32_t(
total_microseconds(now.time_since_epoch()) & 0xffffffff);
@ -1470,7 +1470,7 @@ void utp_socket_impl::parse_close_reason(boost::uint8_t const* ptr, int size)
}
void utp_socket_impl::parse_sack(boost::uint16_t packet_ack, boost::uint8_t const* ptr
, int size, int* acked_bytes, ptime const now, boost::uint32_t& min_rtt)
, int size, int* acked_bytes, time_point const now, boost::uint32_t& min_rtt)
{
INVARIANT_CHECK;
@ -1983,7 +1983,7 @@ bool utp_socket_impl::send_pkt(int flags)
h->type_ver = (ST_FIN << 4) | 1;
// fill in the timestamp as late as possible
ptime now = time_now_hires();
time_point now = clock_type::now();
p->send_time = now;
h->timestamp_microseconds = boost::uint32_t(
total_microseconds(now.time_since_epoch()) & 0xffffffff);
@ -2176,7 +2176,7 @@ bool utp_socket_impl::resend_packet(packet* p, bool fast_resend)
utp_header* h = (utp_header*)p->buf;
// update packet header
h->timestamp_difference_microseconds = m_reply_micro;
p->send_time = time_now_hires();
p->send_time = clock_type::now();
h->timestamp_microseconds = boost::uint32_t(
total_microseconds(p->send_time.time_since_epoch()) & 0xffffffff);
@ -2317,7 +2317,7 @@ void utp_socket_impl::maybe_inc_acked_seq_nr()
m_duplicate_acks = 0;
}
void utp_socket_impl::ack_packet(packet* p, ptime const& receive_time
void utp_socket_impl::ack_packet(packet* p, time_point const& receive_time
, boost::uint32_t& min_rtt, boost::uint16_t seq_nr)
{
INVARIANT_CHECK;
@ -2365,7 +2365,7 @@ void utp_socket_impl::ack_packet(packet* p, ptime const& receive_time
}
void utp_socket_impl::incoming(boost::uint8_t const* buf, int size, packet* p
, ptime /* now */)
, time_point /* now */)
{
INVARIANT_CHECK;
@ -2448,7 +2448,7 @@ bool utp_socket_impl::cancel_handlers(error_code const& ec, bool kill)
bool utp_socket_impl::consume_incoming_data(
utp_header const* ph, boost::uint8_t const* ptr, int payload_size
, ptime now)
, time_point now)
{
INVARIANT_CHECK;
@ -2635,7 +2635,7 @@ void utp_socket_impl::init_mtu(int link_mtu, int utp_mtu)
// return false if this is an invalid packet
bool utp_socket_impl::incoming_packet(boost::uint8_t const* buf, int size
, udp::endpoint const& ep, ptime receive_time)
, udp::endpoint const& ep, time_point receive_time)
{
INVARIANT_CHECK;
@ -3470,7 +3470,7 @@ int utp_socket_impl::packet_timeout() const
return timeout;
}
void utp_socket_impl::tick(ptime now)
void utp_socket_impl::tick(time_point now)
{
INVARIANT_CHECK;

View File

@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/io_service.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/aux_/time.hpp"
#include "dht_server.hpp"
#include <boost/detail/atomic_count.hpp>
@ -85,7 +86,7 @@ struct dht_server
return;
}
fprintf(stderr, "%s: DHT initialized on port %d\n", time_now_string(), m_port);
fprintf(stderr, "%s: DHT initialized on port %d\n", aux::time_now_string(), m_port);
m_thread.reset(new thread(boost::bind(&dht_server::thread_fun, this)));
}
@ -170,8 +171,8 @@ int num_dht_hits()
void stop_dht()
{
fprintf(stderr, "%s: stop_dht()\n", time_now_string());
fprintf(stderr, "%s: stop_dht()\n", aux::time_now_string());
g_dht.reset();
fprintf(stderr, "%s: stop_dht() done\n", time_now_string());
fprintf(stderr, "%s: stop_dht() done\n", aux::time_now_string());
}

View File

@ -95,7 +95,7 @@ int main()
| SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
#endif
srand((total_microseconds(time_now_hires() - min_time())) & 0x7fffffff);
srand((total_microseconds(clock_type::now() - min_time())) & 0x7fffffff);
#ifdef O_NONBLOCK
// on darwin, stdout is set to non-blocking mode by default
// which sometimes causes tests to fail with EAGAIN just

View File

@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/io_service.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/aux_/time.hpp"
#include "peer_server.hpp"
#include <boost/detail/atomic_count.hpp>
@ -87,7 +88,7 @@ struct peer_server
return;
}
fprintf(stderr, "%s: PEER peer initialized on port %d\n", time_now_string(), m_port);
fprintf(stderr, "%s: PEER peer initialized on port %d\n", aux::time_now_string(), m_port);
m_thread.reset(new thread(boost::bind(&peer_server::thread_fun, this)));
}
@ -134,7 +135,7 @@ struct peer_server
return;
}
fprintf(stderr, "%s: PEER incoming peer connection\n", time_now_string());
fprintf(stderr, "%s: PEER incoming peer connection\n", aux::time_now_string());
++m_peer_requests;
socket.close(ec);
}
@ -158,8 +159,8 @@ int num_peer_hits()
void stop_peer()
{
fprintf(stderr, "%s: PEER stop_peer()\n", time_now_string());
fprintf(stderr, "%s: PEER stop_peer()\n", aux::time_now_string());
g_peer.reset();
fprintf(stderr, "%s: PEER stop_peer() done\n", time_now_string());
fprintf(stderr, "%s: PEER stop_peer() done\n", aux::time_now_string());
}

View File

@ -145,10 +145,10 @@ std::map<std::string, boost::uint64_t> get_counters(libtorrent::session& s)
std::auto_ptr<alert> wait_for_alert(lt::session& ses, int type, char const* name)
{
std::auto_ptr<alert> ret;
ptime end = time_now() + seconds(10);
time_point end = aux::time_now() + seconds(10);
while (!ret.get())
{
ptime now = time_now();
time_point now = aux::time_now();
if (now > end) return std::auto_ptr<alert>();
ses.wait_for_alert(end - now);
@ -157,7 +157,7 @@ std::auto_ptr<alert> wait_for_alert(lt::session& ses, int type, char const* name
for (std::deque<alert*>::iterator i = alerts.begin()
, end(alerts.end()); i != end; ++i)
{
fprintf(stderr, "%s: %s: [%s] %s\n", time_now_string(), name
fprintf(stderr, "%s: %s: [%s] %s\n", aux::time_now_string(), name
, (*i)->what(), (*i)->message().c_str());
if (!ret.get() && (*i)->type() == type)
{
@ -268,14 +268,14 @@ bool print_alerts(lt::session& ses, char const* name
if (predicate && predicate(*i)) ret = true;
if (peer_disconnected_alert* p = alert_cast<peer_disconnected_alert>(*i))
{
fprintf(stderr, "%s: %s: [%s] (%s): %s\n", time_now_string(), name, (*i)->what(), print_endpoint(p->ip).c_str(), p->message().c_str());
fprintf(stderr, "%s: %s: [%s] (%s): %s\n", aux::time_now_string(), name, (*i)->what(), print_endpoint(p->ip).c_str(), p->message().c_str());
}
else if ((*i)->message() != "block downloading"
&& (*i)->message() != "block finished"
&& (*i)->message() != "piece finished"
&& !no_output)
{
fprintf(stderr, "%s: %s: [%s] %s\n", time_now_string(), name, (*i)->what(), (*i)->message().c_str());
fprintf(stderr, "%s: %s: [%s] %s\n", aux::time_now_string(), name, (*i)->what(), (*i)->message().c_str());
}
TEST_CHECK(alert_cast<fastresume_rejected_alert>(*i) == 0 || allow_failed_fastresume);
@ -283,7 +283,7 @@ bool print_alerts(lt::session& ses, char const* name
peer_error_alert* pea = alert_cast<peer_error_alert>(*i);
if (pea)
{
fprintf(stderr, "%s: peer error: %s\n", time_now_string(), pea->error.message().c_str());
fprintf(stderr, "%s: peer error: %s\n", aux::time_now_string(), pea->error.message().c_str());
TEST_CHECK((!handles.empty() && h.status().is_seeding)
|| pea->error.message() == "connecting to peer"
|| pea->error.message() == "closing connection to ourself"
@ -503,7 +503,7 @@ int start_proxy(int proxy_type)
if (i->second.type == proxy_type) { return i->first; }
}
unsigned int seed = total_microseconds(time_now_hires() - min_time()) & 0xffffffff;
unsigned int seed = total_microseconds(clock_type::now() - min_time()) & 0xffffffff;
printf("random seed: %u\n", seed);
std::srand(seed);
@ -541,13 +541,13 @@ int start_proxy(int proxy_type)
char buf[512];
snprintf(buf, sizeof(buf), "%s --port %d%s", cmd, port, auth);
fprintf(stderr, "%s starting proxy on port %d (%s %s)...\n", time_now_string(), port, type, auth);
fprintf(stderr, "%s starting proxy on port %d (%s %s)...\n", aux::time_now_string(), port, type, auth);
fprintf(stderr, "%s\n", buf);
pid_type r = async_run(buf);
if (r == 0) exit(1);
proxy_t t = { r, proxy_type };
running_proxies.insert(std::make_pair(port, t));
fprintf(stderr, "%s launched\n", time_now_string());
fprintf(stderr, "%s launched\n", aux::time_now_string());
test_sleep(500);
return port;
}
@ -823,7 +823,7 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3
port = ses2->listen_port();
fprintf(stderr, "%s: ses1: connecting peer port: %d\n"
, time_now_string(), port);
, aux::time_now_string(), port);
tor1.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec)
, port));
@ -860,7 +860,7 @@ pid_type web_server_pid = 0;
int start_web_server(bool ssl, bool chunked_encoding, bool keepalive)
{
unsigned int seed = total_microseconds(time_now_hires() - min_time()) & 0xffffffff;
unsigned int seed = total_microseconds(clock_type::now() - min_time()) & 0xffffffff;
fprintf(stderr, "random seed: %u\n", seed);
std::srand(seed);
int port = 5000 + (rand() % 55000);
@ -869,13 +869,13 @@ int start_web_server(bool ssl, bool chunked_encoding, bool keepalive)
snprintf(buf, sizeof(buf), "python ../web_server.py %d %d %d %d"
, port, chunked_encoding , ssl, keepalive);
fprintf(stderr, "%s starting web_server on port %d...\n", time_now_string(), port);
fprintf(stderr, "%s starting web_server on port %d...\n", aux::time_now_string(), port);
fprintf(stderr, "%s\n", buf);
pid_type r = async_run(buf);
if (r == 0) exit(1);
web_server_pid = r;
fprintf(stderr, "%s launched\n", time_now_string());
fprintf(stderr, "%s launched\n", aux::time_now_string());
test_sleep(500);
return port;
}

View File

@ -191,10 +191,10 @@ void test_swarm(int flags)
ses3.remove_torrent(tor3, lt::session::delete_files);
std::auto_ptr<alert> a = ses1.pop_alert();
ptime end = time_now() + seconds(20);
time_point end = aux::time_now() + seconds(20);
while (a.get() == 0 || alert_cast<torrent_deleted_alert>(a.get()) == 0)
{
if (ses1.wait_for_alert(end - time_now()) == 0)
if (ses1.wait_for_alert(end - aux::time_now()) == 0)
{
std::cerr << "wait_for_alert() expired" << std::endl;
break;
@ -210,13 +210,13 @@ void test_swarm(int flags)
// make sure that the timer in wait_for_alert() works
// this should time out (ret == 0) and it should take
// about 2 seconds
ptime start = time_now_hires();
time_point start = clock_type::now();
alert const* ret;
while ((ret = ses1.wait_for_alert(seconds(2))))
{
a = ses1.pop_alert();
std::cerr << ret->message() << std::endl;
start = time_now();
start = aux::time_now();
}
// this allows shutting down the sessions in parallel
@ -224,8 +224,8 @@ void test_swarm(int flags)
p2 = ses2.abort();
p3 = ses3.abort();
TEST_CHECK(time_now_hires() - start < seconds(3));
TEST_CHECK(time_now_hires() - start >= seconds(2));
TEST_CHECK(clock_type::now() - start < seconds(3));
TEST_CHECK(clock_type::now() - start >= seconds(2));
TEST_CHECK(!exists("tmp1_swarm/temporary"));
TEST_CHECK(!exists("tmp2_swarm/temporary"));

View File

@ -43,7 +43,7 @@ int test_main()
{
using namespace libtorrent;
ptime start(time_now());
time_point start(clock_type::now());
for (int i = 0; i < 100000; ++i)
{
@ -52,7 +52,7 @@ int test_main()
error_code ec;
lazy_bdecode(b, b + sizeof(b)-1, e, ec);
}
ptime stop(time_now());
time_point stop(clock_type::now());
std::cout << "done in " << total_milliseconds(stop - start) / 100. << " seconds per million message" << std::endl;
return 0;

View File

@ -46,7 +46,7 @@ int test_main()
address spammer = address_v4::from_string("10.10.10.10");
ptime now = time_now();
time_point now = aux::time_now();
for (int i = 0; i < 1000; ++i)
{
b.incoming(spammer, now);

View File

@ -53,7 +53,7 @@ int read_message(stream_socket& s, char* buffer)
, libtorrent::asio::transfer_all(), ec);
if (ec)
{
std::cout << time_now_string() << ": " << ec.message() << std::endl;
std::cout << aux::time_now_string() << ": " << ec.message() << std::endl;
TEST_ERROR("read_message: " + ec.message());
return 0;
}
@ -64,7 +64,7 @@ int read_message(stream_socket& s, char* buffer)
, libtorrent::asio::transfer_all(), ec);
if (ec)
{
std::cout << time_now_string() << ": " << ec.message() << std::endl;
std::cout << aux::time_now_string() << ": " << ec.message() << std::endl;
TEST_ERROR("read_message: " + ec.message());
return 0;
}
@ -111,12 +111,12 @@ void print_message(char const* buffer, int len)
}
}
fprintf(stderr, "%s <== %s %s\n", time_now_string(), message, extra);
fprintf(stderr, "%s <== %s %s\n", aux::time_now_string(), message, extra);
}
void send_allow_fast(stream_socket& s, int piece)
{
std::cout << time_now_string() << " ==> allow fast: " << piece << std::endl;
std::cout << aux::time_now_string() << " ==> allow fast: " << piece << std::endl;
using namespace libtorrent::detail;
char msg[] = "\0\0\0\x05\x11\0\0\0\0";
char* ptr = msg + 5;
@ -128,7 +128,7 @@ void send_allow_fast(stream_socket& s, int piece)
void send_suggest_piece(stream_socket& s, int piece)
{
std::cout << time_now_string() << " ==> suggest piece: " << piece << std::endl;
std::cout << aux::time_now_string() << " ==> suggest piece: " << piece << std::endl;
using namespace libtorrent::detail;
char msg[] = "\0\0\0\x05\x0d\0\0\0\0";
char* ptr = msg + 5;
@ -140,7 +140,7 @@ void send_suggest_piece(stream_socket& s, int piece)
void send_keepalive(stream_socket& s)
{
std::cout << time_now_string() << " ==> keepalive" << std::endl;
std::cout << aux::time_now_string() << " ==> keepalive" << std::endl;
char msg[] = "\0\0\0\0";
error_code ec;
libtorrent::asio::write(s, libtorrent::asio::buffer(msg, 4)
@ -149,7 +149,7 @@ void send_keepalive(stream_socket& s)
void send_unchoke(stream_socket& s)
{
std::cout << time_now_string() << " ==> unchoke" << std::endl;
std::cout << aux::time_now_string() << " ==> unchoke" << std::endl;
char msg[] = "\0\0\0\x01\x01";
error_code ec;
libtorrent::asio::write(s, libtorrent::asio::buffer(msg, 5)
@ -158,7 +158,7 @@ void send_unchoke(stream_socket& s)
void send_have_all(stream_socket& s)
{
std::cout << time_now_string() << " ==> have_all" << std::endl;
std::cout << aux::time_now_string() << " ==> have_all" << std::endl;
char msg[] = "\0\0\0\x01\x0e"; // have_all
error_code ec;
libtorrent::asio::write(s, libtorrent::asio::buffer(msg, 5)
@ -167,7 +167,7 @@ void send_have_all(stream_socket& s)
void send_have_none(stream_socket& s)
{
std::cout << time_now_string() << " ==> have_none" << std::endl;
std::cout << aux::time_now_string() << " ==> have_none" << std::endl;
char msg[] = "\0\0\0\x01\x0f"; // have_none
error_code ec;
libtorrent::asio::write(s, libtorrent::asio::buffer(msg, 5)
@ -185,7 +185,7 @@ void send_bitfield(stream_socket& s, char const* bits)
char* ptr = msg;
write_int32(packet_size-4, ptr);
write_int8(5, ptr);
std::cout << time_now_string() << " ==> bitfield [" << bits << "]" << std::endl;;
std::cout << aux::time_now_string() << " ==> bitfield [" << bits << "]" << std::endl;;
for (int i = 0; i < num_pieces; ++i)
{
ptr[i/8] |= (bits[i] == '1' ? 1 : 0) << i % 8;
@ -200,7 +200,7 @@ void do_handshake(stream_socket& s, sha1_hash const& ih, char* buffer)
char handshake[] = "\x13" "BitTorrent protocol\0\0\0\0\0\x10\0\x04"
" " // space for info-hash
"aaaaaaaaaaaaaaaaaaaa"; // peer-id
std::cout << time_now_string() << " ==> handshake" << std::endl;
std::cout << aux::time_now_string() << " ==> handshake" << std::endl;
error_code ec;
std::memcpy(handshake + 28, ih.begin(), 20);
libtorrent::asio::write(s, libtorrent::asio::buffer(handshake, sizeof(handshake) - 1)
@ -211,10 +211,10 @@ void do_handshake(stream_socket& s, sha1_hash const& ih, char* buffer)
, libtorrent::asio::transfer_all(), ec);
if (ec)
{
std::cout << time_now_string() << ": " << ec.message() << std::endl;
std::cout << aux::time_now_string() << ": " << ec.message() << std::endl;
exit(1);
}
std::cout << time_now_string() << " <== handshake" << std::endl;
std::cout << aux::time_now_string() << " <== handshake" << std::endl;
TEST_CHECK(buffer[0] == 19);
TEST_CHECK(std::memcmp(buffer + 1, "BitTorrent protocol", 19) == 0);
@ -303,7 +303,7 @@ void test_reject_fast()
// send reject request
recv_buffer[0] = 0x10;
error_code ec;
std::cerr << time_now_string() << " ==> reject" << std::endl;
std::cerr << aux::time_now_string() << " ==> reject" << std::endl;
libtorrent::asio::write(s, libtorrent::asio::buffer("\0\0\0\x0d", 4)
, libtorrent::asio::transfer_all(), ec);
libtorrent::asio::write(s, libtorrent::asio::buffer(recv_buffer, 13)
@ -361,7 +361,7 @@ void test_respect_suggest()
// send reject request
recv_buffer[0] = 0x10;
error_code ec;
std::cerr << time_now_string() << " ==> reject" << std::endl;
std::cerr << aux::time_now_string() << " ==> reject" << std::endl;
libtorrent::asio::write(s, libtorrent::asio::buffer("\0\0\0\x0d", 4)
, libtorrent::asio::transfer_all(), ec);
libtorrent::asio::write(s, libtorrent::asio::buffer(recv_buffer, 13)

View File

@ -55,12 +55,12 @@ char data_buffer[4000];
void print_http_header(http_parser const& p)
{
std::cerr << time_now_string() << " < " << p.status_code() << " " << p.message() << std::endl;
std::cerr << aux::time_now_string() << " < " << p.status_code() << " " << p.message() << std::endl;
for (std::multimap<std::string, std::string>::const_iterator i
= p.headers().begin(), end(p.headers().end()); i != end; ++i)
{
std::cerr << time_now_string() << " < " << i->first << ": " << i->second << std::endl;
std::cerr << aux::time_now_string() << " < " << i->first << ": " << i->second << std::endl;
}
}
@ -69,7 +69,7 @@ void http_connect_handler(http_connection& c)
++connect_handler_called;
TEST_CHECK(c.socket().is_open());
error_code ec;
std::cerr << time_now_string() << " connected to: " << print_endpoint(c.socket().remote_endpoint(ec))
std::cerr << aux::time_now_string() << " connected to: " << print_endpoint(c.socket().remote_endpoint(ec))
<< std::endl;
// this is not necessarily true when using a proxy and proxying hostnames
// TEST_CHECK(c.socket().remote_endpoint(ec).address() == address::from_string("127.0.0.1", ec));
@ -111,7 +111,7 @@ void run_test(std::string const& url, int size, int status, int connected
std::cerr << " ===== TESTING: " << url << " =====" << std::endl;
std::cerr << time_now_string()
std::cerr << aux::time_now_string()
<< " expecting: size: " << size
<< " status: " << status
<< " connected: " << connected
@ -124,14 +124,14 @@ void run_test(std::string const& url, int size, int status, int connected
ios.reset();
error_code e;
ios.run(e);
if (e) std::cerr << time_now_string() << " run failed: " << e.message() << std::endl;
if (e) std::cerr << aux::time_now_string() << " run failed: " << e.message() << std::endl;
std::cerr << time_now_string() << " connect_handler_called: " << connect_handler_called << std::endl;
std::cerr << time_now_string() << " handler_called: " << handler_called << std::endl;
std::cerr << time_now_string() << " status: " << http_status << std::endl;
std::cerr << time_now_string() << " size: " << data_size << std::endl;
std::cerr << time_now_string() << " expected-size: " << size << std::endl;
std::cerr << time_now_string() << " error_code: " << g_error_code.message() << std::endl;
std::cerr << aux::time_now_string() << " connect_handler_called: " << connect_handler_called << std::endl;
std::cerr << aux::time_now_string() << " handler_called: " << handler_called << std::endl;
std::cerr << aux::time_now_string() << " status: " << http_status << std::endl;
std::cerr << aux::time_now_string() << " size: " << data_size << std::endl;
std::cerr << aux::time_now_string() << " expected-size: " << size << std::endl;
std::cerr << aux::time_now_string() << " error_code: " << g_error_code.message() << std::endl;
TEST_CHECK(connect_handler_called == connected);
TEST_CHECK(handler_called == 1);
TEST_CHECK(data_size == size || size == -1);

View File

@ -137,7 +137,7 @@ void test_transfer(int flags
error_code ec;
int port = seed->listen_port();
fprintf(stderr, "%s: downloader: connecting peer port: %d\n"
, time_now_string(), port);
, aux::time_now_string(), port);
tor2.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec)
, port));
}
@ -146,7 +146,7 @@ void test_transfer(int flags
error_code ec;
int port = downloader->listen_port();
fprintf(stderr, "%s: seed: connecting peer port: %d\n"
, time_now_string(), port);
, aux::time_now_string(), port);
tor1.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec)
, port));
}

View File

@ -260,7 +260,7 @@ void test_transfer(settings_pack const& sett)
std::vector<char> resume_data;
alert const* a = ses2.wait_for_alert(seconds(10));
ptime start = time_now_hires();
time_point start = clock_type::now();
while (a)
{
std::auto_ptr<alert> holder = ses2.pop_alert();
@ -277,7 +277,7 @@ void test_transfer(settings_pack const& sett)
fprintf(stderr, "save resume failed\n");
break;
}
if (total_seconds(time_now_hires() - start) > 10)
if (total_seconds(clock_type::now() - start) > 10)
break;
a = ses2.wait_for_alert(seconds(10));

View File

@ -229,7 +229,7 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
if (flags & expect_http_reject)
TEST_CHECK(std::find(rejected_trackers.begin(), rejected_trackers.end(), http_tracker_url) != rejected_trackers.end());
fprintf(stderr, "%s: ~session\n", time_now_string());
fprintf(stderr, "%s: ~session\n", aux::time_now_string());
session_proxy pr = s->abort();
delete s;

View File

@ -62,33 +62,33 @@ char* piece3 = page_aligned_allocator::malloc(piece_size);
void signal_bool(bool* b, char const* string)
{
*b = true;
std::cerr << time_now_string() << " " << string << std::endl;
std::cerr << aux::time_now_string() << " " << string << std::endl;
}
void on_read_piece(int ret, disk_io_job const& j, char const* data, int size)
{
std::cerr << time_now_string() << " on_read_piece piece: " << j.piece << std::endl;
std::cerr << aux::time_now_string() << " on_read_piece piece: " << j.piece << std::endl;
TEST_EQUAL(ret, size);
if (ret > 0) TEST_CHECK(std::equal(j.buffer, j.buffer + ret, data));
}
void on_check_resume_data(disk_io_job const* j, bool* done)
{
std::cerr << time_now_string() << " on_check_resume_data ret: " << j->ret;
std::cerr << aux::time_now_string() << " on_check_resume_data ret: " << j->ret;
switch (j->ret)
{
case piece_manager::no_error:
std::cerr << time_now_string() << " success" << std::endl;
std::cerr << aux::time_now_string() << " success" << std::endl;
break;
case piece_manager::fatal_disk_error:
std::cerr << time_now_string() << " disk error: " << j->error.ec.message()
std::cerr << aux::time_now_string() << " disk error: " << j->error.ec.message()
<< " file: " << j->error.file << std::endl;
break;
case piece_manager::need_full_check:
std::cerr << time_now_string() << " need full check" << std::endl;
std::cerr << aux::time_now_string() << " need full check" << std::endl;
break;
case piece_manager::disk_check_aborted:
std::cerr << time_now_string() << " aborted" << std::endl;
std::cerr << aux::time_now_string() << " aborted" << std::endl;
break;
}
std::cerr << std::endl;
@ -98,7 +98,7 @@ void on_check_resume_data(disk_io_job const* j, bool* done)
void print_error(char const* call, int ret, storage_error const& ec)
{
fprintf(stderr, "%s: %s() returned: %d error: \"%s\" in file: %d operation: %d\n"
, time_now_string(), call, ret, ec.ec.message().c_str(), ec.file, ec.operation);
, aux::time_now_string(), call, ret, ec.ec.message().c_str(), ec.file, ec.operation);
}
void run_until(io_service& ios, bool const& done)
@ -113,7 +113,7 @@ void run_until(io_service& ios, bool const& done)
std::cerr << "run_one: " << ec.message().c_str() << std::endl;
return;
}
std::cerr << time_now_string() << " done: " << done << std::endl;
std::cerr << aux::time_now_string() << " done: " << done << std::endl;
}
}
@ -678,12 +678,12 @@ void test_fastresume(std::string const& test_path)
torrent_handle h = ses.add_torrent(p, ec);
std::auto_ptr<alert> a = ses.pop_alert();
ptime end = time_now() + seconds(20);
while (time_now() < end
time_point end = aux::time_now() + seconds(20);
while (aux::time_now() < end
&& (a.get() == 0
|| alert_cast<fastresume_rejected_alert>(a.get()) == 0))
{
if (ses.wait_for_alert(end - time_now()) == 0)
if (ses.wait_for_alert(end - aux::time_now()) == 0)
{
std::cerr << "wait_for_alert() expired" << std::endl;
break;

View File

@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace libtorrent;
void check_timer_loop(mutex& m, ptime& last, condition_variable& cv)
void check_timer_loop(mutex& m, time_point& last, condition_variable& cv)
{
mutex::scoped_lock l(m);
cv.wait(l);
@ -47,7 +47,7 @@ void check_timer_loop(mutex& m, ptime& last, condition_variable& cv)
for (int i = 0; i < 10000; ++i)
{
mutex::scoped_lock l(m);
ptime now = time_now_hires();
time_point now = clock_type::now();
TEST_CHECK(now >= last);
last = now;
}
@ -70,11 +70,11 @@ int test_main()
// make sure the timer is monotonic
ptime now = time_now_hires();
ptime last = now;
time_point now = clock_type::now();
time_point last = now;
for (int i = 0; i < 1000; ++i)
{
now = time_now_hires();
now = clock_type::now();
TEST_CHECK(now >= last);
last = now;
}

View File

@ -306,7 +306,7 @@ void test_transfer(int proxy_type, settings_pack const& sett
// at this point we probably disconnected the seed
// so we need to reconnect as well
fprintf(stderr, "%s: reconnecting peer\n", time_now_string());
fprintf(stderr, "%s: reconnecting peer\n", aux::time_now_string());
error_code ec;
tor2.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec)
, ses1.listen_port()));
@ -314,7 +314,7 @@ void test_transfer(int proxy_type, settings_pack const& sett
TEST_CHECK(tor2.status().is_finished == false);
fprintf(stderr, "disconnects: %d\n", peer_disconnects);
TEST_CHECK(peer_disconnects >= 2);
fprintf(stderr, "%s: discovered disk full mode. Raise limit and disable upload-mode\n", time_now_string());
fprintf(stderr, "%s: discovered disk full mode. Raise limit and disable upload-mode\n", aux::time_now_string());
peer_disconnects = 0;
continue;
}

View File

@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp"
#include "libtorrent/socket_io.hpp"
#include "libtorrent/io.hpp"
#include "libtorrent/aux_/time.hpp"
#include "udp_tracker.hpp"
#include <boost/detail/atomic_count.hpp>
@ -65,17 +66,17 @@ struct udp_tracker
{
if (ec)
{
fprintf(stderr, "%s: UDP tracker, read failed: %s\n", time_now_string(), ec.message().c_str());
fprintf(stderr, "%s: UDP tracker, read failed: %s\n", aux::time_now_string(), ec.message().c_str());
return;
}
if (bytes_transferred < 16)
{
fprintf(stderr, "%s: UDP message too short (from: %s)\n", time_now_string(), print_endpoint(*from).c_str());
fprintf(stderr, "%s: UDP message too short (from: %s)\n", aux::time_now_string(), print_endpoint(*from).c_str());
return;
}
fprintf(stderr, "%s: UDP message %d bytes\n", time_now_string(), int(bytes_transferred));
fprintf(stderr, "%s: UDP message %d bytes\n", aux::time_now_string(), int(bytes_transferred));
char* ptr = buffer;
detail::read_uint64(ptr);
@ -88,7 +89,7 @@ struct udp_tracker
{
case 0: // connect
fprintf(stderr, "%s: UDP connect from %s\n", time_now_string()
fprintf(stderr, "%s: UDP connect from %s\n", aux::time_now_string()
, print_endpoint(*from).c_str());
ptr = buffer;
detail::write_uint32(0, ptr); // action = connect
@ -96,15 +97,15 @@ struct udp_tracker
detail::write_uint64(10, ptr); // connection_id
m_socket.send_to(asio::buffer(buffer, 16), *from, 0, e);
if (e) fprintf(stderr, "%s: UDP send_to failed. ERROR: %s\n"
, time_now_string(), e.message().c_str());
, aux::time_now_string(), e.message().c_str());
else fprintf(stderr, "%s: UDP sent response to: %s\n"
, time_now_string(), print_endpoint(*from).c_str());
, aux::time_now_string(), print_endpoint(*from).c_str());
break;
case 1: // announce
++m_udp_announces;
fprintf(stderr, "%s: UDP announce [%d]\n", time_now_string()
fprintf(stderr, "%s: UDP announce [%d]\n", aux::time_now_string()
, int(m_udp_announces));
ptr = buffer;
detail::write_uint32(1, ptr); // action = announce
@ -115,16 +116,16 @@ struct udp_tracker
// 0 peers
m_socket.send_to(asio::buffer(buffer, 20), *from, 0, e);
if (e) fprintf(stderr, "%s: UDP send_to failed. ERROR: %s\n"
, time_now_string(), e.message().c_str());
, aux::time_now_string(), e.message().c_str());
else fprintf(stderr, "%s: UDP sent response to: %s\n"
, time_now_string(), print_endpoint(*from).c_str());
, aux::time_now_string(), print_endpoint(*from).c_str());
break;
case 2:
// ignore scrapes
fprintf(stderr, "%s: UDP scrape (ignored)\n", time_now_string());
fprintf(stderr, "%s: UDP scrape (ignored)\n", aux::time_now_string());
break;
default:
fprintf(stderr, "%s: UDP unknown message: %d\n", time_now_string()
fprintf(stderr, "%s: UDP unknown message: %d\n", aux::time_now_string()
, action);
break;
}
@ -160,7 +161,7 @@ struct udp_tracker
return;
}
fprintf(stderr, "%s: UDP tracker initialized on port %d\n", time_now_string(), m_port);
fprintf(stderr, "%s: UDP tracker initialized on port %d\n", aux::time_now_string(), m_port);
m_thread.reset(new thread(boost::bind(&udp_tracker::thread_fun, this)));
}
@ -222,8 +223,8 @@ int num_udp_announces()
void stop_udp_tracker()
{
fprintf(stderr, "%s: UDP stop_udp_tracker()\n", time_now_string());
fprintf(stderr, "%s: UDP stop_udp_tracker()\n", aux::time_now_string());
g_udp_tracker.reset();
fprintf(stderr, "%s: UDP stop_udp_tracker() done\n", time_now_string());
fprintf(stderr, "%s: UDP stop_udp_tracker() done\n", aux::time_now_string());
}