[gst-debugger] debugserver: expose max simultaneous connections to configuration



commit 15106497b1a1e1c726c67d95cbcf6d7e97eac418
Author: Marcin Kolny <marcin kolny gmail com>
Date:   Thu Oct 5 23:10:08 2017 +0100

    debugserver: expose max simultaneous connections to configuration

 src/debugserver/gstdebugserver.c    |   48 ++++++++++++++++++----------------
 src/debugserver/gstdebugserver.h    |    1 +
 src/debugserver/gstdebugservertcp.c |   15 ++++++-----
 src/debugserver/gstdebugservertcp.h |    2 +-
 4 files changed, 35 insertions(+), 31 deletions(-)
---
diff --git a/src/debugserver/gstdebugserver.c b/src/debugserver/gstdebugserver.c
index e9179a7..199fd36 100644
--- a/src/debugserver/gstdebugserver.c
+++ b/src/debugserver/gstdebugserver.c
@@ -28,10 +28,6 @@
 
 #define GST_USE_UNSTABLE_API
 
-#ifdef HAVE_CONFIG_H
-#  include "config.h"
-#endif
-
 #include "gstdebugserver.h"
 
 #include "gstdebugservertopology.h"
@@ -53,6 +49,7 @@ G_DEFINE_TYPE_WITH_CODE (GstDebugserverTracer, gst_debugserver_tracer,
     GST_TYPE_TRACER, _do_init)
 
 #define DEFAULT_PORT 8080
+#define DEFAULT_MAX_CONNECTIONS 10
 
 static void gst_debugserver_command_handler (GstDebugger__Command * command,
     gpointer debugtracer, TcpClient * client);
@@ -78,36 +75,40 @@ gst_debugserver_log_handler (GstDebugCategory *category, GstDebugLevel level,
 static void
 set_params (GstDebugserverTracer *self)
 {
-    gchar *params = NULL, *tmp;
-    GstStructure *params_struct;
+  gchar *params = NULL, *tmp;
+  GstStructure *params_struct;
+
+  g_object_get (self, "params", &params, NULL);
 
-    g_object_get (self, "params", &params, NULL);
+  if (params == NULL) {
+    self->port = DEFAULT_PORT;
+    self->max_connections = DEFAULT_MAX_CONNECTIONS;
+  } else {
+    tmp = g_strdup_printf ("debugserver,%s", params);
+    params_struct = gst_structure_from_string (tmp, NULL);
+    g_free (tmp);
 
-    if (params == NULL) {
+    if (params_struct) {
+      if (!gst_structure_get_int (params_struct, "port", &self->port)) {
         self->port = DEFAULT_PORT;
-    } else {
-        tmp = g_strdup_printf ("debugserver,%s", params);
-        params_struct = gst_structure_from_string (tmp, NULL);
-        g_free (tmp);
-
-        if (params_struct) {
-            if (!gst_structure_get_int (params_struct, "port", &self->port)) {
-                self->port = DEFAULT_PORT;
-            }
-            gst_structure_free (params_struct);
-        }
+      }
+      if (!gst_structure_get_int (params_struct, "max_connections", &self->max_connections)) {
+        self->max_connections = DEFAULT_MAX_CONNECTIONS;
+      }
+      gst_structure_free (params_struct);
     }
-    g_free (params);
+  }
+  g_free (params);
 }
 
 static void
 gst_debugserver_tracer_constructed (GObject * object)
 {
-    GstDebugserverTracer *self = GST_DEBUGSERVER_TRACER (object);
+  GstDebugserverTracer *self = GST_DEBUGSERVER_TRACER (object);
 
-    set_params (self);
+  set_params (self);
 
-    gst_debugserver_tcp_start_server (self->tcp_server, self->port);
+  gst_debugserver_tcp_start_server (self->tcp_server, self->port, self->max_connections);
 }
 
 static void
@@ -273,6 +274,7 @@ gst_debugserver_tracer_init (GstDebugserverTracer * self)
   GstTracer *tracer = GST_TRACER (self);
 
   self->port = DEFAULT_PORT;
+  self->max_connections = DEFAULT_MAX_CONNECTIONS;
 
   self->log = gst_debugserver_log_new ();
   gst_debug_add_log_function (gst_debugserver_log_handler, self, NULL);
diff --git a/src/debugserver/gstdebugserver.h b/src/debugserver/gstdebugserver.h
index c8940dd..ff9eb9d 100644
--- a/src/debugserver/gstdebugserver.h
+++ b/src/debugserver/gstdebugserver.h
@@ -62,6 +62,7 @@ struct _GstDebugserverTracer {
   /*< private >*/
   GstPipeline *pipeline;
   gint port;
+  gint max_connections;
   GstDebugserverTcp *tcp_server;
   GstDebugserverLog *log;
   GstDebugserverMessage *message;
diff --git a/src/debugserver/gstdebugservertcp.c b/src/debugserver/gstdebugservertcp.c
index fb5864f..340843a 100644
--- a/src/debugserver/gstdebugservertcp.c
+++ b/src/debugserver/gstdebugservertcp.c
@@ -102,11 +102,11 @@ GstDebugserverTcp * gst_debugserver_tcp_new (void)
 }
 
 gboolean
-gst_debugserver_tcp_start_server (GstDebugserverTcp * tcp, guint port)
+gst_debugserver_tcp_start_server (GstDebugserverTcp * tcp, guint port, gint max_connections)
 {
   GError *error = NULL;
 
-  tcp->service = g_threaded_socket_service_new (10); // TODO expose to config
+  tcp->service = g_threaded_socket_service_new (max_connections);
 
   g_socket_listener_add_inet_port ((GSocketListener *) tcp->service,
       port, NULL, &error);
@@ -157,21 +157,22 @@ gst_debugserver_tcp_run (GThreadedSocketService * service,
     gst_debugger__command__free_unpacked (command, NULL);
   }
 
-  g_mutex_lock (&self->clients_mutex);
-  self->clients = g_slist_remove (self->clients, client);
-  g_mutex_unlock (&self->clients_mutex);
-
   if (self->client_disconnected_handler)
     self->client_disconnected_handler (client, self->owner);
 
+  g_mutex_lock (&self->clients_mutex);
+
   g_mutex_clear (&client->mutex);
   g_object_unref (client->cancel);
   g_free (client);
+  self->clients = g_slist_remove (self->clients, client);
 
-  GST_LOG_OBJECT (self, "Client disconnected");
+  g_mutex_unlock (&self->clients_mutex);
 
   g_cond_signal (&self->client_removed_cond);
 
+  GST_LOG_OBJECT (self, "Client disconnected");
+
   return FALSE;
 }
 
diff --git a/src/debugserver/gstdebugservertcp.h b/src/debugserver/gstdebugservertcp.h
index 96276b6..ebd7e8b 100644
--- a/src/debugserver/gstdebugservertcp.h
+++ b/src/debugserver/gstdebugservertcp.h
@@ -76,7 +76,7 @@ struct _GstDebugserverTcpClass
 
 GstDebugserverTcp * gst_debugserver_tcp_new (void);
 
-gboolean gst_debugserver_tcp_start_server (GstDebugserverTcp * tcp, guint port);
+gboolean gst_debugserver_tcp_start_server (GstDebugserverTcp * tcp, guint port, gint max_connections);
 
 gboolean gst_debugserver_tcp_send_packet (GstDebugserverTcp * tcp, TcpClient * client,
   GstDebugger__GStreamerData * gst_data);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]