First pass at adding in exception for servers which have gone away.
authorBrian Aker <brian@tangent.org>
Wed, 18 Apr 2012 01:32:59 +0000 (18:32 -0700)
committerBrian Aker <brian@tangent.org>
Wed, 18 Apr 2012 01:32:59 +0000 (18:32 -0700)
libtest/fatal.cc
libtest/fatal.hpp
libtest/include.am
libtest/main.cc

index 0114635b0de2dee0f18a0a132c9587e2b51b8c95..6c2dc12f9b170f866211d454770f4c76d771f0b3 100644 (file)
@@ -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
 
index 77050e517b4842a2fe445e129a54a5b6d3463995..85f0ac95a03d046e2b867e500b047db5f9d415dd 100644 (file)
@@ -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
 
index 58c7eb495e4ad67af923fef4272c5105ddce12d1..6c7e83be5d8e6bd49cbc0e75a0d0da33a0d2c1d0 100644 (file)
@@ -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\""
index ef10028c5800160dabb687448ec433b0bc0ba321..a5d90462582ca3653d73f4cd95aa4fd6e3d96597 100644 (file)
@@ -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;