From ffade15f8c3b3fb29d6daf901f931d586da2b3e1 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Tue, 17 Apr 2012 18:32:59 -0700 Subject: [PATCH] First pass at adding in exception for servers which have gone away. --- libtest/fatal.cc | 14 ++++++++++++++ libtest/fatal.hpp | 23 +++++++++++++++++++++++ libtest/include.am | 1 - libtest/main.cc | 4 ++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/libtest/fatal.cc b/libtest/fatal.cc index 0114635b..6c2dc12f 100644 --- a/libtest/fatal.cc +++ b/libtest/fatal.cc @@ -65,5 +65,19 @@ void fatal::increment_disabled_counter() _counter++; } +disconnected::disconnected(const char *file, int line, const char *func, const char *instance, const in_port_t port, const char *format, ...) : + _port(port), + std::runtime_error(func) +{ + strncpy(_instance, instance, sizeof(_instance)); + va_list args; + va_start(args, format); + char last_error[BUFSIZ]; + (void)vsnprintf(last_error, sizeof(last_error), format, args); + va_end(args); + + snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", file, int(line), last_error, func); +} + } // namespace libtest diff --git a/libtest/fatal.hpp b/libtest/fatal.hpp index 77050e51..85f0ac95 100644 --- a/libtest/fatal.hpp +++ b/libtest/fatal.hpp @@ -52,6 +52,29 @@ private: char _error_message[BUFSIZ]; }; +class disconnected : std::runtime_error +{ +public: + disconnected(const char *file, int line, const char *func, const char *instance, const in_port_t port, const char *format, ...); + + const char* what() const throw() + { + return _error_message; + } + + // The following are just for unittesting the exception class + static bool is_disabled(); + static void disable(); + static void enable(); + static uint32_t disabled_counter(); + static void increment_disabled_counter(); + +private: + char _error_message[BUFSIZ]; + in_port_t _port; + char _instance[1024]; +}; + } // namespace libtest diff --git a/libtest/include.am b/libtest/include.am index 58c7eb49..6c7e83be 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -132,7 +132,6 @@ libtest_libtest_la_SOURCES+= libtest/strerror.cc libtest_libtest_la_SOURCES+= libtest/tmpfile.cc libtest_libtest_la_SOURCES+= libtest/vchar.cc -libtest_libtest_la_CXXFLAGS+= ${NO_CONVERSION} libtest_libtest_la_CXXFLAGS+= -DBUILDING_LIBTEST libtest_libtest_la_CXXFLAGS+= $(PTHREAD_CFLAGS) libtest_libtest_la_CXXFLAGS+= -DLIBTEST_TEMP="\"tmp_chroot\"" diff --git a/libtest/main.cc b/libtest/main.cc index ef10028c..a5d90462 100644 --- a/libtest/main.cc +++ b/libtest/main.cc @@ -466,6 +466,10 @@ cleanup: { std::cerr << e.what() << std::endl; } + catch (libtest::disconnected& e) + { + std::cerr << "Unhandled disconnection occurred:" << e.what() << std::endl; + } catch (std::exception& e) { std::cerr << e.what() << std::endl; -- 2.30.2