Jump to content
  • Advertisement
Sign in to follow this  
SiS-Shadowman

boost::asio::io_service::run blocks for a long time

This topic is 3090 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using boost::asio in a resource aquisition chain where resources are loaded from memory, the filesystem or the network, depending on their presence and validity in the given location. I used to run all 3 systems in one thread since there is not so much benefit in running 3 threads in my case, however this "lag" forced me to split them up, otherwise the entire resource chain is stalled.

This is the order of calls that produce the undesired behaviour:
-tcp::resolver::async_resolve (bound to resolved)
-io_service::run
--resolved => async_connect (bound to connected)
--connected
This first call to io_service::run returns about 15-30 seconds AFTER connected has been called from the io_service.
All subsequent calls however seem to take almost no time, even when I create about 4 sockets per second.

Does anyone know this kind of behaviour or have any suggestion on how I could avoid it?
One possible "solution" would be to create a dummy socket at startup, but I don't feel comfortable about it, since I could be using boost::asio in the wrong way.

Share this post


Link to post
Share on other sites
Advertisement
Probably some obscure issue.

Also, the time to measure is until each completion happens, not until run() returns. Typically, run will only exit when there are no more pending requests, which will likely be when application is cleanly shutting down.

Measure how long each individual part takes, and monitor what's going on with WireShark or similar.

Share this post


Link to post
Share on other sites
Thanks to your explaination, I figured it out. The run method was waiting for my timers to expire (which are set to 20 seconds). I forgot to cancel them after I closed my sockets, causing run to no return until they timed out.
Things are running smoothly now, thanks :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!