简体   繁体   English

在async_read()和async_write()在计时器处理程序中完成后,boost :: asio :: deadline_timer未到期

[英]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. 我有一个async_connected()客户端,单线程,我的deadline_timer作为某个连接类的成员持久化。 My deadline_timer only goes off once and I'm trying to do 3 things when my deadline_timer expires: 我的deadline_timer只有一次,我在deadline_timer到期时尝试做3件事:

  1. async_write on socket1 socket1上的async_write
  2. async_read on socket1 socket1上的async_read
  3. async_wait on this same timer as I want this timer to go off again in 4 seconds. 在同一个计时器上的async_wait我希望这个计时器在4秒内再次关闭。

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? io_service.run()并没有因为没有打印后的行而停止...为什么我的deadline_timer不会再次到期?

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. 我弄清楚我做错了什么,不知道为什么它会导致我看到的症状,但是当我在deadline_timer处理程序中使用async_read()读取时,在我完成后我清除了我的boost::asio::buffer receive每次读取后用memset()缓冲。 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. 问题是我清理了比使用接收缓冲区的async_read()更多的内存,所以我设置了无效的位置。 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. 我不确定为什么导致deadline_timer再也没有触发,并且async_read()也没有再次工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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