[Cppfcplib] r14353 - trunk/apps/CppFCPLib

mkolar at freenetproject.org mkolar at freenetproject.org
Wed Jul 25 21:22:59 UTC 2007


Author: mkolar
Date: 2007-07-25 21:22:59 +0000 (Wed, 25 Jul 2007)
New Revision: 14353

Modified:
   trunk/apps/CppFCPLib/Node.cpp
   trunk/apps/CppFCPLib/Node.h
Log:
* node shutdown implemented



Modified: trunk/apps/CppFCPLib/Node.cpp
===================================================================
--- trunk/apps/CppFCPLib/Node.cpp	2007-07-25 21:09:41 UTC (rev 14352)
+++ trunk/apps/CppFCPLib/Node.cpp	2007-07-25 21:22:59 UTC (rev 14353)
@@ -633,3 +633,30 @@
   log().log(DEBUG, "waiting for EndListPersistentRequests message");
   job->wait(globalCommandsTimeout);
 }
+
+void
+Node::shutdown()
+{
+  log().log(DEBUG, "about to shutdown the node");
+  Message::Ptr m = Message::factory( std::string("Shutdown") );
+  JobTicket::Ptr job = JobTicket::factory( "", m );
+  clientReqQueue->put(job);
+
+  try {
+    job->wait(globalCommandsTimeout);
+    Response resp = job->getResponse();
+
+    try {
+      checkProtocolError(resp);
+    } catch ( FCPException& e) {
+      if ( boost::lexical_cast<int>( e.getMessage()->getField("Code") ) != 18 )
+        throw e;
+      executor.interrupt();
+      log().log(DEBUG, "node is shutdown");
+    }
+  } catch (...) {
+    log().log(ERROR, "error has occured while node shutdown, kill thread anyway");
+    executor.interrupt();
+    log().log(DEBUG, "node thread killed");
+  }
+}

Modified: trunk/apps/CppFCPLib/Node.h
===================================================================
--- trunk/apps/CppFCPLib/Node.h	2007-07-25 21:09:41 UTC (rev 14352)
+++ trunk/apps/CppFCPLib/Node.h	2007-07-25 21:22:59 UTC (rev 14353)
@@ -41,11 +41,7 @@
     globalCommandsTimeout = t; return *this;
   }
 
-  void shutdown() {
-    log().log(DEBUG, "about to shutdown the node");
-    executor.interrupt();
-    log().log(DEBUG, "node is shutdown");
-  }
+  void shutdown();
 
   bool isAlive() const {
     return nodeThread->isAlive();




More information about the Cppfcplib mailing list