// TimeToLive
//-----------------------------------------------------------------------------
-TimeToLive::TimeToLive( int ttl ) :
+TimeToLive::TimeToLive( uint32_t ttl ) :
Ttl( ttl ),
TtlSetTime( microsec_clock::universal_time() )
{
/**
* @return the original time-to-live value, as specified by the set method.
*/
-int TimeToLive::get_value() const
+uint32_t TimeToLive::get_value() const
{
return Ttl;
}
/**
* @param ttl the time-to-live value.
*/
-void TimeToLive::set_value( const int ttl )
+void TimeToLive::set_value( const uint32_t ttl )
{
BOOST_ASSERT( 0 < ttl );
/**
* @return the value of the time-to-live updated since the last set was called.
*/
-int TimeToLive::get_updated_value() const
+uint32_t TimeToLive::get_updated_value() const
{
ptime now = microsec_clock::universal_time();
- int elapsed_seconds = static_cast<int>(
+ uint32_t elapsed_seconds = static_cast<int>(
(now - TtlSetTime).total_seconds()
);
- int original_ttl = get_value();
- int remaining_seconds = original_ttl - elapsed_seconds;
+ uint32_t original_ttl = get_value();
+ uint32_t remaining_seconds = original_ttl - elapsed_seconds;
return remaining_seconds;
}
#ifndef TIMETOLIVE_H
#define TIMETOLIVE_H
+#include <stdint.h>
+
#include <boost/asio.hpp>
//-----------------------------------------------------------------------------
class TimeToLive
{
public:
- TimeToLive( int ttl = 0 );
+ TimeToLive( uint32_t ttl = 0 );
~TimeToLive();
- int get_value() const;
- void set_value( const int ttl );
+ uint32_t get_value() const;
+ void set_value( const uint32_t ttl );
- int get_updated_value() const;
+ uint32_t get_updated_value() const;
private:
/// the numeric time-to-live
- int Ttl;
+ uint32_t Ttl;
/// the time when the time-to-live was set, so it is possible to know the
/// elapsed time
boost::posix_time::ptime TtlSetTime;