[gtk+] BroadwayServer support for unix socket listening



commit 43bddd205bf82915d6fa5f6166a4e58023778354
Author: Domenico Tortorella <dom tortorella gmail com>
Date:   Thu Aug 14 13:30:00 2014 +0200

    BroadwayServer support for unix socket listening
    
    At the present time broadway listens only for TCP/IP incoming
    display connections. This patch implements the support for listening
    on unix domain sockets too, adding the broadway_server_on_unix_socket_new()
    constructor and the commandline option --unixsocket [path] to broadwayd.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=734420

 docs/reference/gtk/broadwayd.xml |    8 ++++++
 gdk/broadway/broadway-server.c   |   46 ++++++++++++++++++++++++++++++++++++++
 gdk/broadway/broadway-server.h   |    2 +
 gdk/broadway/broadwayd.c         |   10 +++++++-
 4 files changed, 65 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/gtk/broadwayd.xml b/docs/reference/gtk/broadwayd.xml
index 14f7064..207b6c9 100644
--- a/docs/reference/gtk/broadwayd.xml
+++ b/docs/reference/gtk/broadwayd.xml
@@ -32,6 +32,7 @@
 <command>broadwayd</command>
 <arg choice="opt">--port <replaceable>PORT</replaceable></arg>
 <arg choice="opt">--address <replaceable>ADDRESS</replaceable></arg>
+<arg choice="opt">--unixsocket <replaceable>ADDRESS</replaceable></arg>
 <arg choice="opt"><replaceable>:DISPLAY</replaceable></arg>
 </cmdsynopsis>
 </refsynopsisdiv>
@@ -80,6 +81,13 @@ openssl passwd -1  > ~/.config/broadway.passwd
       address, instead of the default <literal>http://127.0.0.1:<replaceable>PORT</replaceable></literal>.
       </para></listitem>
   </varlistentry>
+  <varlistentry>
+    <term>--unixsocket</term>
+    <listitem><para>Use <replaceable>ADDRESS</replaceable> as the unix domain socket
+      address. This option overrides <literal>--address</literal> and <literal>--port</literal>.
+      It is available only on Unix-like systems.
+      </para></listitem>
+  </varlistentry>
 </variablelist>
 </refsect1>
 
diff --git a/gdk/broadway/broadway-server.c b/gdk/broadway/broadway-server.c
index fc97bf4..86c6920 100644
--- a/gdk/broadway/broadway-server.c
+++ b/gdk/broadway/broadway-server.c
@@ -1270,6 +1270,52 @@ broadway_server_new (char *address, int port, GError **error)
   return server;
 }
 
+BroadwayServer *
+broadway_server_on_unix_socket_new (char *address, GError **error)
+{
+  BroadwayServer *server;
+  GSocketAddress *socket_address;
+
+  server = g_object_new (BROADWAY_TYPE_SERVER, NULL);
+  server->port = -1;
+  server->address = g_strdup (address);
+
+  if (address == NULL)
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "Unspecified unix domain socket address");
+      g_object_unref (server);
+      return NULL;
+    }
+  else
+    {
+      socket_address = g_unix_socket_address_new (address);
+      if (socket_address == NULL)
+       {
+         g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "Invalid unix domain socket address %s: ", 
address);
+         g_object_unref (server);
+         return NULL;
+       }
+      if (!g_socket_listener_add_address (G_SOCKET_LISTENER (server->service),
+                                         socket_address,
+                                         G_SOCKET_TYPE_STREAM,
+                                         G_SOCKET_PROTOCOL_DEFAULT,
+                                         G_OBJECT (server),
+                                         NULL,
+                                         error))
+       {
+         g_prefix_error (error, "Unable to listen to %s: ", server->address);
+         g_object_unref (socket_address);
+         g_object_unref (server);
+         return NULL;
+       }
+      g_object_unref (socket_address);
+    }
+
+  g_signal_connect (server->service, "incoming",
+                   G_CALLBACK (handle_incoming_connection), NULL);
+  return server;
+}
+
 guint32
 broadway_server_get_last_seen_time (BroadwayServer *server)
 {
diff --git a/gdk/broadway/broadway-server.h b/gdk/broadway/broadway-server.h
index 1021e44..cbe656e 100644
--- a/gdk/broadway/broadway-server.h
+++ b/gdk/broadway/broadway-server.h
@@ -22,6 +22,8 @@ typedef struct _BroadwayServerClass BroadwayServerClass;
 BroadwayServer     *broadway_server_new                      (char             *address,
                                                              int               port,
                                                              GError          **error);
+BroadwayServer     *broadway_server_on_unix_socket_new       (char             *address,
+                                                             GError          **error);
 gboolean            broadway_server_has_client               (BroadwayServer   *server);
 void                broadway_server_flush                    (BroadwayServer   *server);
 void                broadway_server_sync                     (BroadwayServer   *server);
diff --git a/gdk/broadway/broadwayd.c b/gdk/broadway/broadwayd.c
index 84f95ee..30448ac 100644
--- a/gdk/broadway/broadwayd.c
+++ b/gdk/broadway/broadwayd.c
@@ -417,12 +417,16 @@ main (int argc, char *argv[])
   GSocketService *listener;
   char *path, *basename;
   char *http_address = NULL;
+  char *unixsocket_address = NULL;
   int http_port = 0;
   char *display;
   int port = 0;
   const GOptionEntry entries[] = {
     { "port", 'p', 0, G_OPTION_ARG_INT, &http_port, "Httpd port", "PORT" },
     { "address", 'a', 0, G_OPTION_ARG_STRING, &http_address, "Ip address to bind to ", "ADDRESS" },
+#ifdef G_OS_UNIX
+    { "unixsocket", 'u', 0, G_OPTION_ARG_STRING, &unixsocket_address, "Unix domain socket address", 
"ADDRESS" },
+#endif
     { NULL }
   };
 
@@ -486,7 +490,11 @@ main (int argc, char *argv[])
   if (http_port == 0)
     http_port = 8080 + port;
 
-  server = broadway_server_new (http_address, http_port, &error);
+  if (unixsocket_address != NULL)
+    server = broadway_server_on_unix_socket_new (unixsocket_address, &error);
+  else
+    server = broadway_server_new (http_address, http_port, &error);
+
   if (server == NULL)
     {
       g_printerr ("%s\n", error->message);


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