Utils/Console: Fix console crash on socket write failure
g0dil [Wed, 15 Sep 2010 15:32:22 +0000 (15:32 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1716 270642c3-0616-0410-b53a-bc976706d245

senf/Utils/Console/Server.cc
senf/Utils/Console/Server.ih

index 8eb41ac..40b4d80 100644 (file)
@@ -173,7 +173,7 @@ prefix_ void senf::console::detail::DumbClientReader::showPrompt()
     prompt += " ";
 
     stream() << std::flush;
-    handle().write(prompt);
+    v_write(prompt);
     promptLen_ = prompt.size();
     promptActive_ = true;
 }
@@ -194,7 +194,17 @@ prefix_ void senf::console::detail::DumbClientReader::v_enablePrompt()
 
 prefix_ void senf::console::detail::DumbClientReader::v_write(std::string const & data)
 {
-    handle().write(data);
+    try {
+        handle().write(data);
+    }
+    catch (std::exception & ex) {
+        SENF_LOG(("unexpected failure writing to socket:" << ex.what()));
+        stopClient(); // SUICIDE
+    }
+    catch (...) {
+        SENF_LOG(("unexpected failure writing to socket: unknown exception"));
+        stopClient(); // SUICIDE
+    }
 }
 
 prefix_ unsigned senf::console::detail::DumbClientReader::v_width()
@@ -222,7 +232,17 @@ prefix_ void senf::console::detail::NoninteractiveClientReader::v_enablePrompt()
 
 prefix_ void senf::console::detail::NoninteractiveClientReader::v_write(std::string const & data)
 {
-    handle().write(data);
+    try {
+        handle().write(data);
+    }
+    catch (std::exception & ex) {
+        SENF_LOG(("unexpected failure writing to socket:" << ex.what()));
+        stopClient(); // SUICIDE
+    }
+    catch (...) {
+        SENF_LOG(("unexpected failure writing to socket: unknown exception"));
+        stopClient(); // SUICIDE
+    }
 }
 
 prefix_ unsigned senf::console::detail::NoninteractiveClientReader::v_width()
index 2e793be..fceb6c7 100644 (file)
@@ -30,6 +30,7 @@
 #include <boost/iostreams/concepts.hpp>
 #include <boost/iostreams/stream.hpp>
 #include <set>
+#include <senf/Utils/Logger/SenfLog.hh>
 
 ///////////////////////////////ih.p////////////////////////////////////////
 
@@ -93,6 +94,8 @@ namespace detail {
     class ClientReader
     {
     public:
+        SENF_LOG_CLASS_AREA();
+
         typedef ServerHandle::ClientHandle ClientHandle;
 
         virtual ~ClientReader() = 0;