From df876bc74322b7cd61d0691a20e281891a822318 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Mon, 27 Sep 2010 18:23:54 -0400 Subject: [PATCH 2/3] Keep GCancellable alive during the async calls Keep a reference on GCancellable for the time of the async calls. This is important to allow simple cancel and forget of cancellable by caller. Most call where already implemented correctly, this patch fixes the remaining. --- tests/wocky-test-sasl-auth-server.c | 17 ++++++++++++++++- tests/wocky-test-stream.c | 5 +++-- wocky/wocky-openssl.c | 10 ++++++++-- wocky/wocky-porter.c | 8 ++++++-- wocky/wocky-tls.c | 9 +++++++-- wocky/wocky-xmpp-connection.c | 21 ++++++++++++++++----- 6 files changed, 56 insertions(+), 14 deletions(-) diff --git a/tests/wocky-test-sasl-auth-server.c b/tests/wocky-test-sasl-auth-server.c index d3de229..67cb92d 100644 --- a/tests/wocky-test-sasl-auth-server.c +++ b/tests/wocky-test-sasl-auth-server.c @@ -271,6 +271,11 @@ post_auth_recv_stanza (GObject *source, GSimpleAsyncResult *r = priv->result; priv->result = NULL; + + if (priv->cancellable != NULL) + g_object_unref (priv->cancellable); + priv->cancellable = NULL; + g_simple_async_result_set_from_error (r, error); g_simple_async_result_complete (r); @@ -317,6 +322,11 @@ post_auth_open_sent (GObject *source, GSimpleAsyncResult *r = priv->result; priv->result = NULL; + + if (priv->cancellable != NULL) + g_object_unref (priv->cancellable); + priv->cancellable = NULL; + g_simple_async_result_complete (r); g_object_unref (r); } @@ -391,6 +401,9 @@ failure_sent (GObject *source, if (r != NULL) { + if (priv->cancellable != NULL) + g_object_unref (priv->cancellable); + priv->cancellable = NULL; g_simple_async_result_complete (r); g_object_unref (r); } @@ -994,7 +1007,9 @@ test_sasl_auth_server_auth_async (GObject *obj, priv->state = AUTH_STATE_STARTED; priv->conn = g_object_ref (conn); - priv->cancellable = cancellable; + + if (cancellable != NULL) + priv->cancellable = g_object_ref (cancellable); /* save the details of the point ot which we will hand back control */ if (cb != NULL) diff --git a/tests/wocky-test-stream.c b/tests/wocky-test-stream.c index 4f656ae..9937b39 100644 --- a/tests/wocky-test-stream.c +++ b/tests/wocky-test-stream.c @@ -333,9 +333,10 @@ read_async_complete (WockyTestInputStream *self) { g_signal_handler_disconnect (self->read_cancellable, self->read_cancellable_sig_id); + g_object_unref (self->read_cancellable); + self->read_cancellable = NULL; } - self->read_cancellable = NULL; self->read_result = NULL; g_simple_async_result_complete_in_idle (r); @@ -386,7 +387,7 @@ wocky_test_input_stream_read_async (GInputStream *stream, if (cancellable != NULL) { - self->read_cancellable = cancellable; + self->read_cancellable = g_object_ref (cancellable); self->read_cancellable_sig_id = g_signal_connect (cancellable, "cancelled", G_CALLBACK (read_cancelled_cb), self); } diff --git a/wocky/wocky-openssl.c b/wocky/wocky-openssl.c index d8ecbdf..cf8400f 100644 --- a/wocky/wocky-openssl.c +++ b/wocky/wocky-openssl.c @@ -282,6 +282,13 @@ wocky_tls_job_make_result (WockyTLSJob *job, if (job->source_object) g_object_unref (job->source_object); + + if (job->cancellable) + g_object_unref (job->cancellable); + + job->source_object = NULL; + job->cancellable = NULL; + job->active = FALSE; return simple; @@ -625,9 +632,8 @@ wocky_tls_job_start (WockyTLSJob *job, job->source_object = g_object_ref (source_object); job->io_priority = io_priority; - job->cancellable = cancellable; if (cancellable) - g_object_ref (cancellable); + job->cancellable = g_object_ref (cancellable); job->callback = callback; job->user_data = user_data; job->source_tag = source_tag; diff --git a/wocky/wocky-porter.c b/wocky/wocky-porter.c index 11c75e6..56a2f5f 100644 --- a/wocky/wocky-porter.c +++ b/wocky/wocky-porter.c @@ -868,6 +868,8 @@ complete_close (WockyPorter *self) G_IO_ERROR_CANCELLED, "closing operation was cancelled"); } + if (priv->close_cancellable) + g_object_unref (priv->close_cancellable); tmp = priv->close_result; priv->close_result = NULL; @@ -1401,7 +1403,8 @@ wocky_porter_close_async (WockyPorter *self, priv->close_result = result; - priv->close_cancellable = cancellable; + if (cancellable != NULL) + priv->close_cancellable = g_object_ref (cancellable); g_signal_emit (self, signals[CLOSING], 0); @@ -1822,9 +1825,10 @@ wocky_porter_force_close_async (WockyPorter *self, g_signal_emit (self, signals[CLOSING], 0); } - priv->force_close_cancellable = cancellable; priv->force_close_result = result; + if (cancellable != NULL) + priv->force_close_cancellable = g_object_ref (cancellable); /* Terminate all the pending sending operations */ elem = g_queue_pop_head (priv->sending_queue); diff --git a/wocky/wocky-tls.c b/wocky/wocky-tls.c index e569e3e..f364cf1 100644 --- a/wocky/wocky-tls.c +++ b/wocky/wocky-tls.c @@ -327,7 +327,13 @@ wocky_tls_job_make_result (WockyTLSJob *job, g_error_free (error); } + if (job->cancellable) + g_object_unref (job->cancellable); + job->cancellable = NULL; + g_object_unref (job->source_object); + job->source_object = NULL; + job->active = FALSE; return simple; @@ -453,9 +459,8 @@ wocky_tls_job_start (WockyTLSJob *job, job->source_object = g_object_ref (source_object); job->io_priority = io_priority; - job->cancellable = cancellable; if (cancellable) - g_object_ref (cancellable); + job->cancellable = g_object_ref (cancellable); job->callback = callback; job->user_data = user_data; job->source_tag = source_tag; diff --git a/wocky/wocky-xmpp-connection.c b/wocky/wocky-xmpp-connection.c index fee0af1..4368bc6 100644 --- a/wocky/wocky-xmpp-connection.c +++ b/wocky/wocky-xmpp-connection.c @@ -304,6 +304,9 @@ finished: { GSimpleAsyncResult *r = priv->output_result; + if (priv->output_cancellable != NULL) + g_object_unref (priv->output_cancellable); + priv->output_cancellable = NULL; priv->output_result = NULL; @@ -392,8 +395,9 @@ wocky_xmpp_connection_send_open_async (WockyXmppConnection *connection, g_assert (priv->output_result == NULL); g_assert (priv->output_cancellable == NULL); + if (cancellable != NULL) + priv->output_cancellable = g_object_ref (cancellable); - priv->output_cancellable = cancellable; priv->output_result = result; priv->offset = 0; priv->length = 0; @@ -525,6 +529,9 @@ finished: { GSimpleAsyncResult *r = priv->input_result; + if (priv->input_cancellable != NULL) + g_object_unref (priv->input_cancellable); + priv->input_cancellable = NULL; priv->input_result = NULL; @@ -587,7 +594,8 @@ wocky_xmpp_connection_recv_open_async (WockyXmppConnection *connection, priv->input_result = result; - priv->input_cancellable = cancellable; + if (cancellable != NULL) + priv->input_cancellable = g_object_ref (cancellable); wocky_xmpp_connection_do_read (connection); @@ -717,8 +725,9 @@ wocky_xmpp_connection_send_stanza_async (WockyXmppConnection *connection, g_assert (priv->output_result == NULL); g_assert (priv->output_cancellable == NULL); + if (cancellable != NULL) + priv->output_cancellable = g_object_ref (cancellable); - priv->output_cancellable = cancellable; priv->output_result = result; priv->offset = 0; priv->length = 0; @@ -825,9 +834,10 @@ wocky_xmpp_connection_recv_stanza_async (WockyXmppConnection *connection, return; } - priv->input_cancellable = cancellable; priv->input_result = result; + if (cancellable != NULL) + priv->input_cancellable = g_object_ref (cancellable); wocky_xmpp_connection_do_read (connection); return; @@ -951,8 +961,9 @@ wocky_xmpp_connection_send_close_async (WockyXmppConnection *connection, g_assert (priv->output_result == NULL); g_assert (priv->output_cancellable == NULL); + if (cancellable != NULL) + priv->output_cancellable = g_object_ref (cancellable); - priv->output_cancellable = cancellable; priv->output_result = result; priv->offset = 0; priv->length = 0; -- 1.7.2.3