[Spice-devel] [PATCH spice-gtk 12/15] channel-main: file_xfer_failed -> file_xfer_completed

Marc-André Lureau marcandre.lureau at gmail.com
Sun Mar 10 07:31:30 PDT 2013


Is that necessary? According to GInputStream doc: " Closing a stream
multiple times will not return an error."

On Sat, Mar 9, 2013 at 12:06 PM, Hans de Goede <hdegoede at redhat.com> wrote:
> Make file_xfer_failed usable for all file_stream closing and protect it
> against double calls.
>
> Signed-off-by: Hans de Goede <hdegoede at redhat.com>
> ---
>  gtk/channel-main.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/gtk/channel-main.c b/gtk/channel-main.c
> index e4b9f9e..39061e9 100644
> --- a/gtk/channel-main.c
> +++ b/gtk/channel-main.c
> @@ -55,6 +55,7 @@ typedef struct spice_migrate spice_migrate;
>  #define FILE_XFER_CHUNK_SIZE (VD_AGENT_MAX_DATA_SIZE * 32)
>  typedef struct SpiceFileXferTask {
>      uint32_t                       id;
> +    gboolean                       closed;
>      GFile                          *file;
>      SpiceMainChannel               *channel;
>      GFileInputStream               *file_stream;
> @@ -2585,17 +2586,24 @@ void spice_main_set_display_enabled(SpiceMainChannel *channel, int id, gboolean
>      c->timer_id = g_timeout_add_seconds(1, timer_set_display, channel);
>  }
>
> -static void file_xfer_failed(SpiceFileXferTask *task, GError *error)
> +static void file_xfer_completed(SpiceFileXferTask *task, GError *error)
>  {
> -    SPICE_DEBUG("File %s xfer failed: %s",
> -                g_file_get_path(task->file), error->message);
> +    if (task->closed) {
> +        g_clear_error(&error);
> +        return;
> +    }
>
> -    task->error = error;
> +    if (error) {
> +        SPICE_DEBUG("File %s xfer failed: %s",
> +                    g_file_get_path(task->file), error->message);
> +        task->error = error;
> +    }
>      g_input_stream_close_async(G_INPUT_STREAM(task->file_stream),
>                                 G_PRIORITY_DEFAULT,
>                                 task->cancellable,
>                                 file_xfer_close_cb,
>                                 task);
> +    task->closed = TRUE;
>  }
>
>  static void file_xfer_info_async_cb(GObject *obj, GAsyncResult *res, gpointer data)
> @@ -2646,7 +2654,7 @@ static void file_xfer_info_async_cb(GObject *obj, GAsyncResult *res, gpointer da
>      return;
>
>  failed:
> -    file_xfer_failed(task, error);
> +    file_xfer_completed(task, error);
>  }
>
>  static void file_xfer_read_async_cb(GObject *obj, GAsyncResult *res, gpointer data)
> --
> 1.8.1.4
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel



-- 
Marc-André Lureau


More information about the Spice-devel mailing list