THRIFT-4878 - [c_glib] add unix domain socket support to ThriftSocket (#1807)


diff --git a/test/c_glib/src/test_client.c b/test/c_glib/src/test_client.c
index ef24ab7..7126a86 100644
--- a/test/c_glib/src/test_client.c
+++ b/test/c_glib/src/test_client.c
@@ -113,6 +113,7 @@
 {
   static gchar *  host = NULL;
   static gint     port = 9090;
+  static gchar *  path = NULL;
   static gboolean ssl  = FALSE;
   static gchar *  transport_option = NULL;
   static gchar *  protocol_option = NULL;
@@ -124,6 +125,8 @@
       "Host to connect (=localhost)", NULL },
     { "port",            'p', 0, G_OPTION_ARG_INT,      &port,
       "Port number to connect (=9090)", NULL },
+    { "domain-socket",    0, 0, G_OPTION_ARG_STRING,   &path,
+      "Unix socket domain path to connect", NULL },
     { "ssl",             's', 0, G_OPTION_ARG_NONE,     &ssl,
       "Enable SSL", NULL },
     { "transport",       't', 0, G_OPTION_ARG_STRING,   &transport_option,
@@ -227,12 +230,20 @@
   if (!options_valid)
     return 254;
 
-  printf ("Connecting (%s/%s) to: %s/%s:%d\n",
-          transport_name,
-          protocol_name,
-          socket_name,
-          host,
-          port);
+  if (path) {
+    printf ("Connecting (%s/%s) to: %s/%s\n",
+            transport_name,
+            protocol_name,
+            socket_name,
+            path);
+  } else {
+    printf ("Connecting (%s/%s) to: %s/%s:%d\n",
+            transport_name,
+            protocol_name,
+            socket_name,
+            host,
+            port);
+  }
 
   /* Install our SIGPIPE handler, which outputs an error message to
      standard error before exiting so testers can know what
@@ -247,10 +258,16 @@
   }
 
   /* Establish all our connection objects */
-  socket = g_object_new (socket_type,
-                         "hostname", host,
-                         "port",     port,
-                         NULL);
+  if (path) {
+    socket = g_object_new (socket_type,
+                           "path", path,
+                           NULL);
+  } else {
+    socket = g_object_new (socket_type,
+                           "hostname", host,
+                           "port",     port,
+                           NULL);
+  }
 
   if (ssl && !thrift_ssl_load_cert_from_file(THRIFT_SSL_SOCKET(socket), "../keys/CA.pem")) {
     fprintf(stderr, "Unable to load validation certificate ../keys/CA.pem - did you run in the test/c_glib directory?\n");
@@ -336,7 +353,11 @@
       gboolean first;
       gint32 i, j;
 
-      printf ("Test #%d, connect %s:%d\n", test_num + 1, host, port);
+      if (path) {
+        printf ("Test #%d, connect %s\n", test_num + 1, path);
+      } else {
+        printf ("Test #%d, connect %s:%d\n", test_num + 1, host, port);
+      }
       gettimeofday (&time_start, NULL);
 
       /* These test routines have been ported from the C++ test
diff --git a/test/c_glib/src/test_server.c b/test/c_glib/src/test_server.c
index 2d716ec..0819b8c 100644
--- a/test/c_glib/src/test_server.c
+++ b/test/c_glib/src/test_server.c
@@ -69,6 +69,7 @@
 main (int argc, char **argv)
 {
   static gint   port = 9090;
+  static gchar *path_option = NULL;
   static gchar *server_type_option = NULL;
   static gchar *transport_option = NULL;
   static gchar *protocol_option = NULL;
@@ -79,6 +80,8 @@
     GOptionEntry option_entries[] = {
     { "port",            0, 0, G_OPTION_ARG_INT,      &port,
       "Port number to connect (=9090)", NULL },
+    { "domain-socket",   0, 0, G_OPTION_ARG_STRING,   &path_option,
+      "Unix socket domain path to connect", NULL },
     { "server-type",     0, 0, G_OPTION_ARG_STRING,   &server_type_option,
       "Type of server: simple (=simple)", NULL },
     { "transport",       0, 0, G_OPTION_ARG_STRING,   &transport_option,
@@ -218,9 +221,15 @@
                                         "handler", handler,
                                         NULL);
   }
-  server_transport  = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
-                                    "port", port,
-                                    NULL);
+  if (path_option) {
+    server_transport  = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
+                                      "path", path_option,
+                                      NULL);
+  } else {
+    server_transport  = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
+                                      "port", port,
+                                      NULL);
+  }
   transport_factory = g_object_new (transport_factory_type,
                                     NULL);
 
@@ -250,11 +259,19 @@
   sigint_action.sa_flags = SA_RESETHAND;
   sigaction (SIGINT, &sigint_action, NULL);
 
-  printf ("Starting \"%s\" server (%s/%s) listen on: %d\n",
-          server_name,
-          transport_name,
-          protocol_name,
-          port);
+  if (path_option) {
+    printf ("Starting \"%s\" server (%s/%s) listen on: %s\n",
+            server_name,
+            transport_name,
+            protocol_name,
+            path_option);
+  } else {
+    printf ("Starting \"%s\" server (%s/%s) listen on: %d\n",
+            server_name,
+            transport_name,
+            protocol_name,
+            port);
+  }
   fflush (stdout);
 
   /* Serve clients until SIGINT is received (Ctrl-C is pressed) */