summaryrefslogtreecommitdiffstats
path: root/src/vmcstream.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vmcstream.c')
-rw-r--r--src/vmcstream.c35
1 files changed, 5 insertions, 30 deletions
diff --git a/src/vmcstream.c b/src/vmcstream.c
index 5dd2799..f933e3a 100644
--- a/src/vmcstream.c
+++ b/src/vmcstream.c
@@ -19,6 +19,7 @@
#include <string.h>
+#include "gtask-helper.h"
#include "vmcstream.h"
#include "spice-channel-priv.h"
#include "gio-coroutine.h"
@@ -97,24 +98,6 @@ spice_vmc_input_stream_new(void)
return self;
}
-typedef struct _complete_in_idle_cb_data {
- GTask *task;
- gssize pos;
-} complete_in_idle_cb_data;
-
-static gboolean
-complete_in_idle_cb(gpointer user_data)
-{
- complete_in_idle_cb_data *data = user_data;
-
- g_task_return_int(data->task, data->pos);
-
- g_object_unref (data->task);
- g_free (data);
-
- return FALSE;
-}
-
/* coroutine */
/**
* Feed a SpiceVmc stream with new data from a coroutine
@@ -134,8 +117,6 @@ spice_vmc_input_stream_co_data(SpiceVmcInputStream *self,
self->coroutine = coroutine_self();
while (size > 0) {
- complete_in_idle_cb_data *cb_data;
-
SPICE_DEBUG("spicevmc co_data %p", self->task);
if (!self->task)
coroutine_yield(NULL);
@@ -157,13 +138,7 @@ spice_vmc_input_stream_co_data(SpiceVmcInputStream *self,
if (self->all && min > 0 && self->pos != self->count)
continue;
- /* Let's deal with the task complete in idle by ourselves, as GTask
- * heuristic only makes sense in a non-coroutine case.
- */
- cb_data = g_new(complete_in_idle_cb_data , 1);
- cb_data->task = g_object_ref(self->task);
- cb_data->pos = self->pos;
- g_idle_add(complete_in_idle_cb, cb_data);
+ g_task_helper_return_integer(self->task, self->pos);
g_cancellable_disconnect(g_task_get_cancellable(self->task), self->cancel_id);
g_clear_object(&self->task);
@@ -179,9 +154,9 @@ read_cancelled(GCancellable *cancellable,
SpiceVmcInputStream *self = SPICE_VMC_INPUT_STREAM(user_data);
SPICE_DEBUG("read cancelled, %p", self->task);
- g_task_return_new_error(self->task,
- G_IO_ERROR, G_IO_ERROR_CANCELLED,
- "read cancelled");
+ g_task_helper_return_new_error(self->task,
+ G_IO_ERROR, G_IO_ERROR_CANCELLED,
+ "read cancelled");
g_clear_object(&self->task);