|
Boost Users : |
Subject: [Boost-users] asio: how to handle unreliable network/glitches/server down ?
From: Avi Bahra (avibahra_at_[hidden])
Date: 2010-03-25 14:08:52
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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net