static gboolean kixmail_io_stream_close_finish (GIOStream *stream, GAsyncResult *result, GError **error) { return g_io_stream_close_finish (KIXMAIL_IO_STREAM (stream)->priv->base_iostream, result, error); }
static VALUE rg_close_finish(VALUE self, VALUE result) { GError *error = NULL; if (!g_io_stream_close_finish(_SELF(self), RVAL2GASYNCRESULT(result), &error)) rbgio_raise_error(error); return self; }
static void stream_close_ready (GObject *source, GAsyncResult *res, gpointer userdata) { GError *err = NULL; if (!g_io_stream_close_finish (G_IO_STREAM(source), res, &err)) { g_warning ("%s", err->message); g_error_free (err); } g_object_unref (source); }
static void on_io_closed (GObject *stream, GAsyncResult *result, gpointer user_data) { GError *error = NULL; if (!g_io_stream_close_finish (G_IO_STREAM (stream), result, &error)) { if (!should_suppress_output_error (error)) g_message ("http close error: %s", error->message); g_error_free (error); } }
static void stream_tube_connection_closed_cb (GObject *source, GAsyncResult *result, gpointer user_data) { GError *error = NULL; if (!g_io_stream_close_finish (G_IO_STREAM (source), result, &error)) { DEBUG ("Failed to close connection: %s", error->message); g_error_free (error); return; } }
static void on_io_closed (GObject *stream, GAsyncResult *result, gpointer user_data) { GError *error = NULL; if (!g_io_stream_close_finish (G_IO_STREAM (stream), result, &error)) { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_BROKEN_PIPE)) g_debug ("http close error: %s", error->message); else g_message ("http close error: %s", error->message); g_error_free (error); } }
static void _close_ready(GObject *source_object, GAsyncResult *res, gpointer user_data) { GIOStream *io_stream = G_IO_STREAM(source_object); GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT(user_data); IdleServerConnection *conn = IDLE_SERVER_CONNECTION(g_async_result_get_source_object(G_ASYNC_RESULT(result))); IdleServerConnectionPrivate *priv = IDLE_SERVER_CONNECTION_GET_PRIVATE(conn); GError *error = NULL; change_state(conn, SERVER_CONNECTION_STATE_NOT_CONNECTED, priv->reason); g_object_unref(conn); if (!g_io_stream_close_finish(io_stream, res, &error)) { IDLE_DEBUG("g_io_stream_close failed: %s", error->message); g_simple_async_result_set_error(result, TP_ERROR, TP_ERROR_NETWORK_ERROR, "%s", error->message); g_error_free(error); } g_simple_async_result_complete(result); g_object_unref(result); }
int main (int argc, char *argv[]) { GOptionContext *context; GSocketClient *client; GSocketConnection *connection; GSocketAddress *address; GCancellable *cancellable; GOutputStream *out; 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)) { g_printerr ("%s: %s\n", argv[0], error->message); return 1; } if (argc != 2) { g_printerr ("%s: %s\n", argv[0], "Need to specify hostname"); return 1; } if (async) loop = g_main_loop_new (NULL, FALSE); if (cancel_timeout) { GThread *thread; cancellable = g_cancellable_new (); thread = g_thread_new ("cancel", cancel_thread, cancellable); g_thread_unref (thread); } else { cancellable = NULL; } 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) { GAsyncResult *res; g_socket_client_connect_to_host_async (client, argv[1], 7777, cancellable, async_cb, &res); g_main_loop_run (loop); connection = g_socket_client_connect_to_host_finish (client, res, &error); g_object_unref (res); } else { connection = g_socket_client_connect_to_host (client, argv[1], 7777, cancellable, &error); } if (connection == NULL) { g_printerr ("%s can't connect: %s\n", argv[0], error->message); return 1; } g_object_unref (client); address = g_socket_connection_get_remote_address (connection, &error); if (!address) { g_printerr ("Error getting remote address: %s\n", error->message); return 1; } g_print ("Connected to address: %s\n", socket_address_to_string (address)); g_object_unref (address); if (graceful) g_tcp_connection_set_graceful_disconnect (G_TCP_CONNECTION (connection), TRUE); out = g_io_stream_get_output_stream (G_IO_STREAM (connection)); while (fgets(buffer, sizeof (buffer), stdin) != NULL) { /* FIXME if (async) */ if (!g_output_stream_write_all (out, buffer, strlen (buffer), NULL, cancellable, &error)) { g_warning ("send error: %s\n", error->message); g_error_free (error); error = NULL; } } g_print ("closing stream\n"); if (async) { GAsyncResult *res; g_io_stream_close_async (G_IO_STREAM (connection), 0, cancellable, async_cb, &res); g_main_loop_run (loop); if (!g_io_stream_close_finish (G_IO_STREAM (connection), res, &error)) { g_object_unref (res); g_warning ("close error: %s\n", error->message); return 1; } g_object_unref (res); } else { if (!g_io_stream_close (G_IO_STREAM (connection), cancellable, &error)) { g_warning ("close error: %s\n", error->message); return 1; } } g_object_unref (connection); return 0; }