[kdbus] KDBUS_ITEM_PAYLOAD_OFF items are (once again) relative to msg header
[platform/upstream/glib.git] / gio / tests / send-data.c
index 6ef9382..a30bdca 100644 (file)
@@ -8,6 +8,7 @@ int cancel_timeout = 0;
 int io_timeout = 0;
 gboolean async = FALSE;
 gboolean graceful = FALSE;
+gboolean verbose = FALSE;
 static GOptionEntry cmd_entries[] = {
   {"cancel", 'c', 0, G_OPTION_ARG_INT, &cancel_timeout,
    "Cancel any op after the specified amount of seconds", NULL},
@@ -17,6 +18,8 @@ static GOptionEntry cmd_entries[] = {
    "Use graceful disconnect", NULL},
   {"timeout", 't', 0, G_OPTION_ARG_INT, &io_timeout,
    "Time out socket I/O after the specified number of seconds", NULL},
+  {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
+   "Verbose debugging output", NULL},
   {NULL}
 };
 
@@ -56,6 +59,24 @@ async_cb (GObject *source_object,
   g_main_loop_quit (loop);
 }
 
+static void
+socket_client_event (GSocketClient *client,
+                    GSocketClientEvent event,
+                    GSocketConnectable *connectable,
+                    GSocketConnection *connection)
+{
+  static GEnumClass *event_class;
+  GTimeVal tv;
+
+  if (!event_class)
+    event_class = g_type_class_ref (G_TYPE_SOCKET_CLIENT_EVENT);
+
+  g_get_current_time (&tv);
+  printf ("% 12ld.%06ld GSocketClient => %s [%s]\n",
+         tv.tv_sec, tv.tv_usec,
+         g_enum_get_value (event_class, event)->value_nick,
+         connection ? G_OBJECT_TYPE_NAME (connection) : "");
+}
 
 int
 main (int argc, char *argv[])
@@ -69,8 +90,6 @@ main (int argc, char *argv[])
   GError *error = NULL;
   char buffer[1000];
 
-  g_type_init ();
-
   context = g_option_context_new (" <hostname>[:port] - send data to tcp host");
   g_option_context_add_main_entries (context, cmd_entries, NULL);
   if (!g_option_context_parse (context, &argc, &argv, &error))
@@ -90,8 +109,10 @@ main (int argc, char *argv[])
 
   if (cancel_timeout)
     {
+      GThread *thread;
       cancellable = g_cancellable_new ();
-      g_thread_new ("cancel", cancel_thread, cancellable, FALSE, NULL);
+      thread = g_thread_new ("cancel", cancel_thread, cancellable);
+      g_thread_unref (thread);
     }
   else
     {
@@ -101,6 +122,8 @@ main (int argc, char *argv[])
   client = g_socket_client_new ();
   if (io_timeout)
     g_socket_client_set_timeout (client, io_timeout);
+  if (verbose)
+    g_signal_connect (client, "event", G_CALLBACK (socket_client_event), NULL);
 
   if (async)
     {