Boost logo

Boost Users :

Subject: [Boost-users] boost::asio::deadline_timer::expires_at() seems to have a bug
From: Hite, Christopher (Christopher.Hite_at_[hidden])
Date: 2010-05-21 09:52:39


See the #if below. I'm pretty sure these should do the same thing. The
expires_from_now() version does what I'd expect and calls onTimer() once
a second.

The expires_at() version never calls onTimer(). Even though
'expires_at() const' returns 1s from now:
doit now =2010-May-21 15:07:24.882854
expires_at =2010-May-21 15:07:25.882854
<and nothing more>

//**********************************************************************
***********

#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

#include <iostream>

using std::cout;

using namespace boost::asio;
using namespace boost::posix_time;

io_service ioService;
deadline_timer timer(ioService);
seconds s1(1);

void doit();

void onTimer(const boost::system::error_code&){
        doit(); //repeat forever
}

void doit(){
        ptime now=microsec_clock::local_time();
        cout<< "doit now ="<< now <<std::endl;

#if 0
        timer.expires_from_now(s1); //works
#else
        timer.expires_at( now+s1); //doesn't work
#endif

        timer.async_wait( onTimer );

        cout<< "expires_at ="<< timer.expires_at()<< std::endl ;
}

void timerTest(){
        doit();
        io_service::work w(ioService);
        ioService.run();
}

int main(){
        timerTest();
        return 0;
}



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net