Clear boost::asio::io_service after stop()

Haatschii

I am using (single threaded) a boost::asio:io_service to handle a lot of tcp connections. For each connection I use a deadline_timer to catch timeouts. If any of the connections times out, I can use none of the results of the other connections. Therefore I want to completely restart my io_service. I thought that calling io_service.stop() would allow "finished" handlers in the queue to be called and would call handlers in the queue with an error.

However it looks like the handlers remain in the queue and therefore calling io_service.reset() and later io_service.run() brings the old handlers back up. Can anyone confirm that the handlers indeed remain in the queue even after io_service.stop() is called. And if so, what are the possibilities to completly reset the io_service, e.g. remove all queued handlers?

Tanner Sansbury

io_service::stop() and io_service::reset() only control the state of the io_service's event loop; neither affect the lifespan of handlers scheduled for deferred invocation (ready-to-run) or user-defined handler objects.

The destructor for io_service will cause all outstanding handlers to be destroyed:

  • Each service object associated with the io_service will have its shutdown_service() member function invoked. Per the Service type requirement, the shutdown_service() member function will destroy all copies of user-defined handler objects that are held by the service.
  • Uninvoked handler objects scheduled for deferred invocation are destroyed for the io_service and any of its strands.

Consider either:

  • Controlling the lifespan of the io_service object. One approach can be found in this answer.
  • Running the io_service to completion. This often requires setting state, cancelling outstanding operations, and preventing completion handlers from posting additional work into the io_service. Boost.Asio provides an official timeout example, and a timeout approach with running to the io_service to completion is also shown here.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

asio :: io_service :: run은 boost :: asio :: io_service :: work가 삭제 된 후 반환되지 않습니다.

분류에서Dev

std :: thread에서 boost :: asio :: io_service :: run 호출

분류에서Dev

Using the same Boost.Asio io_service for accepting tcp connections synchronously and as a thread pool

분류에서Dev

boost :: asio :: io_service를 클래스 멤버 필드로 사용

분류에서Dev

부스트 스레드에서 boost asio io_service 실행

분류에서Dev

boost :: asio :: io_service :: run_one () 사용 방법

분류에서Dev

boost :: asio :: io_service, std :: thread, 코드 결과를 이해할 수 없음

분류에서Dev

boost :: asio :: io_service에서 run을 호출 할 때 충돌이 발생합니다.

분류에서Dev

새로운 boost :: asio :: io_service :: work 개체에 unique_ptr을 할당하는 올바른 구문?

분류에서Dev

Boost.Asio : 연결 / 소켓 당 'io_service'를 사용하는 것이 좋은가요?

분류에서Dev

Qt 이벤트 핸들러와 Boost ASIO의 io_service의 차이점은 무엇입니까?

분류에서Dev

Boost 1.70 io_service 지원 중단

분류에서Dev

Does boost::io_service::post queue request?

분류에서Dev

Boost :: Asio 타이머가 io_service :: run ()의 반환을 차단하는 것을 방지하는 방법은 무엇입니까?

분류에서Dev

asio :: io_service는 작업으로 즉시 종료됩니다.

분류에서Dev

Create timer with boost::asio

분류에서Dev

일정 시간 후 boost :: io_service 중지

분류에서Dev

io_service 실행을 유지하지 않는 asio 핸들러 부스트

분류에서Dev

boost :: asio :: spawn yield as callback

분류에서Dev

boost :: asio :: io_context :: run에 대한 혼란

분류에서Dev

빈 폴링 호출에서 boost :: asio :: io_context 중지 방지

분류에서Dev

boost::asio signal_set handler only executes after first signal is caught and ignores consecutive signals of the same type

분류에서Dev

ASIO io_service는 두 번째 run () 호출에서 사후 처리기를 처리하지 않습니다.

분류에서Dev

boost : asio io_service.run ()을 루프에서 두 번 이상 호출 할 수 있습니까?

분류에서Dev

boost :: asio의 Valgrind 오류

분류에서Dev

Taking the port from Boost Asio socket

분류에서Dev

`boost :: asio :: streambuf`에서 파생

분류에서Dev

boost :: asio :: spawn을 위해 io_context를 언제 전달해야합니까? (C ++)

분류에서Dev

Boost 1.73+ Asio의 소켓에서 io_context 참조 가져 오기

Related 관련 기사

  1. 1

    asio :: io_service :: run은 boost :: asio :: io_service :: work가 삭제 된 후 반환되지 않습니다.

  2. 2

    std :: thread에서 boost :: asio :: io_service :: run 호출

  3. 3

    Using the same Boost.Asio io_service for accepting tcp connections synchronously and as a thread pool

  4. 4

    boost :: asio :: io_service를 클래스 멤버 필드로 사용

  5. 5

    부스트 스레드에서 boost asio io_service 실행

  6. 6

    boost :: asio :: io_service :: run_one () 사용 방법

  7. 7

    boost :: asio :: io_service, std :: thread, 코드 결과를 이해할 수 없음

  8. 8

    boost :: asio :: io_service에서 run을 호출 할 때 충돌이 발생합니다.

  9. 9

    새로운 boost :: asio :: io_service :: work 개체에 unique_ptr을 할당하는 올바른 구문?

  10. 10

    Boost.Asio : 연결 / 소켓 당 'io_service'를 사용하는 것이 좋은가요?

  11. 11

    Qt 이벤트 핸들러와 Boost ASIO의 io_service의 차이점은 무엇입니까?

  12. 12

    Boost 1.70 io_service 지원 중단

  13. 13

    Does boost::io_service::post queue request?

  14. 14

    Boost :: Asio 타이머가 io_service :: run ()의 반환을 차단하는 것을 방지하는 방법은 무엇입니까?

  15. 15

    asio :: io_service는 작업으로 즉시 종료됩니다.

  16. 16

    Create timer with boost::asio

  17. 17

    일정 시간 후 boost :: io_service 중지

  18. 18

    io_service 실행을 유지하지 않는 asio 핸들러 부스트

  19. 19

    boost :: asio :: spawn yield as callback

  20. 20

    boost :: asio :: io_context :: run에 대한 혼란

  21. 21

    빈 폴링 호출에서 boost :: asio :: io_context 중지 방지

  22. 22

    boost::asio signal_set handler only executes after first signal is caught and ignores consecutive signals of the same type

  23. 23

    ASIO io_service는 두 번째 run () 호출에서 사후 처리기를 처리하지 않습니다.

  24. 24

    boost : asio io_service.run ()을 루프에서 두 번 이상 호출 할 수 있습니까?

  25. 25

    boost :: asio의 Valgrind 오류

  26. 26

    Taking the port from Boost Asio socket

  27. 27

    `boost :: asio :: streambuf`에서 파생

  28. 28

    boost :: asio :: spawn을 위해 io_context를 언제 전달해야합니까? (C ++)

  29. 29

    Boost 1.73+ Asio의 소켓에서 io_context 참조 가져 오기

뜨겁다태그

보관