コード例 #1
0
void traversal_algorithm::status(dht_lookup& l)
{
	l.timeouts = m_timeouts;
	l.responses = m_responses;
	l.outstanding_requests = m_invoke_count;
	l.branch_factor = m_branch_factor;
	l.type = name();
	l.nodes_left = 0;
	l.first_timeout = 0;

	int last_sent = INT_MAX;
	ptime now = time_now();
	for (std::vector<observer_ptr>::iterator i = m_results.begin()
		, end(m_results.end()); i != end; ++i)
	{
		observer& o = **i;
		if (o.flags & observer::flag_queried)
		{
			last_sent = (std::min)(last_sent, int(total_seconds(now - o.sent())));
			if (o.has_short_timeout()) ++l.first_timeout;
			continue;
		}
		++l.nodes_left;
	}
	l.last_sent = last_sent;
}
コード例 #2
0
void traversal_algorithm::status(dht_lookup& l)
{
	l.timeouts = m_timeouts;
	l.responses = m_responses;
	l.outstanding_requests = m_invoke_count;
	l.branch_factor = m_branch_factor;
	l.type = name();
	l.nodes_left = 0;
	l.first_timeout = 0;
	l.target = m_target;

	int last_sent = INT_MAX;
	time_point now = aux::time_now();
	for (auto const& r : m_results)
	{
		observer const& o = *r;
		if (o.flags & observer::flag_queried)
		{
			last_sent = (std::min)(last_sent, int(total_seconds(now - o.sent())));
			if (o.has_short_timeout()) ++l.first_timeout;
			continue;
		}
		++l.nodes_left;
	}
	l.last_sent = last_sent;
}
コード例 #3
0
	void timeout_handler::timeout_callback(error_code const& error)
	{
		COMPLETE_ASYNC("timeout_handler::timeout_callback");
#if TORRENT_USE_ASSERTS
		TORRENT_ASSERT(m_outstanding_timer_wait > 0);
		--m_outstanding_timer_wait;
#endif
		if (m_abort) return;

		time_point now = clock_type::now();
		time_duration receive_timeout = now - m_read_time;
		time_duration completion_timeout = now - m_start_time;

		if ((m_read_timeout
				&& m_read_timeout <= total_seconds(receive_timeout))
			|| (m_completion_timeout
				&& m_completion_timeout <= total_seconds(completion_timeout))
			|| error)
		{
			on_timeout(error);
			return;
		}

		int timeout = 0;
		if (m_read_timeout > 0) timeout = m_read_timeout;
		if (m_completion_timeout > 0)
		{
			timeout = timeout == 0
				? int(m_completion_timeout - total_seconds(m_read_time - m_start_time))
				: (std::min)(int(m_completion_timeout - total_seconds(m_read_time - m_start_time)), timeout);
		}
		ADD_OUTSTANDING_ASYNC("timeout_handler::timeout_callback");
		error_code ec;
		m_timeout.expires_at(m_read_time + seconds(timeout), ec);
		m_timeout.async_wait(
			std::bind(&timeout_handler::timeout_callback, shared_from_this(), _1));
#if TORRENT_USE_ASSERTS
		++m_outstanding_timer_wait;
#endif
	}
コード例 #4
0
ファイル: thread.cpp プロジェクト: TeoTwawki/libtorrent
	void condition_variable::wait_for(mutex::scoped_lock& l, time_duration rel_time)
	{
		TORRENT_ASSERT(l.locked());

		struct timeval tv;
		struct timespec ts;
		gettimeofday(&tv, NULL);
		boost::uint64_t microseconds = tv.tv_usec + total_microseconds(rel_time) % 1000000;
		ts.tv_nsec = (microseconds % 1000000) * 1000;
		ts.tv_sec = tv.tv_sec + total_seconds(rel_time) + microseconds / 1000000;
		
		// wow, this is quite a hack
		pthread_cond_timedwait(&m_cond, (::pthread_mutex_t*)&l.mutex(), &ts);
	}
コード例 #5
0
	void timeout_handler::timeout_callback(error_code const& error)
	{
#if defined TORRENT_ASIO_DEBUGGING
		complete_async("timeout_handler::timeout_callback");
#endif
		if (m_abort) return;

		ptime now = time_now_hires();
		time_duration receive_timeout = now - m_read_time;
		time_duration completion_timeout = now - m_start_time;
		
		if ((m_read_timeout
				&& m_read_timeout <= total_seconds(receive_timeout))
			|| (m_completion_timeout
				&& m_completion_timeout <= total_seconds(completion_timeout))
			|| error)
		{
			on_timeout(error);
			return;
		}

		int timeout = 0;
		if (m_read_timeout > 0) timeout = m_read_timeout;
		if (m_completion_timeout > 0)
		{
			timeout = timeout == 0
				? int(m_completion_timeout - total_seconds(m_read_time - m_start_time))
				: (std::min)(int(m_completion_timeout - total_seconds(m_read_time - m_start_time)), timeout);
		}
#if defined TORRENT_ASIO_DEBUGGING
		add_outstanding_async("timeout_handler::timeout_callback");
#endif
		error_code ec;
		m_timeout.expires_at(m_read_time + seconds(timeout), ec);
		m_timeout.async_wait(
			boost::bind(&timeout_handler::timeout_callback, self(), _1));
	}
