[Cppfcplib] r14501 - trunk/apps/CppFCPLib

mkolar at freenetproject.org mkolar at freenetproject.org
Tue Aug 7 09:32:38 UTC 2007


Author: mkolar
Date: 2007-08-07 09:32:37 +0000 (Tue, 07 Aug 2007)
New Revision: 14501

Modified:
   trunk/apps/CppFCPLib/Node.h
   trunk/apps/CppFCPLib/NodeThread.cpp
   trunk/apps/CppFCPLib/NodeThread.h
Log:
*  method for retrieving reason of node failure



Modified: trunk/apps/CppFCPLib/Node.h
===================================================================
--- trunk/apps/CppFCPLib/Node.h	2007-08-07 06:46:17 UTC (rev 14500)
+++ trunk/apps/CppFCPLib/Node.h	2007-08-07 09:32:37 UTC (rev 14501)
@@ -12,6 +12,7 @@
 #include "TQueue.h"
 #include "NodeThread.h"
 #include "AdditionalFields.h"
+#include "Exceptions.h"
 
 #include "sha256.h"
 
@@ -44,11 +45,17 @@
   void shutdown();
 
   bool isAlive() const {
-    return nodeThread->isAlive();
+    return nodeThread->isAlive_;
   }
-
+  bool hasFailure() const {
+    return nodeThread->hasException_;
+  }
   std::exception getFailure() const {
-    return *nodeThread->getFailure();
+    if ( nodeThread->isAlive_ )
+      throw std::logic_error("There is no failure");
+    if (! nodeThread->hasException_ )
+      throw std::logic_error("Cannot retrieve the reason of a failure");
+    return *(nodeThread->getFailure());
   }
 
   const Message::Ptr getNodeHelloMessage() const;

Modified: trunk/apps/CppFCPLib/NodeThread.cpp
===================================================================
--- trunk/apps/CppFCPLib/NodeThread.cpp	2007-08-07 06:46:17 UTC (rev 14500)
+++ trunk/apps/CppFCPLib/NodeThread.cpp	2007-08-07 09:32:37 UTC (rev 14501)
@@ -17,7 +17,8 @@
     host_(host),
     port_(port),
     s(new Server( host_, port_ )),
-    isAlive_(true)
+    isAlive_(true),
+    hasException_(false)
 {
 }
 
@@ -57,18 +58,18 @@
     // some error has occured, keep the thread so you can access the isAlive and getFailure
     log().log(ERROR, "_mgrThreag: Caught std::runtime_error");
     log().log(ERROR, e.what());
-    isAlive_ = false;
+    isAlive_ = false; hasException_ = true;
     exception = ZThread::CountedPtr<std::exception> ( new std::runtime_error(e) );
   } catch (std::exception& e) {
     // some error has occured, keep the thread so you can access the isAlive and getFailure
     log().log(ERROR, "_mgrThreag: Caught std::exception");
     log().log(ERROR, e.what());
-    isAlive_ = false;
+    isAlive_ = false; hasException_ = true;
     exception = ZThread::CountedPtr<std::exception> ( new std::exception(e) );
   } catch (...) {
     // thread is stopped and
     log().log(ERROR, "_mgrThreag: Caught something else");
-    isAlive_ = false;
+    isAlive_ = false; hasException_ = false;
     return;
   }
   try {

Modified: trunk/apps/CppFCPLib/NodeThread.h
===================================================================
--- trunk/apps/CppFCPLib/NodeThread.h	2007-08-07 06:46:17 UTC (rev 14500)
+++ trunk/apps/CppFCPLib/NodeThread.h	2007-08-07 09:32:37 UTC (rev 14501)
@@ -28,6 +28,7 @@
   boost::shared_ptr<Server> s;
 
   bool isAlive_;
+  bool hasException_;
   ZThread::CountedPtr<std::exception> exception;
 
   std::map<std::string, JobTicket::Ptr > jobs[2]; // 0 -- local jobs, 1 -- global jobs
@@ -39,9 +40,6 @@
   void doMessage(ServerMessage::Ptr message);
 public:
   void run();
-  bool isAlive() const {
-    return isAlive_;
-  }
   ZThread::CountedPtr<std::exception> getFailure() const {
     return exception;
   }




More information about the Cppfcplib mailing list