asio: how to handle unreliable network/glitches/server down ?

Ok. I am a newbie to asio so bear with me: I have the following piece of code for handling a unreliable network and/or server crashed/servicing where I do not want the client to fail. My solution basically involves looping round , sleeping and trying again. .... int no_of_tries = clientEnv.no_of_tries(); while ( no_of_tries > 0 ) { try { boost::asio::io_service io_service; Client theClient( io_service, clientEnv.get_cmd(), clientEnv.host(), clientEnv.port() ); io_service.run(); ... // Some kind of connection error fall through and try again. } catch (std::exception& e) { .... } sleep( RETRY_POLL_PERIOD ); no_of_tries--; } This does not seem right to me, but I am not sure how typical my case is. Are there any known design patterns/idioms that provide a more robust ways of handling unreliable networks/glitches and cases where the server needs to be taken down temporarily ? Best regards, Ta, Avi
participants (1)
-
Avi Bahra