[Cppfcplib] r14296 - in trunk/apps/CppFCPLib: . examples

mkolar at freenetproject.org mkolar at freenetproject.org
Tue Jul 24 10:53:42 UTC 2007


Author: mkolar
Date: 2007-07-24 10:53:41 +0000 (Tue, 24 Jul 2007)
New Revision: 14296

Modified:
   trunk/apps/CppFCPLib/Node.h
   trunk/apps/CppFCPLib/NodeThread.cpp
   trunk/apps/CppFCPLib/examples/list_peers.cpp
   trunk/apps/CppFCPLib/todo.txt
Log:
*  node shutdown
*  solved problems with accessing thread local storage



Modified: trunk/apps/CppFCPLib/Node.h
===================================================================
--- trunk/apps/CppFCPLib/Node.h	2007-07-24 09:26:38 UTC (rev 14295)
+++ trunk/apps/CppFCPLib/Node.h	2007-07-24 10:53:41 UTC (rev 14296)
@@ -41,6 +41,11 @@
     globalCommandsTimeout = t; return *this;
   }
 
+  void shutdown() {
+    log().log(DEBUG, "about to shutdown the node");
+    executor.interrupt();
+  }
+
   bool isAlive() const {
     return nodeThread->isAlive();
   }

Modified: trunk/apps/CppFCPLib/NodeThread.cpp
===================================================================
--- trunk/apps/CppFCPLib/NodeThread.cpp	2007-07-24 09:26:38 UTC (rev 14295)
+++ trunk/apps/CppFCPLib/NodeThread.cpp	2007-07-24 10:53:41 UTC (rev 14296)
@@ -46,27 +46,38 @@
       Thread::sleep(100);  // do I need this?
     }
   } catch (ZThread::Synchronization_Exception& e) {
+    // thread was interupted, normal way to shutdown the thread
+    // this object will be destroyed
     log().log(ERROR, "_mgrThread: Caught Synchronization_Exception");
-    isAlive_ = false;
-    exception = ZThread::CountedPtr<std::exception> ( new std::runtime_error(e.what()) );
     return;
   } catch (std::runtime_error& e) {
+    // some error has occured, keep the thread so you can access the isAlive and getFailure
     log().log(ERROR, "_mgrThreag: Caught std::runtime_error");
     isAlive_ = false;
     exception = ZThread::CountedPtr<std::exception> ( new std::runtime_error(e) );
-    return;
   } 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");
     isAlive_ = false;
     exception = ZThread::CountedPtr<std::exception> ( new std::exception(e) );
-    return;
   } catch (...) {
+    // thread is stopped and
     log().log(ERROR, "_mgrThreag: Caught something else");
     isAlive_ = false;
     return;
   }
-  // TODO: catch more specific exceptions as well
-  // TODO: what does happen to this object when exception is thrown?
+  try {
+    while (!Thread::interrupted()) {
+      // dummy loop, wait untill interrupt
+      Thread::sleep(1000);
+      Thread::yield();
+    }
+  } catch (ZThread::Synchronization_Exception& e) {
+    // thread was interupted, normal way to shutdown the thread
+    // this object will be destroyed
+    log().log(ERROR, "_mgrThread: Caught Synchronization_Exception");
+    return;
+  }
 }
 
 void

Modified: trunk/apps/CppFCPLib/examples/list_peers.cpp
===================================================================
--- trunk/apps/CppFCPLib/examples/list_peers.cpp	2007-07-24 09:26:38 UTC (rev 14295)
+++ trunk/apps/CppFCPLib/examples/list_peers.cpp	2007-07-24 10:53:41 UTC (rev 14296)
@@ -5,14 +5,21 @@
 
 int main() {
   Node n("List Peers Test", "", -1);
-  MessagePtrContainer peers = n.listPeers();
+  AdditionalFields fs;
+
+  fs.addField("WithMetadata", true);
+  fs.addField("WithVolatile", true);
+
+  MessagePtrContainer peers = n.listPeers(fs);
   
   for (MessagePtrContainer::iterator it = peers.begin();
        it != peers.end();
        ++it) {
+    //    std::cout << "Identity :: " << (*it)->getField("identity") << std::endl;
     std::cout << (*it)->toString() << std::endl;
     std::cout << std::endl;
   }
+  n.shutdown();
 
   return 0;
 }

Modified: trunk/apps/CppFCPLib/todo.txt
===================================================================
--- trunk/apps/CppFCPLib/todo.txt	2007-07-24 09:26:38 UTC (rev 14295)
+++ trunk/apps/CppFCPLib/todo.txt	2007-07-24 10:53:41 UTC (rev 14296)
@@ -2,7 +2,6 @@
 ====
 
 *  work on logging messages...
-*  check what happens when the exception is thrown in the NodeThread, is the object still alive, or is it destroyed once it exits the run...
 *  peerNoteType is always one? 
 *  how should I read a file from TestDDAReply (binary mode or textual mode)
 *  delete created tmp file in TestDDA




More information about the Cppfcplib mailing list