本文整理汇总了C++中boost::asio::deadline_timer::expires_from_now方法的典型用法代码示例。如果您正苦于以下问题:C++ deadline_timer::expires_from_now方法的具体用法?C++ deadline_timer::expires_from_now怎么用?C++ deadline_timer::expires_from_now使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::asio::deadline_timer
的用法示例。
在下文中一共展示了deadline_timer::expires_from_now方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: timeout
void timeout(const boost::system::error_code &e) {
if(
mum!=nullptr &&
m_audiofifo!=nullptr &&
mum->getConnectionState()==mumlib::ConnectionState::CONNECTED &&
m_audiofifo->getNoOfFrames() >= output_frame_size
) {
timer.expires_from_now(boost::posix_time::milliseconds(60));
auto packet=m_audiofifo->getAudio();
mum->sendAudioData(packet->m_samples, output_frame_size, mumlib::SourceAudioPacketType::FLOAT);
delete packet;
} else {
timer.expires_from_now(boost::posix_time::seconds(2));
}
timer.async_wait(timeout_handler);
};
示例2: start
void start(FIFO_TYPE *audiofifo) {
m_audiofifo = audiofifo;
if(running)
return;
timer.expires_from_now(boost::posix_time::seconds(2));
timer.async_wait(timeout_handler);
}
示例3: print
void print(const boost::system::error_code& e)
{
std::cout << i++ << ": Hello, world!\n";
std::cout << e << std::endl;
t.expires_from_now(boost::posix_time::seconds(1));
t.async_wait(print);
}
示例4: set_timer
inline void set_timer(io::deadline_timer& timer, uint64_t milliseconds,
Handler&& handler) {
if (milliseconds != length_framed_connection::no_deadline) {
timer.expires_from_now(boost::posix_time::milliseconds(milliseconds));
timer.async_wait(std::forward<Handler>(handler));
}
}
示例5: on_check
void thread_pool_checker::on_check(const boost::system::error_code& error)
{
// On error, return early.
if (error)
return;
// Check how long this job was waiting in the service queue. This
// returns the expiration time relative to now. Thus, if it expired
// 7 seconds ago, then the delta time is -7 seconds.
boost::posix_time::time_duration delta = timer_.expires_from_now();
long wait_in_seconds = -delta.seconds();
// If the time delta is greater than the threshold, then the job
// remained in the service queue for too long, so increase the
// thread pool.
std::cout << "Job job sat in queue for " << wait_in_seconds << " seconds."
<< std::endl;
if (threshold_seconds_ < wait_in_seconds)
{
std::cout << "Increasing thread pool." << std::endl;
threads_.create_thread(
boost::bind(&boost::asio::io_service::run, &io_service_));
}
// Otherwise, schedule another pool check.
run();
}
示例6: check_interrupt
static void check_interrupt( boost::asio::deadline_timer& c )
{
if( boost::this_thread::interruption_requested() )
throw std::runtime_error("Thread interrupted.");
c.expires_from_now( boost::posix_time::seconds(1) );
c.async_wait( boost::bind( &listener::check_interrupt, boost::ref(c) ) );
}
示例7: Wait
void Wait() {
if (!queue_.empty()) {
std::cout << "t0 + " << std::setw(4) << mark() << "ms Open for Number : " << type << " (dur:" << queue_.front() << ") (depth " << queue_.size() << ")\n";
timer_.expires_from_now(boost::posix_time::milliseconds(queue_.front()));
timer_.async_wait(strand_.wrap(std::bind(&Session::Close, shared_from_this())));
}
}
示例8: handle_timer
//---------------------------------------------------------
void handle_timer(boost::asio::deadline_timer& timer, const boost::system::error_code& ec)
{
std::cout<<"*"<<std::flush;
timer.expires_from_now(boost::posix_time::seconds(1)); ///!\ important /!\ got to be reset
timer.async_wait(boost::bind(handle_timer, boost::ref(timer), boost::asio::placeholders::error));
}
示例9: justdoit
void justdoit()
{
rc_->get(strand_.wrap(
boost::bind(&tormoz_get::handle_done, shared_from_this(), _1, _2))
);
timer_.expires_from_now(boost::posix_time::milliseconds(100));
timer_.async_wait(strand_.wrap(boost::bind(&tormoz_get::handle_timeout, shared_from_this(), _1)));
}
示例10: on_open
void on_open() override {
auto self(shared_from_this());
std::cout << "WebSocket connection open\n";
timer_.expires_from_now(boost::posix_time::milliseconds(100));
timer_.async_wait([this, self](const boost::system::error_code &ec) {
timer_cb(ec);
});
}
示例11: do_timer
void do_timer(const boost::system::error_code&)
{
callback();
// reset the timer
timer.expires_from_now(checkpoint_interval);
timer.async_wait(boost::bind(&handlers::do_timer, this, _1));
}
示例12: reconnect
void reconnect() {
if (m_abort || m_reconnect_secs <= 0)
return;
m_reconnect_timer.expires_from_now(boost::posix_time::seconds(m_reconnect_secs));
m_reconnect_timer.async_wait(
boost::bind(&self::timer_reconnect, this->shared_from_this(),
boost::asio::placeholders::error));
}
示例13: keepRunning
void PionScheduler::keepRunning(boost::asio::io_service& my_service,
boost::asio::deadline_timer& my_timer)
{
if (m_is_running) {
// schedule this again to make sure the service doesn't complete
my_timer.expires_from_now(boost::posix_time::seconds(KEEP_RUNNING_TIMER_SECONDS));
my_timer.async_wait(boost::bind(&PionScheduler::keepRunning, this,
boost::ref(my_service), boost::ref(my_timer)));
}
}
示例14: set_timeout
inline void wamp_dealer_invocation::set_timeout(timeout_callback callback, unsigned timeout_ms)
{
// Do not allow setting a timeout value of 0 as this is a
// special timeout value indicating infinite timeout. So
// insted we just don't arm the timer which gives us an
// infinite timeout.
if (timeout_ms) {
m_timeout_timer.expires_from_now(boost::posix_time::milliseconds(timeout_ms));
m_timeout_timer.async_wait(callback);
}
}
示例15: handlers
handlers(boost::asio::io_service& io_service, std::function<void()> callback)
: callback(callback)
, signals(io_service, SIGHUP, SIGTERM, SIGINT)
, timer(io_service)
, checkpoint_interval(boost::posix_time::hours(1))
{
signals.async_wait(boost::bind(&handlers::do_signal, this, _1, _2));
// set the timer
timer.expires_from_now(checkpoint_interval);
timer.async_wait(boost::bind(&handlers::do_timer, this, _1));
}