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},
"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}
};
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[])
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))
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
{
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)
{