static void read_cb (GObject *source, GAsyncResult *asyncResult, gpointer data) { GMainLoop *loop = (GMainLoop*)data; GInputStream *stream = G_INPUT_STREAM (source); GError *error = NULL; gssize bytes_read = g_input_stream_read_finish (stream, asyncResult, &error); if (error) { debug_printf (1, " failed read: %s\n", error->message); errors++; g_object_unref (stream); g_main_loop_quit (loop); return; } if (!bytes_read) { g_input_stream_close (stream, NULL, &error); g_object_unref (stream); if (error) { debug_printf (1, " failed close: %s\n", error->message); errors++; } g_main_loop_quit (loop); return; } g_input_stream_read_async (stream, buffer, READ_BUFFER_SIZE, G_PRIORITY_DEFAULT, NULL, read_cb, data); }
static void read_all_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GInputStream *stream = G_INPUT_STREAM (source_object); GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); gsize bytes_read; GError *err = NULL; ReadAllData *read_data; bytes_read = g_input_stream_read_finish (stream, res, &err); if (bytes_read == -1) { g_simple_async_result_take_error (simple, err); goto done; } read_data = g_simple_async_result_get_op_res_gpointer (simple); read_data->bytes_read += bytes_read; if (read_data->bytes_read < read_data->count) { g_input_stream_read_async (stream, (guint8 *)read_data->buffer + read_data->bytes_read, read_data->count - read_data->bytes_read, 0, read_data->cancellable, read_all_cb, simple); return; } done: g_simple_async_result_complete (simple); g_object_unref (simple); }
static void inputStreamReadReadyCallback(GInputStream* stream, GAsyncResult* result, gpointer userData) { std::unique_ptr<ReadAsyncData> asyncData(static_cast<ReadAsyncData*>(userData)); gssize bytesRead = g_input_stream_read_finish(stream, result, nullptr); if (bytesRead == -1) { asyncData->completionHandler(asyncData->data, -1); return; } if (!bytesRead) { asyncData->completionHandler(asyncData->data, 0); return; } ASSERT(bytesRead > 0); fillDataFromReadBuffer(asyncData->buffer.get(), static_cast<size_t>(bytesRead), asyncData->data); size_t pendingBytesToRead = asyncData->bytesToRead - asyncData->data.size(); if (!pendingBytesToRead) { asyncData->completionHandler(asyncData->data, 0); return; } size_t bytesToRead = std::min(pendingBytesToRead, asyncData->buffer->length); // Use a local variable for the data buffer to pass it to g_input_stream_read_async(), because ReadAsyncData is released. auto data = const_cast<char*>(asyncData->buffer->data); g_input_stream_read_async(stream, data, bytesToRead, G_PRIORITY_DEFAULT, nullptr, reinterpret_cast<GAsyncReadyCallback>(inputStreamReadReadyCallback), asyncData.release()); }
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); }
static void gtkhash_hash_file_read_finish( G_GNUC_UNUSED GObject *source, GAsyncResult *res, struct hash_file_s *data) { data->just_read = g_input_stream_read_finish( G_INPUT_STREAM(data->stream), res, NULL); if (G_UNLIKELY(data->just_read == -1) && !g_cancellable_is_cancelled(data->cancellable)) { g_warning("failed to read file (%s)", data->uri); g_cancellable_cancel(data->cancellable); } else if (G_UNLIKELY(data->just_read == 0)) { g_warning("unexpected EOF (%s)", data->uri); g_cancellable_cancel(data->cancellable); } else { g_mutex_lock(data->priv.mutex); data->priv.total_read += data->just_read; const goffset total_read = data->priv.total_read; g_mutex_unlock(data->priv.mutex); if (G_UNLIKELY(total_read > data->file_size)) { g_warning("read %" G_GOFFSET_FORMAT " more bytes than expected (%s)", total_read - data->file_size, data->uri); g_cancellable_cancel(data->cancellable); } else gtkhash_hash_file_set_state(data, HASH_FILE_STATE_HASH); } if (G_UNLIKELY(g_cancellable_is_cancelled(data->cancellable))) gtkhash_hash_file_set_state(data, HASH_FILE_STATE_CLOSE); gtkhash_hash_file_add_source(data); }
static void update_system_bookmark_list_ready (GObject *source_object, GAsyncResult *result, gpointer user_data) { UpdateBookmarksData *data = user_data; gssize size; size = g_input_stream_read_finish (data->stream, result, NULL); if (size < 0) { update_bookmakrs_data_free (data); return; } if (size > 0) { data->buffer[size + 1] = '\0'; g_string_append (data->file_content, data->buffer); g_input_stream_read_async (data->stream, data->buffer, BUFFER_SIZE - 1, G_PRIORITY_DEFAULT, NULL, update_system_bookmark_list_ready, data); return; } update_system_bookmark_list_from_content (data->browser, data->file_content->str); update_bookmakrs_data_free (data); }
static void _input_stream_read_ready(GObject *source_object, GAsyncResult *res, gpointer user_data) { GInputStream *input_stream = G_INPUT_STREAM(source_object); IdleServerConnection *conn = IDLE_SERVER_CONNECTION(user_data); IdleServerConnectionPrivate *priv = IDLE_SERVER_CONNECTION_GET_PRIVATE(conn); gssize ret; GError *error = NULL; if (priv->io_stream == NULL) /* ie. we are in the process of disconnecting */ goto cleanup; ret = g_input_stream_read_finish(input_stream, res, &error); if (ret == -1) { IDLE_DEBUG("g_input_stream_read failed: %s", error->message); g_error_free(error); goto disconnect; } else if (ret == 0) { IDLE_DEBUG("g_input_stream_read returned end-of-file"); goto disconnect; } g_signal_emit(conn, signals[RECEIVED], 0, priv->input_buffer); _input_stream_read(conn, input_stream, _input_stream_read_ready); return; disconnect: if (priv->state == SERVER_CONNECTION_STATE_CONNECTED) idle_server_connection_disconnect_full_async(conn, SERVER_CONNECTION_STATE_REASON_ERROR, NULL, NULL, NULL); cleanup: g_object_unref(conn); }
static void stream_read_async_cb (GObject *obj, GAsyncResult *res, gpointer data) { RBChunkLoader *loader = RB_CHUNK_LOADER (data); gssize done; done = g_input_stream_read_finish (G_INPUT_STREAM (obj), res, &loader->priv->error); if (done == -1) { rb_debug ("error reading from stream: %s", loader->priv->error->message); loader->priv->callback (loader, NULL, 0, loader->priv->callback_data); cleanup (loader); } else if (done == 0) { rb_debug ("reached end up input stream"); loader->priv->callback (loader, NULL, 0, loader->priv->callback_data); cleanup (loader); } else { loader->priv->chunk_string.len = done; loader->priv->callback (loader, &loader->priv->chunk_string, loader->priv->total, loader->priv->callback_data); g_input_stream_read_async (G_INPUT_STREAM (loader->priv->stream), loader->priv->chunk, loader->priv->chunk_size, G_PRIORITY_DEFAULT, loader->priv->cancel, stream_read_async_cb, loader); } }
/* *** read () *** */ static void read_ready (GObject *source_object, GAsyncResult *result, gpointer user_data) { GInputStream *stream; GVfsJob *job; GError *error; gssize nread; stream = G_INPUT_STREAM (source_object); error = NULL; job = G_VFS_JOB (user_data); nread = g_input_stream_read_finish (stream, result, &error); if (nread < 0) { g_vfs_job_failed_literal (G_VFS_JOB (job), error->domain, error->code, error->message); g_error_free (error); return; } g_vfs_job_read_set_size (G_VFS_JOB_READ (job), nread); g_vfs_job_succeeded (job); }
/* * * 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 on_read_ready (GObject * source_object, GAsyncResult * res, gpointer user_data) { GError * error = NULL; g_input_stream_read_finish (G_INPUT_STREAM (source_object), res, &error); g_clear_error (&error); }
static void on_read_buffer (GObject *obj, GAsyncResult *res, gpointer user_data) { GError *error = NULL; gssize count; count = g_input_stream_read_finish (G_INPUT_STREAM (obj), res, &error); complete_read_buffer (user_data, count, error); }
static void load_stream_data_read_callback (GObject *object, GAsyncResult *read_res, gpointer user_data) { GInputStream *stream = G_INPUT_STREAM (object); LoadStreamData *data = user_data; GError *error = NULL; gssize read_size; read_size = g_input_stream_read_finish (stream, read_res, &error); if (read_size < 0) { if (error != NULL) data->error = error; else { GSimpleAsyncResult *res; /* EOF */ res = g_simple_async_result_new (G_OBJECT (data->parser), data->callback, data->user_data, json_parser_load_from_stream_async); g_simple_async_result_set_op_res_gpointer (res, data, load_stream_data_free); g_simple_async_result_complete (res); g_object_unref (res); } } else if (read_size > 0) { data->pos += read_size; g_byte_array_set_size (data->content, data->pos + GET_DATA_BLOCK_SIZE); g_input_stream_read_async (stream, data->content->data + data->pos, GET_DATA_BLOCK_SIZE, 0, data->cancellable, load_stream_data_read_callback, data); } else { GSimpleAsyncResult *res; res = g_simple_async_result_new (G_OBJECT (data->parser), data->callback, data->user_data, json_parser_load_from_stream_async); g_simple_async_result_set_op_res_gpointer (res, data, load_stream_data_free); g_simple_async_result_complete (res); g_object_unref (res); } }
static void readReadyCallback(GInputStream* stream, GAsyncResult* result, void* id) { // Always finish the read, even if this SocketStreamHandle was deactivated earlier. GOwnPtr<GError> error; gssize bytesRead = g_input_stream_read_finish(stream, result, &error.outPtr()); SocketStreamHandle* handle = getHandleFromId(id); if (!handle) return; handle->readBytes(bytesRead, error.get()); }
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 identd_read_ready (GInputStream *in_stream, GAsyncResult *res, ident_info *info) { GSocketAddress *sok_addr; GOutputStream *out_stream; guint64 local, remote; gchar buf[512], *p; if (g_input_stream_read_finish (in_stream, res, NULL)) { local = g_ascii_strtoull (info->read_buf, NULL, 0); p = strchr (info->read_buf, ','); if (!p) goto cleanup; remote = g_ascii_strtoull (p + 1, NULL, 0); if (!local || !remote || local > G_MAXUINT16 || remote > G_MAXUINT16) goto cleanup; info->username = g_strdup (g_hash_table_lookup (responses, GINT_TO_POINTER (local))); if (!info->username) goto cleanup; g_hash_table_remove (responses, GINT_TO_POINTER (local)); if ((sok_addr = g_socket_connection_get_remote_address (info->conn, NULL))) { GInetAddress *inet_addr; gchar *addr; inet_addr = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (sok_addr)); addr = g_inet_address_to_string (inet_addr); hextor_printf (ph, _("*\tServicing ident request from %s as %s"), addr, info->username); g_object_unref (sok_addr); g_object_unref (inet_addr); g_free (addr); } g_snprintf (buf, sizeof (buf), "%"G_GUINT16_FORMAT", %"G_GUINT16_FORMAT" : USERID : UNIX : %s\r\n", (guint16)local, (guint16)remote, info->username); out_stream = g_io_stream_get_output_stream (G_IO_STREAM (info->conn)); g_output_stream_write_async (out_stream, buf, strlen (buf), G_PRIORITY_DEFAULT, NULL, (GAsyncReadyCallback)identd_write_ready, info); } return; cleanup: g_object_unref (info->conn); g_free (info); }
static void file_read_callback (GObject *source_object, GAsyncResult *res, gpointer user_data) { EelPixbufLoadHandle *handle; gssize bytes_read; GError *error; handle = user_data; if (g_cancellable_is_cancelled (handle->cancellable)) { free_pixbuf_load_handle (handle); return; } error = NULL; bytes_read = g_input_stream_read_finish (G_INPUT_STREAM (source_object), res, &error); if (bytes_read > 0) { if (!gdk_pixbuf_loader_write (handle->loader, handle->buffer, bytes_read, &error)) { bytes_read = -1; } else { g_input_stream_read_async (handle->stream, handle->buffer, sizeof (handle->buffer), 0, handle->cancellable, file_read_callback, handle); return; } } load_done (handle, error, bytes_read == 0); if (error != NULL) { g_error_free (error); } }
static void read_finished (GObject *stream, GAsyncResult *result, gpointer user_data) { gssize *nread = user_data; GError *error = NULL; *nread = g_input_stream_read_finish (G_INPUT_STREAM (stream), result, &error); if (error) { debug_printf (1, " Error reading: %s\n", error->message); g_error_free (error); errors++; } }
void SocketStreamHandle::readReadyCallback(GInputStream* stream, GAsyncResult* result, SocketStreamHandle* handle) { RefPtr<SocketStreamHandle> protectedThis = adoptRef(handle); // Always finish the read, even if this SocketStreamHandle was cancelled earlier. GUniqueOutPtr<GError> error; gssize bytesRead = g_input_stream_read_finish(stream, result, &error.outPtr()); if (g_cancellable_is_cancelled(handle->m_cancellable.get())) return; if (error) handle->didFail(SocketStreamError(error->code, error->message)); else handle->readBytes(bytesRead); }
static gssize g_filter_input_stream_read_finish (GInputStream *stream, GAsyncResult *result, GError **error) { GFilterInputStream *filter_stream; GInputStream *base_stream; gssize nread; filter_stream = G_FILTER_INPUT_STREAM (stream); base_stream = filter_stream->base_stream; nread = g_input_stream_read_finish (base_stream, result, error); return nread; }
/* Called when a read completes */ static void vfs_data_read_done (GObject *source, GAsyncResult *res, gpointer callback_data) { VfsAsyncHandle* ah = (VfsAsyncHandle*)callback_data; if (ah->state == VFS_ASYNC_PROCESSING) { g_assert (ah->operation == VFS_OP_READING); g_clear_error (&ah->error); ah->processed = g_input_stream_read_finish (ah->istream, res, &ah->error); ah->state = VFS_ASYNC_READY; ah->total += ah->processed; /* Call progress callback if setup */ if (ah->progcb && ah->total >= ah->last + PROGRESS_BLOCK) (ah->progcb) (ah->gdata, ah->total, ah->userdata); } }
static void on_read_finished (GObject* input, GAsyncResult* result, gpointer data) { SourceviewIO* sio = SOURCEVIEW_IO(data); GInputStream* input_stream = G_INPUT_STREAM(input); gsize current_bytes = 0; GError* err = NULL; current_bytes = g_input_stream_read_finish (input_stream, result, &err); if (err) { g_signal_emit_by_name (sio, "open-failed", err); g_error_free (err); g_object_unref (input_stream); g_free (sio->read_buffer); sio->read_buffer = NULL; sio->bytes_read = 0; return; } sio->bytes_read += current_bytes; if (current_bytes != 0) { sio->read_buffer = g_realloc (sio->read_buffer, sio->bytes_read + READ_SIZE); g_input_stream_read_async (G_INPUT_STREAM (input_stream), sio->read_buffer + sio->bytes_read, READ_SIZE, G_PRIORITY_LOW, sio->cancel, on_read_finished, sio); return; } else { if (append_buffer (sio, sio->bytes_read)) g_signal_emit_by_name (sio, "open-finished"); sio->bytes_read = 0; g_object_unref (input_stream); setup_monitor (sio); g_free (sio->read_buffer); sio->read_buffer = NULL; } }
static void input_stream_read_callback (GObject *source_object, GAsyncResult *res, gpointer user_data) { GnomeGdkPixbufAsyncHandle *handle = user_data; gssize bytes_read; GnomeVFSResult result; bytes_read = g_input_stream_read_finish (G_INPUT_STREAM (source_object), res, NULL); if (bytes_read == -1) { /* TODO: could map the GError more precisely */ result = GNOME_VFS_ERROR_GENERIC; } else if (bytes_read > 0) { if (!gdk_pixbuf_loader_write (handle->loader, (const guchar *) handle->buffer, bytes_read, NULL)) { result = GNOME_VFS_ERROR_WRONG_FORMAT; } else { /* read more */ g_input_stream_read_async (G_INPUT_STREAM (handle->file_input_stream), handle->buffer, sizeof (handle->buffer), G_PRIORITY_DEFAULT, handle->cancellable, input_stream_read_callback, handle); return; } } else { /* EOF */ result = GNOME_VFS_OK; } if (result == GNOME_VFS_OK) { GdkPixbuf *pixbuf; pixbuf = gdk_pixbuf_loader_get_pixbuf (handle->loader); load_done (handle, result, pixbuf); } else { load_done (handle, result, NULL); } }
//------------------------------------------------------------------------------ void onMessage(GObject* source_object, GAsyncResult *res, gpointer user_data) { GInputStream *istream = G_INPUT_STREAM (source_object); GError *err = NULL; ConnData *data = (ConnData*)user_data; int count; count = g_input_stream_read_finish(istream, res, &err); if (count == -1) { g_error ("Error when receiving message"); if (err != NULL) { g_error("%s", err->message); g_clear_error(&err); } ostream = NULL; g_object_unref (G_SOCKET_CONNECTION (data->connection)); delete data; return; } if (count == 0) { g_print("connection closed"); ostream = NULL; g_object_unref (G_SOCKET_CONNECTION (data->connection)); delete data; return; } data->message[count] = 0; g_print("Message: \"%s\"\n", data->message); // start new read // g_input_stream_read_async(istream, data->message, sizeof (data->message), G_PRIORITY_DEFAULT, NULL, onMessage, data); }
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 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 connect_reply_read_cb (GObject *source, GAsyncResult *result, gpointer user_data) { GTask *task = user_data; ConnectAsyncData *data = g_task_get_task_data (task); GError *error = NULL; gssize read; read = g_input_stream_read_finish (G_INPUT_STREAM (source), result, &error); if (read < 0) { g_task_return_error (task, error); g_object_unref (task); return; } data->offset += read; if (data->offset == data->length) { if (!parse_connect_reply (data->buffer, &error)) { g_task_return_error (task, error); g_object_unref (task); return; } else { g_task_return_pointer (task, g_object_ref (data->io_stream), g_object_unref); g_object_unref (task); return; } } else { do_read (connect_reply_read_cb, task, data); } }
static void tunnel_read_cb (GObject *object, GAsyncResult *result, gpointer user_data) { Tunnel *tunnel = user_data; TunnelEnd *read_end, *write_end; GError *error = NULL; gssize nread; nread = g_input_stream_read_finish (G_INPUT_STREAM (object), result, &error); if (nread <= 0) { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { g_error_free (error); return; } else if (error) { g_print ("Tunnel read failed: %s\n", error->message); g_error_free (error); } tunnel_close (tunnel); return; } if (object == (GObject *)tunnel->client.istream) { read_end = &tunnel->client; write_end = &tunnel->server; } else { read_end = &tunnel->server; write_end = &tunnel->client; } read_end->nread = nread; write_end->nwrote = 0; g_output_stream_write_async (write_end->ostream, read_end->buffer, read_end->nread, G_PRIORITY_DEFAULT, tunnel->cancellable, tunnel_wrote_cb, tunnel); }
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); } }
static void read_cb (GObject *source, GAsyncResult *result, gpointer user_data) { PnNode *conn; gssize size; GError *error = NULL; conn = PN_NODE(user_data); size = g_input_stream_read_finish (G_INPUT_STREAM (source), result, &error); conn = PN_NODE(user_data); if (G_UNLIKELY (size == 0)) error = g_error_new_literal(PN_NODE_ERROR, PN_NODE_ERROR_OPEN, "End of stream"); if (error) goto nok; pn_node_parse (conn, (char *) conn->input_buffer, size); if (conn->status == PN_NODE_STATUS_OPEN) g_input_stream_read_async (G_INPUT_STREAM (source), conn->input_buffer, PN_BUF_LEN, G_PRIORITY_DEFAULT, NULL, read_cb, conn); else g_object_unref (conn); return; nok: conn->error = error; pn_node_error (conn); g_object_unref (conn); }