summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2009-05-15 08:20:51 (GMT)
committerAlexander Larsson <alexl@redhat.com>2009-05-15 08:20:51 (GMT)
commit661d5f1f2d808153059bfec7935a39fe26766cd5 (patch)
tree0cabf341cb98a13912bf584790582877ecc1457b
parentb7857e934f32fe3599957d49c2aacda728dfcc75 (diff)
downloadgnio-661d5f1f2d808153059bfec7935a39fe26766cd5.tar.gz
gnio-661d5f1f2d808153059bfec7935a39fe26766cd5.tar.xz
Fix error handling in g_socket_client_connect
We want to report the error from last connect try if the g_socket_address_enumerator_next call returns no more adresses to try.
-rw-r--r--gio/gsocketclient.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/gio/gsocketclient.c b/gio/gsocketclient.c
index 3fefd90..4d1fabb 100644
--- a/gio/gsocketclient.c
+++ b/gio/gsocketclient.c
@@ -244,7 +244,9 @@ g_socket_client_connect (GSocketClient *client,
{
GSocketConnection *connection = NULL;
GSocketAddressEnumerator *enumerator;
+ GError *last_error, *tmp_error;
+ last_error = NULL;
enumerator = g_socket_connectable_enumerate (connectable);
while (connection == NULL)
{
@@ -258,22 +260,33 @@ g_socket_client_connect (GSocketClient *client,
break;
}
- address =
- g_socket_address_enumerator_next (enumerator, cancellable, error);
-
+ tmp_error = NULL;
+ address = g_socket_address_enumerator_next (enumerator, cancellable,
+ &tmp_error);
if (address == NULL)
- {
- g_assert (error == NULL || *error != NULL);
+ {
+ if (tmp_error)
+ {
+ g_clear_error (&last_error);
+ g_propagate_error (error, tmp_error);
+ }
+ else if (last_error)
+ {
+ g_propagate_error (error, tmp_error);
+ }
+ else
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ _("Unknown error on connect"));
break;
- }
+ }
/* clear error from previous attempt */
- g_clear_error (error);
+ g_clear_error (&last_error);
- socket = create_socket (client, address, error);
+ socket = create_socket (client, address, &last_error);
if (socket != NULL)
{
- if (g_socket_connect (socket, address, error))
+ if (g_socket_connect (socket, address, &last_error))
connection = g_socket_connection_factory_create_connection (socket);
g_object_unref (socket);