mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 23:16:14 +01:00
gio: Make enumerating a GNetworkAddress work more than once
Previously, the code only initialized the enumerator if the address hadn't had cached addresses. But creating an enumerator cached the addresses, so the second one failed to work.
This commit is contained in:
parent
07fd29c323
commit
bd227f5219
@ -781,7 +781,8 @@ typedef struct {
|
||||
GSocketAddressEnumerator parent_instance;
|
||||
|
||||
GNetworkAddress *addr;
|
||||
GList *a;
|
||||
GList *addresses;
|
||||
GList *next;
|
||||
} GNetworkAddressAddressEnumerator;
|
||||
|
||||
typedef struct {
|
||||
@ -811,6 +812,8 @@ g_network_address_address_enumerator_next (GSocketAddressEnumerator *enumerator
|
||||
G_NETWORK_ADDRESS_ADDRESS_ENUMERATOR (enumerator);
|
||||
GSocketAddress *sockaddr;
|
||||
|
||||
if (addr_enum->addresses == NULL)
|
||||
{
|
||||
if (!addr_enum->addr->priv->sockaddrs)
|
||||
{
|
||||
GResolver *resolver = g_resolver_get_default ();
|
||||
@ -825,17 +828,18 @@ g_network_address_address_enumerator_next (GSocketAddressEnumerator *enumerator
|
||||
return NULL;
|
||||
|
||||
g_network_address_set_addresses (addr_enum->addr, addresses);
|
||||
addr_enum->a = addr_enum->addr->priv->sockaddrs;
|
||||
}
|
||||
|
||||
if (!addr_enum->a)
|
||||
return NULL;
|
||||
else
|
||||
{
|
||||
sockaddr = addr_enum->a->data;
|
||||
addr_enum->a = addr_enum->a->next;
|
||||
return g_object_ref (sockaddr);
|
||||
addr_enum->addresses = addr_enum->addr->priv->sockaddrs;
|
||||
addr_enum->next = addr_enum->addresses;
|
||||
}
|
||||
|
||||
if (addr_enum->next == NULL)
|
||||
return NULL;
|
||||
|
||||
sockaddr = addr_enum->next->data;
|
||||
addr_enum->next = addr_enum->next->next;
|
||||
return g_object_ref (sockaddr);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -850,24 +854,21 @@ got_addresses (GObject *source_object,
|
||||
GList *addresses;
|
||||
GError *error = NULL;
|
||||
|
||||
addresses = g_resolver_lookup_by_name_finish (resolver, result, &error);
|
||||
if (!addr_enum->addr->priv->sockaddrs)
|
||||
{
|
||||
addresses = g_resolver_lookup_by_name_finish (resolver, result, &error);
|
||||
|
||||
if (error)
|
||||
{
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_network_address_set_addresses (addr_enum->addr, addresses);
|
||||
addr_enum->a = addr_enum->addr->priv->sockaddrs;
|
||||
}
|
||||
}
|
||||
else if (error)
|
||||
g_error_free (error);
|
||||
|
||||
g_object_unref (resolver);
|
||||
|
||||
addr_enum->addresses = addr_enum->addr->priv->sockaddrs;
|
||||
addr_enum->next = addr_enum->addresses;
|
||||
|
||||
g_simple_async_result_complete (simple);
|
||||
g_object_unref (simple);
|
||||
}
|
||||
@ -886,6 +887,8 @@ g_network_address_address_enumerator_next_async (GSocketAddressEnumerator *enum
|
||||
callback, user_data,
|
||||
g_network_address_address_enumerator_next_async);
|
||||
|
||||
if (addr_enum->addresses == NULL)
|
||||
{
|
||||
if (!addr_enum->addr->priv->sockaddrs)
|
||||
{
|
||||
GResolver *resolver = g_resolver_get_default ();
|
||||
@ -895,12 +898,15 @@ g_network_address_address_enumerator_next_async (GSocketAddressEnumerator *enum
|
||||
addr_enum->addr->priv->hostname,
|
||||
cancellable,
|
||||
got_addresses, simple);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
addr_enum->addresses = addr_enum->addr->priv->sockaddrs;
|
||||
addr_enum->next = addr_enum->addresses;
|
||||
}
|
||||
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
}
|
||||
}
|
||||
|
||||
static GSocketAddress *
|
||||
@ -915,12 +921,12 @@ g_network_address_address_enumerator_next_finish (GSocketAddressEnumerator *enu
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
else if (!addr_enum->a)
|
||||
else if (!addr_enum->next)
|
||||
return NULL;
|
||||
else
|
||||
{
|
||||
sockaddr = addr_enum->a->data;
|
||||
addr_enum->a = addr_enum->a->next;
|
||||
sockaddr = addr_enum->next->data;
|
||||
addr_enum->next = addr_enum->next->next;
|
||||
return g_object_ref (sockaddr);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user