libt2n: (tomj) fixed call of virtual function close() from destructor, fixed return...
[libt2n] / src / connection.cpp
index 30a0b19..4abfad4 100644 (file)
@@ -31,8 +31,13 @@ namespace libt2n
 
 connection::~connection()
 {
-    // we want the connection_closed callbacks to be called before
-    close();
+    // Run close() manually since it's a virtual function
+    // and we are in the destructor.
+    if (!is_closed())
+    {
+        closed=true;
+        do_callbacks(connection_closed);
+    }
 
     do_callbacks(connection_deleted);
 }
@@ -46,6 +51,7 @@ void connection::close()
     }
 }
 
+/// get the number of bytes being available as next complete packet
 connection::packet_size_indicator connection::bytes_available()
 {
     // no size information -> no packet