neuman8
neuman8

Reputation: 334

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?

Upvotes: 0

Views: 781

Answers (1)

neuman8
neuman8

Reputation: 334

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.

Upvotes: 2

Related Questions