libt2n: (gerd) socket reconnect added (incl. unit tests)
[libt2n] / src / socket_client.cpp
index 8b70511..4f4975f 100644 (file)
@@ -185,4 +185,21 @@ void socket_client_connection::close()
     }
 }
 
+/** @brief try to reconnect the current connection with the same connection credentials (host and port or path)
+*/
+void socket_client_connection::reconnect()
+{
+    // close the current connection if still open
+    close();
+
+    socket_type_value type=get_type();
+
+    if (type == tcp_s)
+        tcp_connect(max_retries);
+    else if (type == unix_s)
+        unix_connect(max_retries);
+
+    reopen();
+}
+
 }