Boost logo

Boost Users :

Subject: [Boost-users] [boost][asio] deadline_timer doesn't delays - async_wait invokes handler at once
From: tomasz jankowski (tomasz_jacek_at_[hidden])
Date: 2009-01-29 03:48:55


Hello,

I would like to add timeout to my server which is based on "http server
3" example. But I don't know why but I can't force deadline_timer to
work properly. deadline_timer doesn't delays invoking of handler.

please look how I modified source code of connection::start() in "http
server 3" example. I did it according to suggestion placed on
http://lists.boost.org/Archives/boost/2007/04/120339.php

Could someone tell me what I.m doing wrong?

tom

void set_result(boost::optional<boost::system::error_code>* a,
boost::system::error_code b)
{
  a->reset(b);
}

void connection::start()
{

  boost::optional<boost::system::error_code> timer_result;
  boost::asio::deadline_timer
timer(socket_.io_service(),boost::posix_time::seconds(5));
  timer.async_wait(boost::bind(set_result, &timer_result, _1));
 
  boost::optional<boost::system::error_code> read_result;

  socket_.async_read_some(boost::asio::buffer(buffer_),
      strand_.wrap(
        boost::bind(&connection::handle_read, shared_from_this(),
          boost::asio::placeholders::error,
          boost::asio::placeholders::bytes_transferred)));

  socket_.io_service().reset();
  while (socket_.io_service().run_one())
   {
     if (read_result){
       timer.cancel();
     }else if(timer_result) {
       socket_.cancel();
     }
  }
 
  if (*read_result) {
    throw boost::system::system_error(*read_result);
  }

}

----------------------------------------------------
Pierwszy w Polsce profesjonalny serwis o modelkach!
Zobacz zdjêcia, video i piêkne kobiety. - Kliknij:
http://klik.wp.pl/?adr=http%3A%2F%2Fcorto.www.wp.pl%2Fas%2Falemodelki.html&sid=626


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