libt2n: (gerd) make handle-function on server reentrant
[libt2n] / src / command_client.cpp
index 8ccbf10..63ff539 100644 (file)
@@ -49,8 +49,25 @@ command_client::command_client(client_connection* _c, long long _command_timeout
     c->add_callback(new_connection,bind(&command_client::read_hello, boost::ref(*this)));
 
     // don't expect hello from an always closed connection (like dummy_client_connection)
-    if (!c->is_closed())
-        read_hello();
+    if (!is_connection_closed())
+    {
+        try
+        {
+            read_hello();
+        }
+        catch (t2n_communication_error &e)
+        {
+            c->close();
+
+            // store a copy of the exception that you can find out details about the error later
+            std::auto_ptr<t2n_exception> tmp(e.clone());
+            constructorException=tmp;
+        }
+        catch (...)
+        {
+            throw;
+        }
+    }
 }
 
 /** @brief replace the connection currently in use with a new one
@@ -197,6 +214,9 @@ void command_client::send_command(command* cmd, result_container &res)
     command_container cc(cmd);
     boost::archive::binary_oarchive oa(ofs);
 
+    if (is_connection_closed())
+        throw t2n_transfer_error("connection to server is closed");
+
     try
     {
         oa << cc;