void idle_server_connection_disconnect_full_async(IdleServerConnection *conn, guint reason, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { IdleServerConnectionPrivate *priv = IDLE_SERVER_CONNECTION_GET_PRIVATE(conn); GSimpleAsyncResult *result; g_assert(priv != NULL); if (priv->state != SERVER_CONNECTION_STATE_CONNECTED) { IDLE_DEBUG("the connection was not open"); g_simple_async_report_error_in_idle(G_OBJECT(conn), callback, user_data, TP_ERROR, TP_ERROR_NOT_AVAILABLE, "the connection was not open"); return; } if (priv->io_stream == NULL) { IDLE_DEBUG("We were exploding anyway"); g_simple_async_report_error_in_idle(G_OBJECT(conn), callback, user_data, TP_ERROR, TP_ERROR_NOT_AVAILABLE, "We were exploding anyway"); return; } priv->reason = reason; result = g_simple_async_result_new(G_OBJECT(conn), callback, user_data, idle_server_connection_disconnect_full_async); g_io_stream_close_async(priv->io_stream, G_PRIORITY_DEFAULT, cancellable, _close_ready, result); g_object_unref(priv->io_stream); priv->io_stream = NULL; }
static void kixmail_io_stream_close_async (GIOStream *stream, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { g_io_stream_close_async (KIXMAIL_IO_STREAM (stream)->priv->base_iostream, io_priority, cancellable, callback, user_data); }
static void connection_rejected (TpStreamTubeChannel *self, GSocketConnection *conn, TpHandle handle, guint connection_id) { DEBUG ("Reject connection %u with contact %u", connection_id, handle); g_io_stream_close_async (G_IO_STREAM (conn), G_PRIORITY_DEFAULT, NULL, stream_tube_connection_closed_cb, self); }
static void ident_info_free (ident_info *info) { if (G_LIKELY(info)) { g_io_stream_close_async (G_IO_STREAM(info->conn), G_PRIORITY_DEFAULT, NULL, stream_close_ready, NULL); g_free (info->username); g_free (info); } }
static void gum_duk_debug_session_weak_notify (GumDukDebugSession * self, GObject * where_the_object_was) { g_object_unref (self->channel); g_queue_free_full (self->outgoing, (GDestroyNotify) g_bytes_unref); g_io_stream_close_async (self->stream, G_PRIORITY_LOW, NULL, NULL, NULL); g_object_unref (self->stream); g_slice_free (GumDukDebugSession, self); }
static VALUE rg_close_async(int argc, VALUE *argv, VALUE self) { VALUE rbio_priority, rbcancellable, block; int io_priority; GCancellable *cancellable; rb_scan_args(argc, argv, "01&", &rbio_priority, &rbcancellable, &block); io_priority = RVAL2IOPRIORITYDEFAULT(rbio_priority); cancellable = RVAL2GCANCELLABLE(rbcancellable); SAVE_BLOCK(block); g_io_stream_close_async(_SELF(self), io_priority, cancellable, rbgio_async_ready_callback, (gpointer)block); return self; }
static void close_io_stream (GIOStream *io) { g_io_stream_close_async (io, G_PRIORITY_DEFAULT, NULL, on_io_closed, NULL); }
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; }