From d208ffca52be5d0a0e585db8ea6d592ce84edfaa Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 6 Apr 2011 10:32:58 +0100 Subject: meta-porter: clean up porter closing callbacks They all share more code now, the signal handler disconnection is in its own function and the porter timeouts are no longer removed. Signed-off-by: Jonny Lamb --- wocky/wocky-meta-porter.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/wocky/wocky-meta-porter.c b/wocky/wocky-meta-porter.c index 5eff152..1b5b6f9 100644 --- a/wocky/wocky-meta-porter.c +++ b/wocky/wocky-meta-porter.c @@ -179,50 +179,48 @@ porter_timeout_cb (gpointer d) return FALSE; } +static void porter_closing_cb (WockyPorter *porter, PorterData *data); static void porter_remote_closed_cb (WockyPorter *porter, PorterData *data); +static void porter_remote_error_cb (WockyPorter *porter, GQuark domain, + gint code, const gchar *msg, PorterData *data); static void -porter_closing_cb (WockyPorter *porter, +disconnect_porter_signal_handlers (WockyPorter *porter, PorterData *data) { - DEBUG ("porter to '%s' closing, remove it from our records", data->jid); - - if (data->timeout_id > 0) - g_source_remove (data->timeout_id); - - data->timeout_id = 0; - g_signal_handlers_disconnect_by_func (porter, porter_remote_closed_cb, data); g_signal_handlers_disconnect_by_func (porter, porter_closing_cb, data); - - if (data->porter != NULL) - g_object_unref (data->porter); - data->porter = NULL; + g_signal_handlers_disconnect_by_func (porter, + porter_remote_error_cb, data); } static void -porter_remote_closed_cb (WockyPorter *porter, +porter_closing_cb (WockyPorter *porter, PorterData *data) { - DEBUG ("porter closed by remote, remove it from our records"); - - if (data->timeout_id > 0) - g_source_remove (data->timeout_id); + DEBUG ("porter to '%s' closing, remove it from our records", data->jid); - data->timeout_id = 0; + /* Don't stop the porter timeout here because that means if a + * connection is never opened to the contact again the PorterData + * struct will stick around until the meta porter is disposed. */ - g_signal_handlers_disconnect_by_func (porter, - porter_remote_closed_cb, data); - g_signal_handlers_disconnect_by_func (porter, - porter_closing_cb, data); + disconnect_porter_signal_handlers (porter, data); if (data->porter != NULL) g_object_unref (data->porter); data->porter = NULL; } +static void +porter_remote_closed_cb (WockyPorter *porter, + PorterData *data) +{ + DEBUG ("porter closed by remote, remove it from our records"); + porter_closing_cb (porter, data); +} + static void porter_remote_error_cb (WockyPorter *porter, GQuark domain, @@ -230,8 +228,9 @@ porter_remote_error_cb (WockyPorter *porter, const gchar *msg, PorterData *data) { + DEBUG ("remote error in porter, close it"); wocky_porter_force_close_async (porter, NULL, NULL, NULL); - porter_remote_closed_cb (porter, data); + porter_closing_cb (porter, data); } static void -- cgit v1.2.3