From ca404f4e6e67b7f9aad0f1824cc1de1480e213de Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Mon, 27 Sep 2010 18:20:03 -0400 Subject: [PATCH 1/3] Avoid using g_simple_async_report_error_in_idle() g_simple_async_report_error_in_idle() does not work with g_simple_async_result_is_valid() because it miss the source_tag parameter. Not using it will allow safer result check in the _finish() operation. --- wocky/wocky-connector.c | 12 ++- wocky/wocky-pep-service.c | 11 +- wocky/wocky-porter.c | 130 +++++++++++--------- wocky/wocky-roster.c | 28 +++-- wocky/wocky-sasl-auth.c | 12 ++- wocky/wocky-xmpp-connection.c | 272 +++++++++++++++++++++-------------------- 6 files changed, 255 insertions(+), 210 deletions(-) diff --git a/wocky/wocky-connector.c b/wocky/wocky-connector.c index 696cfe2..13cb09d 100644 --- a/wocky/wocky-connector.c +++ b/wocky/wocky-connector.c @@ -2215,6 +2215,7 @@ connector_connect_async (WockyConnector *self, gpointer user_data) { WockyConnectorPrivate *priv = self->priv; + GSimpleAsyncResult *result; /* 'host' is (by default) the part of the jid after the @ * it must be non-empty (although this test may need to be changed @@ -2227,14 +2228,20 @@ connector_connect_async (WockyConnector *self, gchar *host = NULL; /* domain.tld */ /* / */ gchar *uniq = NULL; /* uniquifier */ + result = g_simple_async_result_new (G_OBJECT (self), cb, user_data, + source_tag); + if (priv->result != NULL) { - g_simple_async_report_error_in_idle (G_OBJECT (self), cb, user_data, + g_simple_async_result_set_error (result, WOCKY_CONNECTOR_ERROR, WOCKY_CONNECTOR_ERROR_IN_PROGRESS, "Connection already established or in progress"); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); return; } + if (priv->cancellable != NULL) { g_warning ("Cancellable already present, but the async result is NULL; " @@ -2243,8 +2250,7 @@ connector_connect_async (WockyConnector *self, priv->cancellable = NULL; } - priv->result = g_simple_async_result_new (G_OBJECT (self), cb, user_data, - source_tag); + priv->result = result; if (cancellable != NULL) priv->cancellable = g_object_ref (cancellable); diff --git a/wocky/wocky-pep-service.c b/wocky/wocky-pep-service.c index 8146937..218596f 100644 --- a/wocky/wocky-pep-service.c +++ b/wocky/wocky-pep-service.c @@ -309,11 +309,16 @@ wocky_pep_service_get_async (WockyPepService *self, GSimpleAsyncResult *result; const gchar *jid; + result = g_simple_async_result_new (G_OBJECT (self), + callback, user_data, wocky_pep_service_get_finish); + if (priv->porter == NULL) { - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, WOCKY_PORTER_ERROR, WOCKY_PORTER_ERROR_NOT_STARTED, + g_simple_async_result_set_error (result, + WOCKY_PORTER_ERROR, WOCKY_PORTER_ERROR_NOT_STARTED, "Service has not been started"); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); return; } @@ -329,8 +334,6 @@ wocky_pep_service_get_async (WockyPepService *self, ')', ')', NULL); - result = g_simple_async_result_new (G_OBJECT (self), - callback, user_data, wocky_pep_service_get_finish); wocky_porter_send_iq_async (priv->porter, msg, cancellable, send_query_cb, result); diff --git a/wocky/wocky-porter.c b/wocky/wocky-porter.c index 0929e2e..11c75e6 100644 --- a/wocky/wocky-porter.c +++ b/wocky/wocky-porter.c @@ -139,8 +139,7 @@ static sending_queue_elem * sending_queue_elem_new (WockyPorter *self, WockyStanza *stanza, GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) + GSimpleAsyncResult *result) { sending_queue_elem *elem = g_slice_new0 (sending_queue_elem); @@ -149,8 +148,7 @@ sending_queue_elem_new (WockyPorter *self, if (cancellable != NULL) elem->cancellable = g_object_ref (cancellable); - elem->result = g_simple_async_result_new (G_OBJECT (self), - callback, user_data, wocky_porter_send_finish); + elem->result = result; return elem; } @@ -784,18 +782,22 @@ wocky_porter_send_async (WockyPorter *self, { WockyPorterPrivate *priv = self->priv; sending_queue_elem *elem; + GSimpleAsyncResult *result; + + result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, + wocky_porter_send_finish); if (priv->close_result != NULL || priv->force_close_result != NULL) { - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, WOCKY_PORTER_ERROR, - WOCKY_PORTER_ERROR_CLOSING, + g_simple_async_result_set_error (result, + WOCKY_PORTER_ERROR, WOCKY_PORTER_ERROR_CLOSING, "Porter is closing"); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); return; } - elem = sending_queue_elem_new (self, stanza, cancellable, callback, - user_data); + elem = sending_queue_elem_new (self, stanza, cancellable, result); g_queue_push_tail (priv->sending_queue, elem); if (g_queue_get_length (priv->sending_queue) == 1) @@ -866,12 +868,12 @@ complete_close (WockyPorter *self) G_IO_ERROR_CANCELLED, "closing operation was cancelled"); } - g_simple_async_result_complete (priv->close_result); tmp = priv->close_result; priv->close_result = NULL; priv->close_cancellable = NULL; + g_simple_async_result_complete (tmp); g_object_unref (tmp); } @@ -1360,44 +1362,44 @@ wocky_porter_close_async (WockyPorter *self, gpointer user_data) { WockyPorterPrivate *priv = self->priv; + GSimpleAsyncResult *result; + + result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, + wocky_porter_close_finish); if (priv->local_closed) { - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, WOCKY_PORTER_ERROR, - WOCKY_PORTER_ERROR_CLOSED, + g_simple_async_result_set_error (result, + WOCKY_PORTER_ERROR, WOCKY_PORTER_ERROR_CLOSED, "Porter has already been closed"); - return; + goto error; } if (priv->receive_cancellable == NULL && !priv->remote_closed) { - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, WOCKY_PORTER_ERROR, - WOCKY_PORTER_ERROR_NOT_STARTED, + g_simple_async_result_set_error (result, + WOCKY_PORTER_ERROR, WOCKY_PORTER_ERROR_NOT_STARTED, "Porter has not been started"); - return; + goto error; } if (priv->close_result != NULL) { - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, G_IO_ERROR, - G_IO_ERROR_PENDING, + g_simple_async_result_set_error (result, + G_IO_ERROR, G_IO_ERROR_PENDING, "Another close operation is pending"); - return; + goto error; } if (priv->force_close_result != NULL) { - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, G_IO_ERROR, G_IO_ERROR_PENDING, + g_simple_async_result_set_error (result, + G_IO_ERROR, G_IO_ERROR_PENDING, "A force close operation is pending"); - return; + goto error; } - priv->close_result = g_simple_async_result_new (G_OBJECT (self), - callback, user_data, wocky_porter_close_finish); + priv->close_result = result; priv->close_cancellable = cancellable; @@ -1411,6 +1413,11 @@ wocky_porter_close_async (WockyPorter *self, } send_close (self); + return; + +error: + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); } /** @@ -1650,6 +1657,9 @@ wocky_porter_send_iq_async (WockyPorter *self, WockyStanzaType type; WockyStanzaSubType sub_type; + result = g_simple_async_result_new (G_OBJECT (self), + callback, user_data, wocky_porter_send_iq_finish); + if (priv->close_result != NULL || priv->force_close_result != NULL) { gchar *node = NULL; @@ -1657,10 +1667,11 @@ wocky_porter_send_iq_async (WockyPorter *self, g_assert (stanza != NULL && wocky_stanza_get_top_node (stanza) != NULL); node = wocky_node_to_string (wocky_stanza_get_top_node (stanza)); - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, WOCKY_PORTER_ERROR, - WOCKY_PORTER_ERROR_CLOSING, + g_simple_async_result_set_error (result, + WOCKY_PORTER_ERROR, WOCKY_PORTER_ERROR_CLOSING, "Porter is closing: iq '%s' aborted", node); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); g_free (node); return; @@ -1688,8 +1699,6 @@ wocky_porter_send_iq_async (WockyPorter *self, wocky_node_set_attribute (wocky_stanza_get_top_node (stanza), "id", id); - result = g_simple_async_result_new (G_OBJECT (self), - callback, user_data, wocky_porter_send_iq_finish); handler = stanza_iq_handler_new (self, id, result, cancellable, recipient); @@ -1707,10 +1716,11 @@ wocky_porter_send_iq_async (WockyPorter *self, return; wrong_stanza: - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, WOCKY_PORTER_ERROR, - WOCKY_PORTER_ERROR_NOT_IQ, + g_simple_async_result_set_error (result, + WOCKY_PORTER_ERROR, WOCKY_PORTER_ERROR_NOT_IQ, "Stanza is not an IQ query"); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); } /** @@ -1766,38 +1776,37 @@ wocky_porter_force_close_async (WockyPorter *self, { WockyPorterPrivate *priv = self->priv; sending_queue_elem *elem; + GSimpleAsyncResult *result; GError err = { WOCKY_PORTER_ERROR, WOCKY_PORTER_ERROR_FORCIBLY_CLOSED, "Porter was closed forcibly" }; + result = g_simple_async_result_new (G_OBJECT (self), + callback, user_data, wocky_porter_force_close_finish); + if (priv->force_close_result != NULL) { - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, G_IO_ERROR, G_IO_ERROR_PENDING, + g_simple_async_result_set_error (result, + G_IO_ERROR, G_IO_ERROR_PENDING, "Another force close operation is pending"); - return; + goto error; } if (priv->receive_cancellable == NULL && priv->local_closed) { - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, WOCKY_PORTER_ERROR, - WOCKY_PORTER_ERROR_CLOSED, + g_simple_async_result_set_error (result, + WOCKY_PORTER_ERROR, WOCKY_PORTER_ERROR_CLOSED, "Porter has already been closed"); - return; + goto error; } if (priv->receive_cancellable == NULL && !priv->remote_closed) { - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, WOCKY_PORTER_ERROR, - WOCKY_PORTER_ERROR_NOT_STARTED, + g_simple_async_result_set_error (result, + WOCKY_PORTER_ERROR, WOCKY_PORTER_ERROR_NOT_STARTED, "Porter has not been started"); - return; + goto error; } - /* Ensure to keep us alive during the closing */ - g_object_ref (self); - if (priv->close_result != NULL) { /* Finish pending close operation */ @@ -1813,13 +1822,9 @@ wocky_porter_force_close_async (WockyPorter *self, g_signal_emit (self, signals[CLOSING], 0); } - priv->force_close_result = g_simple_async_result_new (G_OBJECT (self), - callback, user_data, wocky_porter_force_close_finish); priv->force_close_cancellable = cancellable; + priv->force_close_result = result; - /* force_close_result now keeps a ref on ourself so we can release the ref - * without risking to destroy the object */ - g_object_unref (self); /* Terminate all the pending sending operations */ elem = g_queue_pop_head (priv->sending_queue); @@ -1839,12 +1844,12 @@ wocky_porter_force_close_async (WockyPorter *self, /* forced shutdown in progress. noop */ if (priv->forced_shutdown) { - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, WOCKY_PORTER_ERROR, - WOCKY_PORTER_ERROR_FORCIBLY_CLOSED, + g_simple_async_result_set_error (result, + WOCKY_PORTER_ERROR, WOCKY_PORTER_ERROR_FORCIBLY_CLOSED, "Porter is already executing a forced-shutdown"); - return; + goto error; } + /* No need to wait, close connection right now */ DEBUG ("remote is already closed, close the XMPP connection"); g_object_ref (self); @@ -1860,6 +1865,15 @@ wocky_porter_force_close_async (WockyPorter *self, */ g_cancellable_cancel (priv->receive_cancellable); + return; + +error: + if (priv->force_close_cancellable != NULL) + g_object_unref (priv->force_close_cancellable); + priv->force_close_result = NULL; + priv->force_close_cancellable = NULL; + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); } /** diff --git a/wocky/wocky-roster.c b/wocky/wocky-roster.c index 8ff82b7..02543f7 100644 --- a/wocky/wocky-roster.c +++ b/wocky/wocky-roster.c @@ -705,16 +705,22 @@ wocky_roster_fetch_roster_async (WockyRoster *self, { WockyRosterPrivate *priv; WockyStanza *iq; + GSimpleAsyncResult *result; g_return_if_fail (WOCKY_IS_ROSTER (self)); priv = self->priv; + result = g_simple_async_result_new (G_OBJECT (self), + callback, user_data, wocky_roster_fetch_roster_finish); + if (priv->fetch_result != NULL) { - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, G_IO_ERROR, G_IO_ERROR_PENDING, + g_simple_async_result_set_error (result, + G_IO_ERROR, G_IO_ERROR_PENDING, "Another fetch operation is pending"); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); return; } @@ -725,8 +731,7 @@ wocky_roster_fetch_roster_async (WockyRoster *self, ')', NULL); - priv->fetch_result = g_simple_async_result_new (G_OBJECT (self), - callback, user_data, wocky_roster_fetch_roster_finish); + priv->fetch_result = result; wocky_porter_send_iq_async (priv->porter, iq, cancellable, roster_fetch_roster_cb, self); @@ -1255,9 +1260,10 @@ wocky_roster_change_contact_name_async (WockyRoster *self, if (!contact_in_roster (self, contact)) { - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, WOCKY_ROSTER_ERROR, WOCKY_ROSTER_ERROR_NOT_IN_ROSTER, + g_simple_async_result_set_error (result, + WOCKY_ROSTER_ERROR, WOCKY_ROSTER_ERROR_NOT_IN_ROSTER, "Contact %s is not in the roster", wocky_bare_contact_get_jid (contact)); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); return; } @@ -1332,9 +1338,10 @@ wocky_roster_contact_add_group_async (WockyRoster *self, if (!contact_in_roster (self, contact)) { - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, WOCKY_ROSTER_ERROR, WOCKY_ROSTER_ERROR_NOT_IN_ROSTER, + g_simple_async_result_set_error (result, + WOCKY_ROSTER_ERROR, WOCKY_ROSTER_ERROR_NOT_IN_ROSTER, "Contact %s is not in the roster", jid); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); return; } @@ -1412,9 +1419,10 @@ wocky_roster_contact_remove_group_async (WockyRoster *self, if (!contact_in_roster (self, contact)) { - g_simple_async_report_error_in_idle (G_OBJECT (self), callback, - user_data, WOCKY_ROSTER_ERROR, WOCKY_ROSTER_ERROR_NOT_IN_ROSTER, + g_simple_async_result_set_error (result, + WOCKY_ROSTER_ERROR, WOCKY_ROSTER_ERROR_NOT_IN_ROSTER, "Contact %s is not in the roster", jid); + g_simple_async_result_complete_in_idle (result); g_object_unref (result); return; } diff --git a/wocky/wocky-sasl-auth.c b/wocky/wocky-sasl-auth.c index ff3500a..a61f51b 100644 --- a/wocky/wocky-sasl-auth.c +++ b/wocky/wocky-sasl-auth.c @@ -672,6 +672,7 @@ wocky_sasl_auth_authenticate_async (WockySaslAuth *sasl, { WockySaslAuthPrivate *priv = sasl->priv; WockyNode *mech_node; + GSimpleAsyncResult *result; GSList *mechanisms, *t; g_assert (sasl != NULL); @@ -683,17 +684,20 @@ wocky_sasl_auth_authenticate_async (WockySaslAuth *sasl, mechanisms = wocky_sasl_auth_mechanisms_to_list (mech_node); + result = g_simple_async_result_new (G_OBJECT (sasl), + callback, user_data, wocky_sasl_auth_authenticate_finish); + if (G_UNLIKELY (mechanisms == NULL)) { - g_simple_async_report_error_in_idle (G_OBJECT (sasl), - callback, user_data, + g_simple_async_result_set_error (result, WOCKY_AUTH_ERROR, WOCKY_AUTH_ERROR_NOT_SUPPORTED, "Server doesn't have any sasl mechanisms"); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); goto out; } - priv->result = g_simple_async_result_new (G_OBJECT (sasl), - callback, user_data, wocky_sasl_auth_authenticate_finish); + priv->result = result; if (cancellable != NULL) priv->cancel = g_object_ref (cancellable); diff --git a/wocky/wocky-xmpp-connection.c b/wocky/wocky-xmpp-connection.c index 88a04a7..fee0af1 100644 --- a/wocky/wocky-xmpp-connection.c +++ b/wocky/wocky-xmpp-connection.c @@ -358,25 +358,43 @@ wocky_xmpp_connection_send_open_async (WockyXmppConnection *connection, GAsyncReadyCallback callback, gpointer user_data) { + GSimpleAsyncResult *result; WockyXmppConnectionPrivate *priv = connection->priv; + result = g_simple_async_result_new (G_OBJECT (connection), + callback, user_data, wocky_xmpp_connection_send_open_finish); + if (G_UNLIKELY (priv->output_result != NULL)) - goto pending; + { + g_simple_async_result_set_error (result, + G_IO_ERROR, G_IO_ERROR_PENDING, + "Another send operation is pending"); + goto error; + } if (G_UNLIKELY (priv->output_closed)) - goto is_closed; + { + g_simple_async_result_set_error (result, + WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_IS_CLOSED, + "Connection is closed for sending"); + goto error; + } if (G_UNLIKELY (priv->output_open)) - goto is_open; + { + g_simple_async_result_set_error (result, + WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_IS_OPEN, + "Connection is already open"); + goto error; + } g_assert (priv->output_result == NULL); g_assert (priv->output_cancellable == NULL); - priv->output_result = g_simple_async_result_new (G_OBJECT (connection), - callback, user_data, wocky_xmpp_connection_send_open_finish); priv->output_cancellable = cancellable; + priv->output_result = result; priv->offset = 0; priv->length = 0; @@ -387,25 +405,9 @@ wocky_xmpp_connection_send_open_async (WockyXmppConnection *connection, return; -pending: - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, - G_IO_ERROR, G_IO_ERROR_PENDING, "Another send operation is pending"); - return; - -is_open: - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, - WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_IS_OPEN, - "Connection is already open"); - return; - -is_closed: - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, - WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_IS_CLOSED, - "Connection is closed for sending"); - return; +error: + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); } /** @@ -549,23 +551,41 @@ wocky_xmpp_connection_recv_open_async (WockyXmppConnection *connection, GAsyncReadyCallback callback, gpointer user_data) { + GSimpleAsyncResult *result; WockyXmppConnectionPrivate *priv = connection->priv; + result = g_simple_async_result_new (G_OBJECT (connection), + callback, user_data, wocky_xmpp_connection_recv_open_finish); + if (G_UNLIKELY (priv->input_result != NULL)) - goto pending; + { + g_simple_async_result_set_error (result, + G_IO_ERROR, G_IO_ERROR_PENDING, + "Another receive operation is pending"); + goto error; + } if (G_UNLIKELY (input_is_closed (connection))) - goto is_closed; + { + g_simple_async_result_set_error (result, + WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_IS_CLOSED, + "Connection is closed for receiving"); + goto error; + } if (G_UNLIKELY (priv->input_open)) - goto is_open; + { + g_simple_async_result_set_error (result, + WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_IS_OPEN, + "Connection has already received open"); + goto error; + } g_assert (priv->input_result == NULL); g_assert (priv->input_cancellable == NULL); - priv->input_result = g_simple_async_result_new (G_OBJECT (connection), - callback, user_data, wocky_xmpp_connection_recv_open_finish); + priv->input_result = result; priv->input_cancellable = cancellable; @@ -573,25 +593,9 @@ wocky_xmpp_connection_recv_open_async (WockyXmppConnection *connection, return; -pending: - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, - G_IO_ERROR, G_IO_ERROR_PENDING, "Another receive operation is pending"); - return; - -is_closed: - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, - WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_IS_CLOSED, - "Connection is closed for receiving"); - return; - -is_open: - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, - WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_IS_OPEN, - "Connection has already received open"); - return; +error: + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); } /** @@ -678,26 +682,44 @@ wocky_xmpp_connection_send_stanza_async (WockyXmppConnection *connection, GAsyncReadyCallback callback, gpointer user_data) { + GSimpleAsyncResult *result; WockyXmppConnectionPrivate *priv = connection->priv; + result = g_simple_async_result_new (G_OBJECT (connection), + callback, user_data, wocky_xmpp_connection_send_stanza_finish); + if (G_UNLIKELY (priv->output_result != NULL)) - goto pending; + { + g_simple_async_result_set_error (result, + G_IO_ERROR, G_IO_ERROR_PENDING, + "Another send operation is pending"); + goto error; + } if (G_UNLIKELY (!priv->output_open)) - goto not_open; + { + g_simple_async_result_set_error (result, + WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_NOT_OPEN, + "Connections hasn't been opened for sending"); + goto error; + } if (G_UNLIKELY (priv->output_closed)) - goto is_closed; + { + g_simple_async_result_set_error (result, + WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_IS_CLOSED, + "Connections has been closed for sending"); + goto error; + } g_assert (!priv->output_closed); g_assert (priv->output_result == NULL); g_assert (priv->output_cancellable == NULL); - priv->output_result = g_simple_async_result_new (G_OBJECT (connection), - callback, user_data, wocky_xmpp_connection_send_stanza_finish); priv->output_cancellable = cancellable; + priv->output_result = result; priv->offset = 0; priv->length = 0; @@ -708,25 +730,9 @@ wocky_xmpp_connection_send_stanza_async (WockyXmppConnection *connection, return; -pending: - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, - G_IO_ERROR, G_IO_ERROR_PENDING, "Another send operation is pending"); - return; - -not_open: - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, - WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_NOT_OPEN, - "Connections hasn't been opened for sending"); - return; - -is_closed: - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, - WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_IS_CLOSED, - "Connections has been closed for sending"); - return; +error: + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); } /** @@ -777,60 +783,58 @@ wocky_xmpp_connection_recv_stanza_async (WockyXmppConnection *connection, GAsyncReadyCallback callback, gpointer user_data) { + GSimpleAsyncResult *result; WockyXmppConnectionPrivate *priv = connection->priv; + result = g_simple_async_result_new (G_OBJECT (connection), + callback, user_data, wocky_xmpp_connection_recv_stanza_finish); + if (G_UNLIKELY (priv->input_result != NULL)) - goto pending; + { + g_simple_async_result_set_error (result, + G_IO_ERROR, G_IO_ERROR_PENDING, + "Another receive operation is pending"); + goto error; + } if (G_UNLIKELY (!priv->input_open)) - goto not_open; + { + g_simple_async_result_set_error (result, + WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_NOT_OPEN, + "Connection hasn't been opened for reading stanzas"); + goto error; + } if (G_UNLIKELY (input_is_closed (connection))) - goto is_closed; + { + g_simple_async_result_set_error (result, + WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_IS_CLOSED, + "Connection has been closed for reading stanzas"); + goto error; + } g_assert (priv->input_result == NULL); g_assert (priv->input_cancellable == NULL); - priv->input_result = g_simple_async_result_new (G_OBJECT (connection), - callback, user_data, wocky_xmpp_connection_recv_stanza_finish); - /* There is already a stanza waiting, no need to read */ if (wocky_xmpp_reader_peek_stanza (priv->reader) != NULL) { - GSimpleAsyncResult *r = priv->input_result; - - priv->input_result = NULL; - - g_simple_async_result_complete_in_idle (r); - g_object_unref (r); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); return; } priv->input_cancellable = cancellable; + priv->input_result = result; - wocky_xmpp_connection_do_read (connection); - return; - -pending: - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, - G_IO_ERROR, G_IO_ERROR_PENDING, "Another receive operation is pending"); - return; -not_open: - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, - WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_NOT_OPEN, - "Connection hasn't been opened for reading stanzas"); + wocky_xmpp_connection_do_read (connection); return; -is_closed: - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, - WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_IS_CLOSED, - "Connection has been closed for reading stanzas"); - return; +error: + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); } /** @@ -913,25 +917,43 @@ wocky_xmpp_connection_send_close_async (WockyXmppConnection *connection, GAsyncReadyCallback callback, gpointer user_data) { + GSimpleAsyncResult *result; WockyXmppConnectionPrivate *priv = connection->priv; + result = g_simple_async_result_new (G_OBJECT (connection), + callback, user_data, wocky_xmpp_connection_send_close_finish); + if (G_UNLIKELY (priv->output_result != NULL)) - goto pending; + { + g_simple_async_result_set_error (result, + G_IO_ERROR, G_IO_ERROR_PENDING, + "Another send operation is pending"); + goto error; + } if (G_UNLIKELY (priv->output_closed)) - goto is_closed; + { + g_simple_async_result_set_error (result, + WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_IS_CLOSED, + "Connections has been closed sending"); + goto error; + } if (G_UNLIKELY (!priv->output_open)) - goto not_open; + { + g_simple_async_result_set_error (result, + WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_NOT_OPEN, + "Connections hasn't been opened for sending"); + goto error; + } g_assert (priv->output_result == NULL); g_assert (priv->output_cancellable == NULL); - priv->output_result = g_simple_async_result_new (G_OBJECT (connection), - callback, user_data, wocky_xmpp_connection_send_close_finish); priv->output_cancellable = cancellable; + priv->output_result = result; priv->offset = 0; priv->length = 0; @@ -942,25 +964,9 @@ wocky_xmpp_connection_send_close_async (WockyXmppConnection *connection, return; -pending: - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, - G_IO_ERROR, G_IO_ERROR_PENDING, "Another send operation is pending"); - return; - -not_open: - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, - WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_NOT_OPEN, - "Connections hasn't been opened for sending"); - return; - -is_closed: - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, - WOCKY_XMPP_CONNECTION_ERROR, WOCKY_XMPP_CONNECTION_ERROR_IS_CLOSED, - "Connections has been closed sending"); - return; +error: + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); } /** @@ -1068,19 +1074,23 @@ wocky_xmpp_connection_force_close_async (WockyXmppConnection *connection, GAsyncReadyCallback callback, gpointer user_data) { + GSimpleAsyncResult *result; WockyXmppConnectionPrivate *priv = connection->priv; + result = g_simple_async_result_new (G_OBJECT (connection), + callback, user_data, wocky_xmpp_connection_force_close_finish); + if (G_UNLIKELY (priv->force_close_result != NULL)) { - g_simple_async_report_error_in_idle (G_OBJECT (connection), - callback, user_data, + g_simple_async_result_set_error (result, G_IO_ERROR, G_IO_ERROR_PENDING, "Another close operation is pending"); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); return; } - priv->force_close_result = g_simple_async_result_new (G_OBJECT (connection), - callback, user_data, wocky_xmpp_connection_force_close_finish); + priv->force_close_result = result; g_io_stream_close_async (priv->stream, G_PRIORITY_HIGH, cancellable, stream_close_cb, connection); -- 1.7.2.3