コード例 #6
0
ファイル: session_impl.hpp プロジェクト: mirror/libtorrent
			boost::int64_t session_time() const { return total_seconds(time_now() - m_created); }
コード例 #7
0
ファイル: TimeDuration.cpp プロジェクト: NCAR/wt-classes
long TimeDuration::total_minutes() const {
    return total_seconds() / 60;
}
コード例 #8
0
ファイル: TimeDuration.cpp プロジェクト: NCAR/wt-classes
TimeDuration::operator std::string() const {
    return ptime::to_simple_string(ptime::seconds(total_seconds()));
}
コード例 #9
0
ファイル: date_time.cpp プロジェクト: gibbsxu/helloworld
int main(int argc, const char *argv[]) {
    {
        // 日期创建
        boost::gregorian::date date1(boost::gregorian::from_string("2016-2-9"));
        boost::gregorian::date date2(boost::gregorian::from_simple_string("2016-2-9"));
        boost::gregorian::date date3(boost::gregorian::from_simple_string("2016-Feb-9"));
        boost::gregorian::date date4(boost::gregorian::from_undelimited_string("20160209"));
        boost::gregorian::date date5(boost::gregorian::date_from_iso_string("20160209"));
        boost::gregorian::date date6(2016, 2, 9);
        boost::gregorian::date date7(2016, boost::gregorian::Feb, 9);
        std::cout << "date1: " << date1 << std::endl;
        std::cout << "date2: " << date2 << std::endl;
        std::cout << "date3: " << date3 << std::endl;
        std::cout << "date4: " << date4 << std::endl;
        std::cout << "date5: " << date5 << std::endl;
        std::cout << "date6: " << date6 << std::endl;
        std::cout << "date7: " << date7 << std::endl;
    } {
        // 当前日期
        boost::gregorian::date today(boost::gregorian::day_clock::local_day());
        std::cout << "today: " << today << std::endl;
    } {
        // 日期运算
        boost::gregorian::date today(boost::gregorian::day_clock::local_day());
        boost::gregorian::date date1 = today + boost::gregorian::days(100);
        std::cout << "today: " << date1 << std::endl;
        std::cout << "duration: " << (date1 - today).days() << std::endl;
        std::cout << "date1 > today: " << (date1 > today) << std::endl;
    } {
        // 日期字符串
        boost::gregorian::date today(boost::gregorian::day_clock::local_day());
        std::cout << "today: " << boost::gregorian::to_iso_string(today) << std::endl;
        std::cout << "today: " << boost::gregorian::to_iso_extended_string(today) << std::endl;
    } {
        // 日期属性
        boost::gregorian::date today(boost::gregorian::day_clock::local_day());
        std::cout << "year: " << today.year() << std::endl;
        std::cout << "month: " << today.month() << std::endl;               // Jan, Feb
        std::cout << "month: " << today.month().as_number() << std::endl;   // month of year 1-12
        std::cout << "day: " << today.day() << std::endl;                   // day of month 1-31
        std::cout << "day of year: " << today.day_of_year() << std::endl;   // day of year  1-366
        std::cout << "day of week: " << today.day_of_week() << std::endl;   // Mon, Tue
        std::cout << "day of week: " << today.day_of_week().as_number() << std::endl;   // 1-7
        std::cout << "week number: " << today.week_number() << std::endl;   // 1-53
        std::cout << "day number: " << today.day_number() << std::endl;     // total day
        std::cout << "end of month: " << today.end_of_month() << std::endl; // 2016-Feb-29
    } {
        // 日期循环
        boost::gregorian::date t1(boost::gregorian::from_simple_string("2016-2-9"));
        boost::gregorian::date t2(boost::gregorian::from_simple_string("2016-3-9"));
        for (boost::gregorian::date d = t1; d != t2; d += boost::gregorian::days(1)) {
            std::cout << d << std::endl;
        }
    } {
        // ptime
        boost::posix_time::ptime t1(boost::gregorian::date(2016, 2, 9), boost::posix_time::hours(18));
        boost::posix_time::ptime t2(boost::gregorian::date(2016, 2, 9), boost::posix_time::time_duration(19, 1, 1, 0));
        auto d = t2 - t1;
        std::cout << d.total_seconds() << std::endl;
    }
    
    return 0;
}
コード例 #10
0
int64_t time_span::seconds( void ) const {
    return total_seconds() % 60;
}
コード例 #11
0
int  compare_times(struct time t1, struct time t2)
{
    return  total_seconds(t1) - total_seconds(t2);
}