Boost C++ Libraries/Boost.Asio

Boost.Asio 색인 - basic_deadline_timer::rebind_executor::other

까마귀75 2021. 2. 18. 13:07
728x90
반응형

basic_deadline_timer::rebind_executor::other

주어진 실행기(executor)로 리바인드 할 때의 타이머 유형이다.

typedef basic_deadline_timer< Time, TimeTraits, Executor1 > other;

유 형

이 름 설 명
rebind_executor 타이머 유형을 다른 실행기(executor)로 리바인딩한다.
duration_type 유지 기간 유형이다.
executor_type 개체와 연결된 실행기(executor)의 유형이다.
time_type 시간 유형이다.
traits_type 시간 특성 유형이다.

멤버 함수

이 름 설 명
async_wait 타이머에서 비동기 대기를 시작한다.
basic_deadline_timer
[constructor]
기본 생성자.

특정 만료 시간을 절대 시간으로 설정하는 생성자.

특정 만료 시간을 상대 시간으로 설정하는 생성자.

다른 basic_deadline_timer에서 이동 생성한다.
cancel 타이머에서 대기중인 모든 비동기 작업을 취소한다.
cancel_one 타이머에서 대기중인 하나의 비동기 작업을 취소한다.
expires_at 타이머의 만료 시간을 절대 시간으로 가져온다.

타이머의 만료 시간을 절대 시간으로 설정한다.
expires_from_now 타이머의 만료 시간을 상대 시간으로 가져온다.

타이머의 만료 시간을 상대 시간으로 설정한다.
get_executor 개체와 연결된 실행기(executor)를 가져온다.
operator= 다른 basic_deadline_timer에서 이동 할당한다.
wait 타이머에서 블럭 대기를 수행한다.
~basic_deadline_timer
[destructor]
타이머를 소멸한다.

basic_deadline_timer 클래스 템플릿은 타이머가 만료될 때까지 블럭 또는 비동기 대기를 수행하는 기능을 제공한다.

데드라인 타이머는 항상 두 가지 상태("expired:만료됨" 또는 "not expired:만료되지 않음") 중 하나의 상태를 갖는다. 만료된 타이머에서 wait() 또는 async_wait() 함수가 호출되면, 대기 작업은 즉시 완료된다.

대부분의 응용프로그램은 deadline_timer typedef를 사용한다.

스레드 안전성

고유 개체: 안전함
공유 개체: 안전하지 않음

예 제

블럭 대기 수행:

// Construct a timer without setting an expiry time.
boost::asio::deadline_timer timer(my_context);

// Set an expiry time relative to now.
timer.expires_from_now(boost::posix_time::seconds(5));

// Wait for the timer to expire.
timer.wait();

비동기 대기 수행:

void handler(const boost::system::error_code& error)
{
  if (!error)
  {
    // Timer expired.
  }
}

...

// Construct a timer with an absolute expiry time.
boost::asio::deadline_timer timer(my_context,
    boost::posix_time::time_from_string("2005-12-07 23:59:59.000"));

// Start an asynchronous wait.
timer.async_wait(handler);

사용중인 deadline_timer의 만료 시간 변경

보류중인 비동기 대기가 있는 상태에서 타이머의 만료 시간을 변경하면 해당 대기 작업이 취소된다. 타이머와 관련된 작업이 한번만 수행되도록 하려면 다음과 같이 사용한다:

void on_some_event()
{
  if (my_timer.expires_from_now(seconds(5)) > 0)
  {
    // We managed to cancel the timer. Start new asynchronous wait.
    my_timer.async_wait(on_timeout);
  }
  else
  {
    // Too late, timer has already expired!
  }
}

void on_timeout(const boost::system::error_code& e)
{
  if (e != boost::asio::error::operation_aborted)
  {
    // Timer was not cancelled, take necessary action.
  }
}
  • boost::asio::basic_deadline_timer::expires_from_now() 함수는 보류중인 비동기 대기를 취소하고 취소된 비동기 대기 갯수를 반환한다. 0을 반환하면 취소가 너무 늦은 것이고, 대기 핸들러가 이미 실행되거나 곧 실행될 것입니다. 1을 반환하면 대기 핸들러가 성공적으로 취소된 것입니다.
  • 대기 핸들러가 취소되면, 전달된 boost::system::error_code에는 boost::asio::error::operation_aborted 값이 포함된다.

요구 사항

일반 헤더: boost/asio/basic_deadline_timer.hpp
편의 헤더: boost/asio.hpp

Boost.Asio 홈

728x90
반응형