Re: [PATCH 13/14] wocky-http-proxy: Use GTask instead of GSimpleAsyncResult

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jan 18, 2016 at 10:05:49AM +0100, Fabiano Fidêncio wrote:
> Instead of using GSimpleAsyncResult, use the new GTask API, which is
> much more straightforward.

Is there an upstream for wocky-http-proxy where you should send this
patch?

> ---
>  src/wocky-http-proxy.c | 47 ++++++++++++++++++-----------------------------
>  1 file changed, 18 insertions(+), 29 deletions(-)
> 
> diff --git a/src/wocky-http-proxy.c b/src/wocky-http-proxy.c
> index d84cd72..f079e10 100644
> --- a/src/wocky-http-proxy.c
> +++ b/src/wocky-http-proxy.c
> @@ -254,14 +254,13 @@ error:
>  
>  typedef struct
>  {
> -  GSimpleAsyncResult *simple;
> +  GTask *task;
>    GIOStream *io_stream;
>    gchar *buffer;
>    gssize length;
>    gssize offset;
>    GDataInputStream *data_in;
>    gboolean has_cred;
> -  GCancellable *cancellable;
>  } ConnectAsyncData;
>  
>  static void request_write_cb (GObject *source,
> @@ -282,26 +281,22 @@ free_connect_data (ConnectAsyncData *data)
>    if (data->data_in != NULL)
>      g_object_unref (data->data_in);
>  
> -  if (data->cancellable != NULL)
> -    g_object_unref (data->cancellable);
> -
>    g_free (data);
>  }
>  
>  static void
>  complete_async_from_error (ConnectAsyncData *data, GError *error)
>  {
> -  GSimpleAsyncResult *simple = data->simple;
> +  GTask *task = data->task;
>  
>    if (error == NULL)
>      g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_PROXY_FAILED,
>          "HTTP proxy server closed connection unexpectedly.");
>  
> -  g_simple_async_result_set_from_error (data->simple, error);
> +  g_task_return_error(data->task, error);
>    g_error_free (error);

This should be removed

> -  g_simple_async_result_set_op_res_gpointer (simple, NULL, NULL);
> -  g_simple_async_result_complete (simple);
> -  g_object_unref (simple);
> +  g_task_return_pointer(task, NULL, NULL);

I don't think you need this g_task_return_pointer(), you already
returned an error.

> +  g_object_unref (task);
>  }
>  
>  static void
> @@ -312,7 +307,7 @@ do_write (GAsyncReadyCallback callback, ConnectAsyncData *data)
>    g_output_stream_write_async (out,
>        data->buffer + data->offset,
>        data->length - data->offset,
> -      G_PRIORITY_DEFAULT, data->cancellable,
> +      G_PRIORITY_DEFAULT, g_task_get_cancellable(data->task),
>        callback, data);
>  }
>  
> @@ -357,24 +352,22 @@ wocky_http_proxy_connect_async (GProxy *proxy,
>      GAsyncReadyCallback callback,
>      gpointer user_data)
>  {
> -  GSimpleAsyncResult *simple;
> +  GTask *task;
>    ConnectAsyncData *data;
>  
> -  simple = g_simple_async_result_new (G_OBJECT (proxy),
> -                                      callback, user_data,
> -                                      wocky_http_proxy_connect_async);
> +  task = g_task_new (proxy,
> +                     cancellable,
> +                     callback,
> +                     user_data);
>  
>    data = g_new0 (ConnectAsyncData, 1);
> -  if (cancellable != NULL)
> -    data->cancellable = g_object_ref (cancellable);
> -  data->simple = simple;
> +  data->task = task;
>  
>    data->buffer = create_request (proxy_address, &data->has_cred);
>    data->length = strlen (data->buffer);
>    data->offset = 0;
>  
> -  g_simple_async_result_set_op_res_gpointer (simple, data,
> -                                             (GDestroyNotify) free_connect_data);
> +  g_task_return_pointer (task, data, (GDestroyNotify) free_connect_data);

Ah, I don't think the initial code meant g_task_return_pointer() here
(there is no call to g_simple_async_result_complete_* in this function).
It's rather a slight abuse of GSimpleAsyncResult API in order to get
g_task_set_task_data functionality. Or maybe this is really the value
that it wants to return to the user, but not before it's time to do that
in reply_read_cb().

>  
>    if (WOCKY_IS_HTTPS_PROXY (proxy))
>      {
> @@ -435,7 +428,7 @@ request_write_cb (GObject *source,
>        g_data_input_stream_read_until_async (data->data_in,
>            HTTP_END_MARKER,
>            G_PRIORITY_DEFAULT,
> -          data->cancellable,
> +          g_task_get_cancellable(data->task),
>            reply_read_cb, data);
>  
>      }
> @@ -468,8 +461,7 @@ reply_read_cb (GObject *source,
>        return;
>      }
>  
> -  g_simple_async_result_complete (data->simple);

You need a g_task_return_xxxx here in my opinion.


Christophe

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]