libt2n: (gerd) add lots of error handling code, unit tests for this error handling...
[libt2n] / src / command_server.cpp
index cc66de4..f596860 100644 (file)
@@ -166,7 +166,21 @@ void command_server::handle(long long usec_timeout, long long* usec_timeout_rema
         unsigned int conn_id;
 
         while (s.get_packet(packet,conn_id))
-            handle_packet(packet,s.get_connection(conn_id)); 
+        {
+            server_connection* conn=s.get_connection(conn_id);
+            if (!conn)
+                EXCEPTIONSTREAM(error,logic_error,"illegal connection id " << conn_id << " received");
+
+            try
+                { handle_packet(packet,conn); }
+            catch (t2n_transfer_error &e)
+            {
+                // shut down a connection with transfer errors (usually write errors)
+                conn->close();
+            }
+            catch(...)
+                { throw; }
+        }
     }
     s.cleanup();
 }