From 7840efbac51790a9e32aa5c5dd2196cd8c68495d Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Tue, 26 May 2015 10:09:50 +0200 Subject: [PATCH] removed the main while loop because if catch an exception cannot know state of pingers, so better to fail and re-start binary completely --- src/main.cpp | 45 +++++++++------------------------------------ 1 files changed, 9 insertions(+), 36 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 72157ff..22273bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -477,8 +477,6 @@ int main( int argc, const char *argv[] ) PingSchedulerList scheduler_list; IoServiceItem io_service; int ret_code = 0; - unsigned n_exceptions = 0; - unsigned max_exceptions = 0; try { @@ -558,51 +556,27 @@ int main( int argc, const char *argv[] ) { GlobalLogger.error() << "Uncaught exception. " << ex.what() << endl; ret_code = 3; - ++n_exceptions; } catch (...) { GlobalLogger.error() << "Caught unknown exception!" << endl; ret_code = 4; - ++n_exceptions; } if ( ret_code == 0 ) { GlobalLogger.info() << "starting io_service main loop" << endl; - if (max_exceptions > 0) - GlobalLogger.warning() << "Limited number of acceptable exceptions," - << " this is a debugging option!"; - // call boost::asio main event loop, catching exceptions - while ( !signal_data.stopped ) + try + { + io_service->run(); + } + catch ( const std::exception &ex ) { - try - { - io_service->run(); - } - catch ( const std::exception &ex ) - { - ++n_exceptions; - GlobalLogger.error() << "Caught exception, will continue. " << ex.what() << endl; - } - catch (...) { - ++n_exceptions; - GlobalLogger.error() << "Caught unknown exception, will continue!" << endl; - } - - if (max_exceptions > 0 && n_exceptions >= max_exceptions) - { - GlobalLogger.info() << "reached max number of exceptions allowed in main loop" << endl; - io_service->stop(); - signal_data.stopped = true; - break; - } - else if ( signal_data.stopped ) - GlobalLogger.info() << "exiting io_service main loop" << endl; - // ( io_service->stop() has been called already in signal handler) - else - GlobalLogger.info() << "continuing io_service main loop" << endl; + GlobalLogger.error() << "Caught exception, will continue. " << ex.what() << endl; + } + catch (...) { + GlobalLogger.error() << "Caught unknown exception, will continue!" << endl; } } @@ -624,6 +598,5 @@ int main( int argc, const char *argv[] ) } GlobalLogger.notice() << "Pingcheck done " << endl; - GlobalLogger.debug() << "In main loop, had " << n_exceptions << " exception[s]" << endl; return ret_code; } -- 1.7.1