简体   繁体   中英

boost::asio::deadline_timer not expiring after async_read() and async_write() is done in timer handler

I have an async_connected() client, single threaded, and my deadline_timer is persisted as a member of some connection class. My deadline_timer only goes off once and I'm trying to do 3 things when my deadline_timer expires:

  1. async_write on socket1
  2. async_read on socket1
  3. async_wait on this same timer as I want this timer to go off again in 4 seconds.

The send and read work, the problem is the timer never expires again. io_service.run() didn't not stop as the line right after it is not printed... Why is my deadline_timer not expiring again?

I figured out what I was doing wrong, not sure why it resulted in the symptoms that I saw, but when I read with async_read() in the deadline_timer handler, after I was done I cleared out my boost::asio::buffer receive buffer with memset() after every read. I know I probably do not need this memory cleanup. The problem was that I was clearing more memory than I gave async_read() with the receive buffer, so I was memsetting invalid locations. I am not sure why that resulted in the deadline_timer never firing again and also async_read() didn't work again after that either.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM