static void start_request_input (CockpitRequest *request) { GPollableInputStream *poll_in; GInputStream *in; /* Both GSocketConnection and GTlsServerConnection are pollable */ in = g_io_stream_get_input_stream (request->io); poll_in = NULL; if (G_IS_POLLABLE_INPUT_STREAM (in)) poll_in = (GPollableInputStream *)in; if (!poll_in || !g_pollable_input_stream_can_poll (poll_in)) { g_critical ("cannot use a non-pollable input stream: %s", G_OBJECT_TYPE_NAME (in)); cockpit_request_finish (request); return; } /* Replace with a new source */ if (request->source) { g_source_destroy (request->source); g_source_unref (request->source); } request->source = g_pollable_input_stream_create_source (poll_in, NULL); g_source_set_callback (request->source, (GSourceFunc)on_request_input, request, NULL); g_source_attach (request->source, request->web_server->main_context); }
static void initialize_io (CockpitStream *self) { GInputStream *is; GOutputStream *os; g_return_if_fail (self->priv->in_source == NULL); is = g_io_stream_get_input_stream (self->priv->io); os = g_io_stream_get_output_stream (self->priv->io); if (!G_IS_POLLABLE_INPUT_STREAM (is) || !g_pollable_input_stream_can_poll (G_POLLABLE_INPUT_STREAM (is)) || !G_IS_POLLABLE_OUTPUT_STREAM (os) || !g_pollable_output_stream_can_poll (G_POLLABLE_OUTPUT_STREAM (os))) { g_warning ("%s: stream is not pollable", self->priv->name); close_immediately (self, "internal-error"); return; } if (self->priv->connecting) { g_object_unref (self->priv->connecting); self->priv->connecting = NULL; } self->priv->in_source = g_pollable_input_stream_create_source (G_POLLABLE_INPUT_STREAM (is), NULL); g_source_set_name (self->priv->in_source, "stream-input"); g_source_set_callback (self->priv->in_source, (GSourceFunc)dispatch_input, self, NULL); g_source_attach (self->priv->in_source, self->priv->context); start_output (self); }
static gboolean soup_content_sniffer_stream_can_poll (GPollableInputStream *pollable) { GInputStream *base_stream = G_FILTER_INPUT_STREAM (pollable)->base_stream; return G_IS_POLLABLE_INPUT_STREAM (base_stream) && g_pollable_input_stream_can_poll (G_POLLABLE_INPUT_STREAM (base_stream)); }
static void initialize_io (CockpitStream *self) { GInputStream *is; GOutputStream *os; g_return_if_fail (self->priv->in_source == NULL); is = g_io_stream_get_input_stream (self->priv->io); os = g_io_stream_get_output_stream (self->priv->io); if (!G_IS_POLLABLE_INPUT_STREAM (is) || !g_pollable_input_stream_can_poll (G_POLLABLE_INPUT_STREAM (is)) || !G_IS_POLLABLE_OUTPUT_STREAM (os) || !g_pollable_output_stream_can_poll (G_POLLABLE_OUTPUT_STREAM (os))) { g_warning ("%s: stream is not pollable", self->priv->name); close_immediately (self, "internal-error"); return; } if (self->priv->connecting) { cockpit_connectable_unref (self->priv->connecting); self->priv->connecting = NULL; } self->priv->in_source = g_pollable_input_stream_create_source (G_POLLABLE_INPUT_STREAM (is), NULL); g_source_set_name (self->priv->in_source, "stream-input"); g_source_set_callback (self->priv->in_source, (GSourceFunc)dispatch_input, self, NULL); g_source_attach (self->priv->in_source, self->priv->context); if (G_IS_TLS_CONNECTION (self->priv->io)) { self->priv->sig_accept_cert = g_signal_connect (G_TLS_CONNECTION (self->priv->io), "accept-certificate", G_CALLBACK (on_rejected_certificate), self); } else { self->priv->sig_accept_cert = 0; } start_output (self); g_signal_emit (self, cockpit_stream_sig_open, 0); }
static void test_pollable_properties (NiceAddress *addr) { NiceAgent *agent; guint stream_id; GIOStream *io_stream; GInputStream *input_stream; GOutputStream *output_stream; GPollableInputStream *pollable_input_stream; GPollableOutputStream *pollable_output_stream; guint8 buf[65536]; GError *error = NULL; GSource *stream_source; agent = nice_agent_new_reliable (NULL, NICE_COMPATIBILITY_RFC5245); nice_agent_add_local_address (agent, addr); /* Add a stream. */ stream_id = nice_agent_add_stream (agent, 1); /* Try building an I/O stream around it. */ io_stream = nice_agent_get_io_stream (agent, stream_id, 1); g_assert (G_IS_IO_STREAM (io_stream)); g_assert (NICE_IS_IO_STREAM (io_stream)); /* Check the input stream’s properties. */ input_stream = g_io_stream_get_input_stream (G_IO_STREAM (io_stream)); g_assert (G_IS_POLLABLE_INPUT_STREAM (input_stream)); pollable_input_stream = G_POLLABLE_INPUT_STREAM (input_stream); g_assert (g_pollable_input_stream_can_poll (pollable_input_stream)); g_assert (!g_pollable_input_stream_is_readable (pollable_input_stream)); g_assert ( g_pollable_input_stream_read_nonblocking (pollable_input_stream, buf, sizeof (buf), NULL, &error) == -1); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK); g_clear_error (&error); stream_source = g_pollable_input_stream_create_source (pollable_input_stream, NULL); g_assert (stream_source != NULL); g_source_unref (stream_source); /* Check the output stream’s properties. */ output_stream = g_io_stream_get_output_stream (G_IO_STREAM (io_stream)); g_assert (G_IS_POLLABLE_OUTPUT_STREAM (output_stream)); pollable_output_stream = G_POLLABLE_OUTPUT_STREAM (output_stream); g_assert (g_pollable_output_stream_can_poll (pollable_output_stream)); g_assert (!g_pollable_output_stream_is_writable (pollable_output_stream)); g_assert ( g_pollable_output_stream_write_nonblocking (pollable_output_stream, buf, sizeof (buf), NULL, &error) == -1); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK); g_clear_error (&error); stream_source = g_pollable_output_stream_create_source (pollable_output_stream, NULL); g_assert (stream_source != NULL); g_source_unref (stream_source); /* Remove the component and check that the I/O streams close. */ nice_agent_remove_stream (agent, stream_id); g_assert (!g_pollable_input_stream_is_readable (pollable_input_stream)); g_assert (!g_pollable_output_stream_is_writable (pollable_output_stream)); g_assert ( g_pollable_input_stream_read_nonblocking (pollable_input_stream, buf, sizeof (buf), NULL, &error) == 0); g_assert_no_error (error); g_assert ( g_pollable_output_stream_write_nonblocking (pollable_output_stream, buf, sizeof (buf), NULL, &error) == -1); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CLOSED); g_clear_error (&error); g_object_unref (io_stream); g_object_unref (agent); }
static void g_tls_connection_base_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GTlsConnectionBase *tls = G_TLS_CONNECTION_BASE (object); GInputStream *istream; GOutputStream *ostream; gboolean system_certdb; GTlsBackend *backend; switch (prop_id) { case PROP_BASE_IO_STREAM: if (tls->base_io_stream) { g_object_unref (tls->base_io_stream); tls->base_istream = NULL; tls->base_ostream = NULL; } tls->base_io_stream = g_value_dup_object (value); if (!tls->base_io_stream) return; istream = g_io_stream_get_input_stream (tls->base_io_stream); ostream = g_io_stream_get_output_stream (tls->base_io_stream); if (G_IS_POLLABLE_INPUT_STREAM (istream) && g_pollable_input_stream_can_poll (G_POLLABLE_INPUT_STREAM (istream))) { tls->base_istream = G_POLLABLE_INPUT_STREAM (istream); tls->tls_istream = g_tls_input_stream_base_new (tls); } if (G_IS_POLLABLE_OUTPUT_STREAM (ostream) && g_pollable_output_stream_can_poll (G_POLLABLE_OUTPUT_STREAM (ostream))) { tls->base_ostream = G_POLLABLE_OUTPUT_STREAM (ostream); tls->tls_ostream = g_tls_output_stream_base_new (tls); } break; case PROP_REQUIRE_CLOSE_NOTIFY: tls->require_close_notify = g_value_get_boolean (value); break; case PROP_REHANDSHAKE_MODE: tls->rehandshake_mode = g_value_get_enum (value); break; case PROP_USE_SYSTEM_CERTDB: system_certdb = g_value_get_boolean (value); if (system_certdb != tls->is_system_certdb) { g_clear_object (&tls->database); if (system_certdb) { backend = g_tls_backend_get_default (); tls->database = g_tls_backend_get_default_database (backend); } tls->is_system_certdb = system_certdb; tls->database_is_unset = FALSE; } break; case PROP_DATABASE: g_clear_object (&tls->database); tls->database = g_value_dup_object (value); tls->is_system_certdb = FALSE; tls->database_is_unset = FALSE; break; case PROP_CERTIFICATE: if (tls->certificate) g_object_unref (tls->certificate); tls->certificate = g_value_dup_object (value); break; case PROP_INTERACTION: g_clear_object (&tls->interaction); tls->interaction = g_value_dup_object (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } }