src.ctf.lttng-live: use viewer_connection_close_socket more
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 26 Jul 2022 21:51:07 +0000 (17:51 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 23 Aug 2022 16:06:16 +0000 (12:06 -0400)
Use viewer_connection_close_socket at all spots we close the control
socket, to de-duplicate code a little bit.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I47ce5bf00edd367792a8f8262d746a61b0c474fd
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8484
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/plugins/ctf/lttng-live/viewer-connection.cpp

index 937f7b283ca7304a5fe51f2ff2e3f5754fc4caed..bdd67532a203937f20b11a1be0cc59b2f51d3801 100644 (file)
@@ -175,6 +175,10 @@ viewer_status_to_ctf_msg_iter_medium_status(enum lttng_live_viewer_status viewer
 
 static inline void viewer_connection_close_socket(struct live_viewer_connection *viewer_connection)
 {
+    if (viewer_connection->control_sock == BT_INVALID_SOCKET) {
+        return;
+    }
+
     int ret = bt_socket_close(viewer_connection->control_sock);
     if (ret == -1) {
         const bt2_common::LogCfg& logCfg = viewer_connection->logCfg;
@@ -497,29 +501,12 @@ lttng_live_connect_viewer(struct live_viewer_connection *viewer_connection)
     goto end;
 
 error:
-    if (viewer_connection->control_sock != BT_INVALID_SOCKET) {
-        if (bt_socket_close(viewer_connection->control_sock) == BT_SOCKET_ERROR) {
-            BT_CLOGW("Error closing socket: %s.", bt_socket_errormsg());
-        }
-    }
-    viewer_connection->control_sock = BT_INVALID_SOCKET;
+    viewer_connection_close_socket(viewer_connection);
+
 end:
     return status;
 }
 
-static void lttng_live_disconnect_viewer(struct live_viewer_connection *viewer_connection)
-{
-    const bt2_common::LogCfg& logCfg = viewer_connection->logCfg;
-
-    if (viewer_connection->control_sock == BT_INVALID_SOCKET) {
-        return;
-    }
-    if (bt_socket_close(viewer_connection->control_sock) == BT_SOCKET_ERROR) {
-        BT_CLOGW("Error closing socket: %s", bt_socket_errormsg());
-        viewer_connection->control_sock = BT_INVALID_SOCKET;
-    }
-}
-
 static int list_update_session(bt2::ArrayValue results, const struct lttng_viewer_session *session,
                                bool *_found, struct live_viewer_connection *viewer_connection)
 {
@@ -1635,7 +1622,7 @@ live_viewer_connection::~live_viewer_connection()
              "relay-url=\"%s\"",
              this->url.c_str());
 
-    lttng_live_disconnect_viewer(this);
+    viewer_connection_close_socket(this);
 
     bt_socket_fini();
 }
This page took 0.028104 seconds and 5 git commands to generate.