static gboolean soup_cache_input_stream_close_fn (GInputStream *stream, GCancellable *cancellable, GError **error) { SoupCacheInputStream *istream = SOUP_CACHE_INPUT_STREAM (stream); SoupCacheInputStreamPrivate *priv = istream->priv; if (!priv->read_finished) { if (priv->output_stream) { /* Cancel any pending write operation or return an error if none. */ if (g_output_stream_has_pending (priv->output_stream)) g_cancellable_cancel (priv->cancellable); else { GError *notify_error = NULL; g_set_error_literal (¬ify_error, G_IO_ERROR, G_IO_ERROR_PARTIAL_INPUT, _("Failed to completely cache the resource")); notify_and_clear (istream, notify_error); } } else if (priv->cancellable) /* The file_replace_async() hasn't finished yet */ g_cancellable_cancel (priv->cancellable); } return G_INPUT_STREAM_CLASS (soup_cache_input_stream_parent_class)->close_fn (stream, cancellable, error); }
void ekg_connection_write_buf(GDataOutputStream *f, gconstpointer buf, gsize len) { struct ekg_connection *c = get_connection_by_outstream(f); GError *err = NULL; gssize out; GOutputStream *of = G_OUTPUT_STREAM(f); /* we can't write to buffer if it has pending ops; * yes, it is stupid. */ if (g_output_stream_has_pending(of)) { c->wr_buffer = g_string_append_len(c->wr_buffer, buf, len); return; } out = g_output_stream_write(of, buf, len, NULL, &err); if (out != len) { debug_error("ekg_connection_write_string() failed (wrote %d out of %d): %s\n", out, len, err ? err->message : "(no error?!)"); failed_write(c); g_error_free(err); return; } debug_function("ekg_connection_write_buf(), wrote %d bytes\n", out); c->flush_handler(c); }
static void done_async_write(GObject *obj, GAsyncResult *res, gpointer user_data) { struct ekg_connection *c = user_data; GError *err = NULL; gboolean ret; GOutputStream *of = G_OUTPUT_STREAM(obj); ret = g_output_stream_flush_finish(of, res, &err); if (!ret) { debug_error("done_async_write(), write failed: %s\n", err ? err->message : NULL); /* XXX */ failed_write(c); g_error_free(err); return; } if (c->wr_buffer->len > 0) { /* the stream should not have any pending writes ATM * we need to ensure that to have the data written to stream * rather than re-appended to the buffer*/ g_assert(!g_output_stream_has_pending(of)); ekg_connection_write_buf(G_DATA_OUTPUT_STREAM(of), c->wr_buffer->str, c->wr_buffer->len); g_string_truncate(c->wr_buffer, 0); } /* XXX: anything to do? */ }
static void test_io_stream_properties (NiceAddress *addr) { NiceAgent *agent; guint stream_id; GIOStream *io_stream; GInputStream *input_stream; GOutputStream *output_stream; agent = nice_agent_new_reliable (NULL, NICE_COMPATIBILITY_RFC5245); nice_agent_add_local_address (agent, addr); 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 various initial properties. */ g_assert (!g_io_stream_is_closed (G_IO_STREAM (io_stream))); g_assert (!g_io_stream_has_pending (G_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_INPUT_STREAM (input_stream)); g_assert (NICE_IS_INPUT_STREAM (input_stream)); g_assert (!g_input_stream_is_closed (input_stream)); g_assert (!g_input_stream_has_pending (input_stream)); /* Check the output stream’s properties. */ output_stream = g_io_stream_get_output_stream (G_IO_STREAM (io_stream)); g_assert (G_IS_OUTPUT_STREAM (output_stream)); g_assert (NICE_IS_OUTPUT_STREAM (output_stream)); g_assert (!g_output_stream_is_closing (output_stream)); g_assert (!g_output_stream_is_closed (output_stream)); g_assert (!g_output_stream_has_pending (output_stream)); /* Remove the component and check that the I/O streams close. */ nice_agent_remove_stream (agent, stream_id); g_assert (g_io_stream_is_closed (G_IO_STREAM (io_stream))); g_assert (g_input_stream_is_closed (input_stream)); g_assert (g_output_stream_is_closed (output_stream)); g_object_unref (io_stream); g_object_unref (agent); }
static void ekg_connection_remove(struct ekg_connection *c) { if (g_input_stream_has_pending(G_INPUT_STREAM(c->instream))) { debug_warn("ekg_connection_remove(%x) input stream has pending!\n", c); g_input_stream_clear_pending(G_INPUT_STREAM(c->instream)); } #if 0 /* XXX */ g_assert(!g_output_stream_has_pending( G_OUTPUT_STREAM(c->outstream))); #endif connections = g_slist_remove(connections, c); g_string_free(c->wr_buffer, TRUE); g_object_unref(c->cancellable); g_object_unref(c->instream); g_object_unref(c->outstream); g_slice_free(struct ekg_connection, c); }
static VALUE rg_has_pending_p(VALUE self) { return CBOOL2RVAL(g_output_stream_has_pending(_SELF(self))); }