/* * * Read from g_input_stream until we get 0 bytes read. Then process * * using the value of stream_type. Finally try and read another multipart. * */ static void read_cb (GObject *source, GAsyncResult *async_result, gpointer user_data) { //g_print ("read_cb: Enter\n"); GInputStream *in = G_INPUT_STREAM (source); MultiPartData *multipart_data = (MultiPartData *) user_data; SoupMultipartInputStream *multipart = SOUP_MULTIPART_INPUT_STREAM (multipart_data->multipart); gssize bytes_read; bytes_read = g_input_stream_read_finish (in, async_result, &multipart_data->error); /* Read 0 bytes - try to start reading another part. */ if (bytes_read <= 0) { g_input_stream_close_async (in, G_PRIORITY_DEFAULT, multipart_data->cancellable, close_cb, user_data); if (multipart_data->callback) { SoupBuffer *soup_buffer; //g_print ("callback\n"); soup_buffer = soup_buffer_new(SOUP_MEMORY_TEMPORARY, (guchar *) multipart_data->buffer->str, multipart_data->buffer->len); multipart_data->callback (multipart_data->method, multipart_data->path, multipart_data->cancellable, multipart_data->error, multipart_data->headers, soup_buffer, multipart_data->user_data); soup_buffer_free(soup_buffer); } g_string_free (multipart_data->buffer, TRUE); if (multipart_data->error) { g_input_stream_close_async (G_INPUT_STREAM (multipart), G_PRIORITY_DEFAULT, multipart_data->cancellable, close_base_cb, user_data); return; } soup_multipart_input_stream_next_part_async (multipart_data->multipart, G_PRIORITY_DEFAULT, multipart_data->cancellable, next_part_cb, user_data); return; } multipart_data->buffer = g_string_append_len (multipart_data->buffer, buffer, bytes_read); g_input_stream_read_async (in, buffer, READ_BUFFER_SIZE, G_PRIORITY_DEFAULT, multipart_data->cancellable, read_cb, user_data); //g_print ("read_cb: Exit\n"); }
static void gtkhash_hash_file_close(struct hash_file_s *data) { gtkhash_hash_file_remove_source(data); g_input_stream_close_async(G_INPUT_STREAM(data->stream), G_PRIORITY_DEFAULT, data->cancellable, (GAsyncReadyCallback)gtkhash_hash_file_close_finish, data); }
gboolean soup_test_request_close_stream (SoupRequest *req, GInputStream *stream, GCancellable *cancellable, GError **error) { AsyncAsSyncData data; gboolean ok; if (SOUP_IS_SESSION_SYNC (soup_request_get_session (req))) return g_input_stream_close (stream, cancellable, error); data.loop = g_main_loop_new (g_main_context_get_thread_default (), FALSE); g_input_stream_close_async (stream, G_PRIORITY_DEFAULT, cancellable, async_as_sync_callback, &data); g_main_loop_run (data.loop); ok = g_input_stream_close_finish (stream, data.result, error); g_main_loop_unref (data.loop); g_object_unref (data.result); return ok; }
static void readCallback(GObject* source, GAsyncResult* res, gpointer data) { ResourceHandle* handle = static_cast<ResourceHandle*>(data); ResourceHandleInternal* d = handle->getInternal(); ResourceHandleClient* client = handle->client(); if (d->m_cancelled || !client) { cleanupGioOperation(handle); return; } gssize nread; GError *error = 0; nread = g_input_stream_read_finish(d->m_input_stream, res, &error); if (error) { cleanupGioOperation(handle); // FIXME: error client->didFinishLoading(handle); return; } else if (!nread) { client->didFinishLoading(handle); g_input_stream_close_async(d->m_input_stream, G_PRIORITY_DEFAULT, NULL, closeCallback, handle); return; } d->m_total += nread; client->didReceiveData(handle, d->m_buffer, nread, d->m_total); g_input_stream_read_async(d->m_input_stream, d->m_buffer, d->m_bufsize, G_PRIORITY_DEFAULT, d->m_cancellable, readCallback, handle); }
/* Called to cancel the current operation. * Puts the async handle into a cancelled state. */ static void vfs_data_cancel (VfsAsyncHandle *ah) { switch (ah->state) { case VFS_ASYNC_CANCELLED: break; case VFS_ASYNC_PROCESSING: g_cancellable_cancel (ah->cancellable); break; case VFS_ASYNC_READY: break; } if (ah->ostream) g_output_stream_close_async (ah->ostream, G_PRIORITY_DEFAULT, NULL, vfs_data_close_done, ah); else if (ah->istream) g_input_stream_close_async (ah->istream, G_PRIORITY_DEFAULT, NULL, vfs_data_close_done, ah); else return; vfs_data_wait_results (ah, FALSE); ah->state = VFS_ASYNC_CANCELLED; }
static void cleanup (RBChunkLoader *loader) { g_input_stream_close_async (G_INPUT_STREAM (loader->priv->stream), G_PRIORITY_DEFAULT, loader->priv->cancel, stream_close_cb, loader); }
static void multipart_read_cb (GObject *source, GAsyncResult *asyncResult, gpointer data) { GMainLoop *loop = (GMainLoop*)data; GInputStream *in = G_INPUT_STREAM (source); GError *error = NULL; static gssize bytes_read_for_part = 0; gssize bytes_read; bytes_read = g_input_stream_read_finish (in, asyncResult, &error); if (error) { debug_printf (1, " failed read: %s\n", error->message); errors++; g_input_stream_close_async (in, G_PRIORITY_DEFAULT, NULL, multipart_close_part_cb, NULL); g_object_unref (in); g_main_loop_quit (loop); return; } /* Read 0 bytes - try to start reading another part. */ if (!bytes_read) { check_read (bytes_read_for_part, passes); bytes_read_for_part = 0; passes++; g_input_stream_close_async (in, G_PRIORITY_DEFAULT, NULL, multipart_close_part_cb, NULL); g_object_unref (in); soup_multipart_input_stream_next_part_async (multipart, G_PRIORITY_DEFAULT, NULL, multipart_next_part_cb, data); return; } bytes_read_for_part += bytes_read; g_input_stream_read_async (in, buffer, READ_BUFFER_SIZE, G_PRIORITY_DEFAULT, NULL, multipart_read_cb, data); }
static void rygel_seekable_response_on_contents_read (RygelSeekableResponse* self, GObject* source_object, GAsyncResult* _result_) { GError * _inner_error_; GFileInputStream* _tmp0_; GFileInputStream* input_stream; gssize bytes_read; g_return_if_fail (self != NULL); g_return_if_fail (source_object != NULL); g_return_if_fail (_result_ != NULL); _inner_error_ = NULL; _tmp0_ = NULL; input_stream = (_tmp0_ = G_FILE_INPUT_STREAM (source_object), (_tmp0_ == NULL) ? NULL : g_object_ref (_tmp0_)); bytes_read = 0L; { gssize _tmp1_; _tmp1_ = g_input_stream_read_finish ((GInputStream*) input_stream, _result_, &_inner_error_); if (_inner_error_ != NULL) { goto __catch14_g_error; goto __finally14; } bytes_read = _tmp1_; } goto __finally14; __catch14_g_error: { GError * err; err = _inner_error_; _inner_error_ = NULL; { char* _tmp2_; _tmp2_ = NULL; g_warning ("rygel-seekable-response.vala:113: Failed to read contents from URI: %s: %s\n", _tmp2_ = g_file_get_uri (self->priv->file), err->message); _tmp2_ = (g_free (_tmp2_), NULL); rygel_http_response_end ((RygelHTTPResponse*) self, FALSE, (guint) SOUP_STATUS_NOT_FOUND); (err == NULL) ? NULL : (err = (g_error_free (err), NULL)); (input_stream == NULL) ? NULL : (input_stream = (g_object_unref (input_stream), NULL)); return; } } __finally14: if (_inner_error_ != NULL) { (input_stream == NULL) ? NULL : (input_stream = (g_object_unref (input_stream), NULL)); g_critical ("file %s: line %d: uncaught error: %s", __FILE__, __LINE__, _inner_error_->message); g_clear_error (&_inner_error_); return; } if (bytes_read > 0) { rygel_http_response_push_data ((RygelHTTPResponse*) self, self->priv->buffer, (gsize) bytes_read); } else { g_input_stream_close_async ((GInputStream*) input_stream, self->priv->priority, ((RygelHTTPResponse*) self)->cancellable, _rygel_seekable_response_on_input_stream_closed_gasync_ready_callback, self); } (input_stream == NULL) ? NULL : (input_stream = (g_object_unref (input_stream), NULL)); }
static void free_pixbuf_load_handle (EelPixbufLoadHandle *handle) { g_object_unref (handle->cancellable); if (handle->loader != NULL) { g_object_unref (handle->loader); } if (handle->stream) { g_input_stream_close_async (handle->stream, 0, NULL, NULL, NULL); g_object_unref (handle->stream); } g_free (handle); }
static gboolean try_close_read (GVfsBackend *backend, GVfsJobCloseRead *job, GVfsBackendHandle handle) { GInputStream *stream; stream = G_INPUT_STREAM (handle); g_input_stream_close_async (stream, G_PRIORITY_DEFAULT, G_VFS_JOB (job)->cancellable, close_read_ready, job); return TRUE; }
static void g_filter_input_stream_close_async (GInputStream *stream, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GFilterInputStream *filter_stream; GInputStream *base_stream; filter_stream = G_FILTER_INPUT_STREAM (stream); base_stream = filter_stream->base_stream; g_input_stream_close_async (base_stream, io_priority, cancellable, callback, user_data); }
static void photos_base_item_refresh_thumb_path_pixbuf (GObject *source_object, GAsyncResult *res, gpointer user_data) { PhotosBaseItem *self = PHOTOS_BASE_ITEM (user_data); PhotosBaseItemPrivate *priv = self->priv; GApplication *app; GdkPixbuf *pixbuf = NULL; GdkPixbuf *scaled_pixbuf = NULL; GError *error = NULL; GInputStream *stream = G_INPUT_STREAM (source_object); gint icon_size; gint scale; pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error); if (error != NULL) { GFile *file; gchar *uri; file = G_FILE (g_object_get_data (G_OBJECT (stream), "file")); uri = g_file_get_uri (file); g_warning ("Unable to create pixbuf from %s: %s", uri, error->message); priv->failed_thumbnailing = TRUE; priv->thumb_path = NULL; g_file_delete_async (file, G_PRIORITY_DEFAULT, NULL, NULL, NULL); photos_base_item_set_failed_icon (self); g_free (uri); g_error_free (error); goto out; } app = g_application_get_default (); scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app)); icon_size = photos_utils_get_icon_size_unscaled (); scaled_pixbuf = photos_utils_downscale_pixbuf_for_scale (pixbuf, icon_size, scale); photos_base_item_set_original_icon (self, scaled_pixbuf); out: g_input_stream_close_async (stream, G_PRIORITY_DEFAULT, NULL, NULL, NULL); g_clear_object (&scaled_pixbuf); g_clear_object (&pixbuf); g_object_unref (self); }
static void on_input_stream_read_ready (GObject * object, GAsyncResult * res, gpointer data) { GError * error = NULL; GDownloadable *download = G_DOWNLOADABLE (data); GioDownload *gio_download = GIO_DOWNLOAD (data); g_assert (download != NULL); gssize size = g_input_stream_read_finish (G_INPUT_STREAM(object), res, &error); handle_critical_error (error); if (size < 0) { g_downloadable_set_status (download, G_DOWNLOADABLE_NETWORK_ERROR); return; } if (size == 0 && download->priv->size == download->priv->downloaded_size) { /* Download Completed */ write_chunks_to_output_stream (gio_download); g_input_stream_close_async (G_INPUT_STREAM(gio_download->priv->input), G_PRIORITY_DEFAULT, NULL, on_input_stream_close_ready, NULL); g_output_stream_close_async (G_OUTPUT_STREAM(gio_download->priv->output), G_PRIORITY_DEFAULT, NULL, on_output_stream_close_ready, NULL); g_downloadable_set_status (download, G_DOWNLOADABLE_COMPLETED); g_signal_emit_by_name (download, "download-completed"); return; } if (gio_download->priv->num_chunks == NUM_OF_CHUNKS) { write_chunks_to_output_stream (gio_download); gio_download->priv->num_chunks = 0; } MemChunk *chunk = mem_chunk_new_from_buffer (size, gio_download->priv->chunk_buff); gio_download->priv->chunks = g_slist_prepend (gio_download->priv->chunks, chunk); gio_download->priv->num_chunks++; g_signal_emit_by_name (data, "download-progressed", size); read_input_stream (download); }
static void avatar_cache_read_cb (GObject *object, GAsyncResult *result, gpointer user_data) { GiggleAvatarCacheLoader *loader = user_data; GInputStream *stream = G_INPUT_STREAM (object); GError *error = NULL; gssize len; len = g_input_stream_read_finish (stream, result, &error); if (len > 0) { if (gdk_pixbuf_loader_write (loader->pixbuf_loader, (gpointer) loader->buffer, len, &error)) { g_input_stream_read_async (stream, loader->buffer, sizeof loader->buffer, G_PRIORITY_DEFAULT, loader->cancellable, avatar_cache_read_cb, loader); } else { len = -2; } } if (0 >= len) { g_input_stream_close_async (stream, G_PRIORITY_DEFAULT, loader->cancellable, avatar_cache_close_cb, loader); } if (error) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning ("%s: %s", G_STRFUNC, error->message); g_error_free (error); } }
/* * Try and read another multipart message. if in is NULL then there are no more * messages to read. */ static void next_part_cb (GObject *source, GAsyncResult *async_result, gpointer user_data) { //g_print ("next_part_cb: Enter\n"); SoupMultipartInputStream *multipart = SOUP_MULTIPART_INPUT_STREAM (source); MultiPartData *multipart_data = (MultiPartData *) user_data; g_assert (SOUP_MULTIPART_INPUT_STREAM (source) == multipart_data->multipart); GInputStream *in = soup_multipart_input_stream_next_part_finish (multipart, async_result, &multipart_data->error); if (!in) { g_input_stream_close_async (G_INPUT_STREAM (multipart), G_PRIORITY_DEFAULT, multipart_data->cancellable, close_base_cb, user_data); return; } // Read the headers here. multipart_read_headers (multipart_data); multipart_data->buffer = g_string_sized_new(READ_BUFFER_SIZE); g_input_stream_read_async (in, buffer, READ_BUFFER_SIZE, G_PRIORITY_DEFAULT, multipart_data->cancellable, read_cb, user_data); //g_print ("next_part_cb: Exit\n"); }
static void www_pixbufRead_cb (GObject *source_object, GAsyncResult *res, struct rom_romItem *item) { GError *error = NULL; GInputStream *stream = G_INPUT_STREAM (source_object); item->tile = gdk_pixbuf_new_from_stream_finish (res, &error); g_input_stream_close_async (stream, G_PRIORITY_HIGH, NULL, (GAsyncReadyCallback) www_closeStream_cb, NULL); gchar* localName = www_getFileNameWWW (item->name); if (!error) { g_print ("%s fetched %s \n", item->name, SUCCESS_MSG); if (gdk_pixbuf_save (item->tile, localName, "png", &error, NULL)) { g_print ("%s saved %s \n", item->name, SUCCESS_MSG); } else { g_print ("%s not saved %s \n", item->name, FAIL_MSG); g_warning ("can't save: %s\n", error->message); g_error_free (error); } } else { g_warning ("pixbuf stream error:%s\n", error->message); g_error_free (error); item->tile = NULL; } item->tileLoaded = TRUE; item->tileLoading = FALSE; g_free (localName); if (ui_tileIsVisible (item)) { ui_invalidateDrawingArea (); } www_downloadingItm--; }
static void file_read_callback (GObject *object, GAsyncResult *res, gpointer data) { CajaImagePropertiesPage *page; GInputStream *stream; gssize count_read; GError *error; int exif_still_loading; gboolean done_reading; page = CAJA_IMAGE_PROPERTIES_PAGE (data); stream = G_INPUT_STREAM (object); error = NULL; done_reading = FALSE; count_read = g_input_stream_read_finish (stream, res, &error); if (count_read > 0) { g_assert (count_read <= sizeof(page->details->buffer)); #ifdef HAVE_EXIF exif_still_loading = exif_loader_write (page->details->exifldr, page->details->buffer, count_read); #else exif_still_loading = 0; #endif /*HAVE_EXIF*/ if (page->details->pixbuf_still_loading) { if (!gdk_pixbuf_loader_write (page->details->loader, page->details->buffer, count_read, NULL)) { page->details->pixbuf_still_loading = FALSE; } } if (page->details->pixbuf_still_loading || (exif_still_loading == 1)) { g_input_stream_read_async (G_INPUT_STREAM (stream), page->details->buffer, sizeof (page->details->buffer), 0, page->details->cancellable, file_read_callback, page); } else { done_reading = TRUE; } } else { /* either EOF, cancelled or an error occurred */ done_reading = TRUE; } if (done_reading) { load_finished (page); g_input_stream_close_async (stream, 0, page->details->cancellable, file_close_callback, page); } }
static void file_read_callback (GObject *object, GAsyncResult *res, gpointer data) { NemoImagePropertiesPage *page; GInputStream *stream; gssize count_read; GError *error; int exif_still_loading; gboolean done_reading; page = NEMO_IMAGE_PROPERTIES_PAGE (data); stream = G_INPUT_STREAM (object); error = NULL; done_reading = FALSE; count_read = g_input_stream_read_finish (stream, res, &error); if (count_read > 0) { g_assert (count_read <= sizeof(page->details->buffer)); #ifdef HAVE_EXIF exif_still_loading = exif_loader_write (page->details->exifldr, (guchar *) page->details->buffer, count_read); #else exif_still_loading = 0; #endif if (page->details->pixbuf_still_loading) { if (!gdk_pixbuf_loader_write (page->details->loader, (const guchar *) page->details->buffer, count_read, NULL)) { page->details->pixbuf_still_loading = FALSE; } } if (page->details->pixbuf_still_loading || (exif_still_loading == 1)) { g_input_stream_read_async (G_INPUT_STREAM (stream), page->details->buffer, sizeof (page->details->buffer), 0, page->details->cancellable, file_read_callback, page); } else { done_reading = TRUE; } } else { /* either EOF, cancelled or an error occurred */ done_reading = TRUE; } if (error != NULL) { char *uri = g_file_get_uri (G_FILE (object)); g_warning ("Error reading %s: %s", uri, error->message); g_free (uri); g_clear_error (&error); } if (done_reading) { load_finished (page); g_input_stream_close_async (stream, 0, page->details->cancellable, file_close_callback, page); } }
static gboolean rygel_seekable_response_close_stream_co (RygelSeekableResponseCloseStreamData* data) { switch (data->_state_) { case 0: goto _state_0; case 21: goto _state_21; default: g_assert_not_reached (); } _state_0: { { data->_state_ = 21; g_input_stream_close_async ((GInputStream*) data->self->priv->input_stream, data->self->priv->priority, rygel_state_machine_get_cancellable ((RygelStateMachine*) data->self), rygel_seekable_response_close_stream_ready, data); return FALSE; _state_21: #line 151 "rygel-seekable-response.vala" g_input_stream_close_finish ((GInputStream*) data->self->priv->input_stream, data->_res_, &data->_inner_error_); #line 863 "rygel-seekable-response.c" if (data->_inner_error_ != NULL) { goto __catch38_g_error; } } goto __finally38; __catch38_g_error: { data->err = data->_inner_error_; data->_inner_error_ = NULL; { #line 154 "rygel-seekable-response.vala" g_warning (_ ("Failed to close stream to URI %s: %s"), data->_tmp0_ = g_file_get_uri (data->self->priv->file), data->err->message); #line 876 "rygel-seekable-response.c" _g_free0 (data->_tmp0_); _g_error_free0 (data->err); } } __finally38: if (data->_inner_error_ != NULL) { g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, data->_inner_error_->message, g_quark_to_string (data->_inner_error_->domain), data->_inner_error_->code); g_clear_error (&data->_inner_error_); return FALSE; } #line 159 "rygel-seekable-response.vala" if (rygel_state_machine_get_cancellable ((RygelStateMachine*) data->self) == NULL) { #line 159 "rygel-seekable-response.vala" data->_tmp1_ = TRUE; #line 891 "rygel-seekable-response.c" } else { #line 159 "rygel-seekable-response.vala" data->_tmp1_ = !g_cancellable_is_cancelled (rygel_state_machine_get_cancellable ((RygelStateMachine*) data->self)); #line 895 "rygel-seekable-response.c" } #line 159 "rygel-seekable-response.vala" if (data->_tmp1_) { #line 160 "rygel-seekable-response.vala" rygel_http_response_end ((RygelHTTPResponse*) data->self, FALSE, (guint) SOUP_STATUS_NONE); #line 901 "rygel-seekable-response.c" } } { if (data->_state_ == 0) { g_simple_async_result_complete_in_idle (data->_async_result); } else { g_simple_async_result_complete (data->_async_result); } g_object_unref (data->_async_result); return FALSE; } }