Beispiel #1
0
static void
send_async_finished (GInputStream *stream)
{
  SoupInputStreamPrivate *priv = SOUP_INPUT_STREAM_GET_PRIVATE (stream);
  GSimpleAsyncResult *result;
  GError *error = NULL;

  if (!g_cancellable_set_error_if_cancelled (priv->cancellable, &error))
    set_error_if_http_failed (priv->msg, &error);

  priv->got_headers_cb = NULL;
  priv->finished_cb = NULL;
  soup_input_stream_done_io (stream);

  result = priv->result;
  priv->result = NULL;

  g_simple_async_result_set_op_res_gboolean (result, error == NULL);
  if (error)
    {
      g_simple_async_result_set_from_error (result, error);
      g_error_free (error);
    }
  g_simple_async_result_complete (result);
}
Beispiel #2
0
static gssize
soup_input_stream_read (GInputStream *stream,
			void         *buffer,
			gsize         count,
			GCancellable *cancellable,
			GError      **error)
{
  SoupInputStreamPrivate *priv = SOUP_INPUT_STREAM_GET_PRIVATE (stream);

  if (priv->finished)
    return 0;

  /* If there is data leftover from a previous read, return it. */
  if (priv->leftover_bufsize)
    return read_from_leftover (priv, buffer, count);

  /* No leftover data, accept one chunk from the network */
  soup_input_stream_prepare_for_io (stream, cancellable, buffer, count);
  while (!priv->finished && priv->caller_nread == 0 &&
	 !g_cancellable_is_cancelled (cancellable))
    g_main_context_iteration (priv->async_context, TRUE);
  soup_input_stream_done_io (stream);

  if (priv->caller_nread > 0)
    return priv->caller_nread;

  if (g_cancellable_set_error_if_cancelled (cancellable, error))
    return -1;
  else if (set_error_if_http_failed (priv->msg, error))
    return -1;
  else
    return 0;
}
Beispiel #3
0
static void
close_async_done (GOutputStream *stream)
{
  SoupOutputStreamPrivate *priv = SOUP_OUTPUT_STREAM_GET_PRIVATE (stream);
  GSimpleAsyncResult *result;
  GError *error = NULL;

  result = priv->result;
  priv->result = NULL;

  if (g_cancellable_set_error_if_cancelled (priv->cancellable, &error) ||
      set_error_if_http_failed (priv->msg, &error))
    {
      g_simple_async_result_set_from_error (result, error);
      g_error_free (error);
    }
  else
    g_simple_async_result_set_op_res_gboolean (result, TRUE);

  priv->finished_cb = NULL;
  priv->cancelled_cb = NULL;
  soup_output_stream_done_io (stream);

  g_simple_async_result_complete (result);
  g_object_unref (result);
}
Beispiel #4
0
/* This does the work of soup_input_stream_send(), assuming that the
 * GInputStream pending flag has already been set. It is also used by
 * soup_input_stream_send_async() in some circumstances.
 */
static gboolean
soup_input_stream_send_internal (GInputStream  *stream,
				 GCancellable  *cancellable,
				 GError       **error)
{
  SoupInputStreamPrivate *priv = SOUP_INPUT_STREAM_GET_PRIVATE (stream);

  soup_input_stream_prepare_for_io (stream, cancellable, NULL, 0);
  while (!priv->finished && !priv->got_headers &&
	 !g_cancellable_is_cancelled (cancellable))
    g_main_context_iteration (priv->async_context, TRUE);
  soup_input_stream_done_io (stream);

  if (g_cancellable_set_error_if_cancelled (cancellable, error))
    return FALSE;
  else if (set_error_if_http_failed (priv->msg, error))
    return FALSE;
  return TRUE;
}
Beispiel #5
0
static int
soup_output_stream_close (GOutputStream  *stream,
			  GCancellable   *cancellable,
			  GError        **error)
{
  SoupOutputStreamPrivate *priv = SOUP_OUTPUT_STREAM_GET_PRIVATE (stream);

  if (priv->size > 0 && priv->offset != priv->size) {
      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NO_SPACE,
			   "File is incomplete");
      return -1;
  }

  soup_output_stream_prepare_for_io (stream, cancellable);
  while (!priv->finished && !g_cancellable_is_cancelled (cancellable))
    g_main_context_iteration (priv->async_context, TRUE);
  soup_output_stream_done_io (stream);

  return !set_error_if_http_failed (priv->msg, error);
}