diff options
author | Hyunjee Kim <hj0426.kim@samsung.com> | 2019-12-03 10:57:58 +0900 |
---|---|---|
committer | Hyunjee Kim <hj0426.kim@samsung.com> | 2019-12-03 10:57:58 +0900 |
commit | 68bf5c4184c2899c4b0594930c7112d88f15e199 (patch) | |
tree | e37e1ab4b65798014596f9778bd2b2a73642e64c /gio | |
parent | d5a1e991c0c65ccab2b0cb9b8b9320ee3b2ea8e5 (diff) | |
download | glib-68bf5c4184c2899c4b0594930c7112d88f15e199.tar.gz glib-68bf5c4184c2899c4b0594930c7112d88f15e199.tar.bz2 glib-68bf5c4184c2899c4b0594930c7112d88f15e199.zip |
Imported Upstream version 2.61.1
Diffstat (limited to 'gio')
-rw-r--r-- | gio/.gitignore | 20 | ||||
-rw-r--r-- | gio/gappinfo.c | 9 | ||||
-rw-r--r-- | gio/gapplication.c | 22 | ||||
-rw-r--r-- | gio/gcocoanotificationbackend.m | 1 | ||||
-rw-r--r-- | gio/gdbusobjectmanager.c | 6 | ||||
-rw-r--r-- | gio/gdbusserver.c | 3 | ||||
-rw-r--r-- | gio/gdesktopappinfo.c | 4 | ||||
-rw-r--r-- | gio/gfileattribute.c | 2 | ||||
-rw-r--r-- | gio/gioenums.h | 34 | ||||
-rw-r--r-- | gio/gnetworkaddress.c | 236 | ||||
-rw-r--r-- | gio/gnetworkmonitornm.c | 39 | ||||
-rw-r--r-- | gio/gproxy.c | 4 | ||||
-rw-r--r-- | gio/gresolver.c | 8 | ||||
-rw-r--r-- | gio/gschema.dtd | 3 | ||||
-rw-r--r-- | gio/gsettings-mapping.c | 2 | ||||
-rw-r--r-- | gio/gsocket.c | 17 | ||||
-rw-r--r-- | gio/gsocketclient.c | 22 | ||||
-rw-r--r-- | gio/gtask.c | 10 | ||||
-rw-r--r-- | gio/gtlsdatabase.c | 14 | ||||
-rw-r--r-- | gio/gvfs.h | 2 | ||||
-rw-r--r-- | gio/meson.build | 6 | ||||
-rw-r--r-- | gio/strinfo.c | 18 | ||||
-rw-r--r-- | gio/tests/desktop-app-info.c | 2 | ||||
-rw-r--r-- | gio/tests/gapplication.c | 6 | ||||
-rw-r--r-- | gio/tests/meson.build | 8 | ||||
-rw-r--r-- | gio/tests/monitor.c | 220 | ||||
-rw-r--r-- | gio/tests/network-address.c | 63 | ||||
-rw-r--r-- | gio/tests/resolver.c | 4 | ||||
-rw-r--r-- | gio/tests/socket-client.c | 2 | ||||
-rw-r--r-- | gio/tests/socket-server.c | 2 |
30 files changed, 376 insertions, 413 deletions
diff --git a/gio/.gitignore b/gio/.gitignore deleted file mode 100644 index e88411eff..000000000 --- a/gio/.gitignore +++ /dev/null @@ -1,20 +0,0 @@ -gapplication -gconstructor_as_data.h -gdbus -objectmanager-gen-org.gtk.GDBus.Example.ObjectManager.Animal.xml -objectmanager-gen-org.gtk.GDBus.Example.ObjectManager.Cat.xml -objectmanager-gen.[ch] -gdbus-daemon-generated.[ch] -gio -gio_probes.h -gio-marshal.[ch] -gio-public-headers.txt -gio-querymodules -gioenumtypes.[ch] -glib-compile-resources -glib-compile-schemas -gnetworking.h -gresource -gschema-compile -gsettings -xdp-dbus.[ch] diff --git a/gio/gappinfo.c b/gio/gappinfo.c index 1fd0a7ad7..b2135e644 100644 --- a/gio/gappinfo.c +++ b/gio/gappinfo.c @@ -1204,6 +1204,10 @@ g_app_launch_context_setenv (GAppLaunchContext *context, const char *variable, const char *value) { + g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context)); + g_return_if_fail (variable != NULL); + g_return_if_fail (value != NULL); + if (!context->priv->envp) context->priv->envp = g_get_environ (); @@ -1225,6 +1229,9 @@ void g_app_launch_context_unsetenv (GAppLaunchContext *context, const char *variable) { + g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context)); + g_return_if_fail (variable != NULL); + if (!context->priv->envp) context->priv->envp = g_get_environ (); @@ -1249,6 +1256,8 @@ g_app_launch_context_unsetenv (GAppLaunchContext *context, char ** g_app_launch_context_get_environment (GAppLaunchContext *context) { + g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL); + if (!context->priv->envp) context->priv->envp = g_get_environ (); diff --git a/gio/gapplication.c b/gio/gapplication.c index 2d2ab48e3..b154cbe6a 100644 --- a/gio/gapplication.c +++ b/gio/gapplication.c @@ -2458,6 +2458,28 @@ g_application_run (GApplication *application, sizeof (arguments[0]) * (argc + 1)); } } +#elif defined(__APPLE__) + { + gint i, j; + + /* + * OSX adds an unexpected parameter on the format -psn_X_XXXXXX + * when opening the application using Launch Services. In order + * to avoid that GOption fails to parse this parameter we just + * skip it if it was provided. + * See: https://gitlab.gnome.org/GNOME/glib/issues/1784 + */ + arguments = g_new (gchar *, argc + 1); + for (i = 0, j = 0; i < argc; i++) + { + if (!g_str_has_prefix (argv[i], "-psn_")) + { + arguments[j] = g_strdup (argv[i]); + j++; + } + } + arguments[j] = NULL; + } #else { gint i; diff --git a/gio/gcocoanotificationbackend.m b/gio/gcocoanotificationbackend.m index 9d632b4a5..42cf8abcf 100644 --- a/gio/gcocoanotificationbackend.m +++ b/gio/gcocoanotificationbackend.m @@ -258,7 +258,6 @@ g_cocoa_notification_backend_withdraw_notification (GNotificationBackend *backen } } - [notifications release]; [str_id release]; } diff --git a/gio/gdbusobjectmanager.c b/gio/gdbusobjectmanager.c index 0eaec3f8c..3ef622a33 100644 --- a/gio/gdbusobjectmanager.c +++ b/gio/gdbusobjectmanager.c @@ -188,7 +188,7 @@ g_dbus_object_manager_get_objects (GDBusObjectManager *manager) /** * g_dbus_object_manager_get_object: * @manager: A #GDBusObjectManager. - * @object_path: Object path to lookup. + * @object_path: Object path to look up. * * Gets the #GDBusObjectProxy at @object_path, if any. * @@ -209,8 +209,8 @@ g_dbus_object_manager_get_object (GDBusObjectManager *manager, /** * g_dbus_object_manager_get_interface: * @manager: A #GDBusObjectManager. - * @object_path: Object path to lookup. - * @interface_name: D-Bus interface name to lookup. + * @object_path: Object path to look up. + * @interface_name: D-Bus interface name to look up. * * Gets the interface proxy for @interface_name at @object_path, if * any. diff --git a/gio/gdbusserver.c b/gio/gdbusserver.c index 07757f40f..026d4ee6b 100644 --- a/gio/gdbusserver.c +++ b/gio/gdbusserver.c @@ -608,8 +608,7 @@ g_dbus_server_stop (GDBusServer *server) /* Right now we don't have any transport not using the listener... */ g_assert (server->is_using_listener); g_assert (server->run_signal_handler_id > 0); - g_signal_handler_disconnect (server->listener, server->run_signal_handler_id); - server->run_signal_handler_id = 0; + g_clear_signal_handler (&server->run_signal_handler_id, server->listener); g_socket_service_stop (G_SOCKET_SERVICE (server->listener)); server->active = FALSE; g_object_notify (G_OBJECT (server), "active"); diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c index 238141158..77e385aa5 100644 --- a/gio/gdesktopappinfo.c +++ b/gio/gdesktopappinfo.c @@ -2514,6 +2514,10 @@ prepend_terminal_to_vector (int *argc, term_argv = g_new0 (char *, 3); check = g_find_program_in_path ("gnome-terminal"); + if (check == NULL) + check = g_find_program_in_path ("mate-terminal"); + if (check == NULL) + check = g_find_program_in_path ("xfce4-terminal"); if (check != NULL) { term_argv[0] = check; diff --git a/gio/gfileattribute.c b/gio/gfileattribute.c index c3a8ebf4b..0e4bfc28f 100644 --- a/gio/gfileattribute.c +++ b/gio/gfileattribute.c @@ -917,7 +917,7 @@ g_file_attribute_info_list_bsearch (GFileAttributeInfoList *list, /** * g_file_attribute_info_list_lookup: * @list: a #GFileAttributeInfoList. - * @name: the name of the attribute to lookup. + * @name: the name of the attribute to look up. * * Gets the file attribute with the name @name from @list. * diff --git a/gio/gioenums.h b/gio/gioenums.h index 2fc69b6be..d3ada454a 100644 --- a/gio/gioenums.h +++ b/gio/gioenums.h @@ -715,11 +715,11 @@ typedef enum { /** * GResolverRecordType: - * @G_RESOLVER_RECORD_SRV: lookup DNS SRV records for a domain - * @G_RESOLVER_RECORD_MX: lookup DNS MX records for a domain - * @G_RESOLVER_RECORD_TXT: lookup DNS TXT records for a name - * @G_RESOLVER_RECORD_SOA: lookup DNS SOA records for a zone - * @G_RESOLVER_RECORD_NS: lookup DNS NS records for a domain + * @G_RESOLVER_RECORD_SRV: look up DNS SRV records for a domain + * @G_RESOLVER_RECORD_MX: look up DNS MX records for a domain + * @G_RESOLVER_RECORD_TXT: look up DNS TXT records for a name + * @G_RESOLVER_RECORD_SOA: look up DNS SOA records for a zone + * @G_RESOLVER_RECORD_NS: look up DNS NS records for a domain * * The type of record that g_resolver_lookup_records() or * g_resolver_lookup_records_async() should retrieve. The records are returned @@ -727,24 +727,30 @@ typedef enum { * the variant tuples returned. * * %G_RESOLVER_RECORD_SRV records are returned as variants with the signature - * '(qqqs)', containing a guint16 with the priority, a guint16 with the - * weight, a guint16 with the port, and a string of the hostname. + * `(qqqs)`, containing a `guint16` with the priority, a `guint16` with the + * weight, a `guint16` with the port, and a string of the hostname. * * %G_RESOLVER_RECORD_MX records are returned as variants with the signature - * '(qs)', representing a guint16 with the preference, and a string containing + * `(qs)`, representing a `guint16` with the preference, and a string containing * the mail exchanger hostname. * * %G_RESOLVER_RECORD_TXT records are returned as variants with the signature - * '(as)', representing an array of the strings in the text record. + * `(as)`, representing an array of the strings in the text record. Note: Most TXT + * records only contain a single string, but + * [RFC 1035](https://tools.ietf.org/html/rfc1035#section-3.3.14) does allow a + * record to contain multiple strings. The RFC which defines the interpretation + * of a specific TXT record will likely require concatenation of multiple + * strings if they are present, as with + * [RFC 7208](https://tools.ietf.org/html/rfc7208#section-3.3). * * %G_RESOLVER_RECORD_SOA records are returned as variants with the signature - * '(ssuuuuu)', representing a string containing the primary name server, a - * string containing the administrator, the serial as a guint32, the refresh - * interval as guint32, the retry interval as a guint32, the expire timeout - * as a guint32, and the ttl as a guint32. + * `(ssuuuuu)`, representing a string containing the primary name server, a + * string containing the administrator, the serial as a `guint32`, the refresh + * interval as a `guint32`, the retry interval as a `guint32`, the expire timeout + * as a `guint32`, and the TTL as a `guint32`. * * %G_RESOLVER_RECORD_NS records are returned as variants with the signature - * '(s)', representing a string of the hostname of the name server. + * `(s)`, representing a string of the hostname of the name server. * * Since: 2.34 */ diff --git a/gio/gnetworkaddress.c b/gio/gnetworkaddress.c index df1bc3158..4d8d74bd4 100644 --- a/gio/gnetworkaddress.c +++ b/gio/gnetworkaddress.c @@ -52,6 +52,10 @@ * then attempt to connect to that host, handling the possibility of * multiple IP addresses and multiple address families. * + * The enumeration results of resolved addresses *may* be cached as long + * as this object is kept alive which may have unexpected results if + * alive for too long. + * * See #GSocketConnectable for an example of using the connectable * interface. */ @@ -66,7 +70,7 @@ struct _GNetworkAddressPrivate { gchar *hostname; guint16 port; - GList *sockaddrs; + GList *cached_sockaddrs; gchar *scheme; gint64 resolver_serial; @@ -105,7 +109,7 @@ g_network_address_finalize (GObject *object) g_free (addr->priv->hostname); g_free (addr->priv->scheme); - g_list_free_full (addr->priv->sockaddrs, g_object_unref); + g_list_free_full (addr->priv->cached_sockaddrs, g_object_unref); G_OBJECT_CLASS (g_network_address_parent_class)->finalize (object); } @@ -220,30 +224,51 @@ g_network_address_get_property (GObject *object, } -/* - * g_network_address_add_addresses: - * @addr: A #GNetworkAddress - * @addresses: (transfer full): List of #GSocketAddress - * @resolver_serial: Serial of #GResolver used +/** + * inet_addresses_to_inet_socket_addresses: + * @addresses: (transfer full): #GList of #GInetAddress * - * Consumes address list and adds them to internal list. + * Returns: (transfer full): #GList of #GInetSocketAddress */ -static void -g_network_address_add_addresses (GNetworkAddress *addr, - GList *addresses, - guint64 resolver_serial) +static GList * +inet_addresses_to_inet_socket_addresses (GNetworkAddress *addr, + GList *addresses) { - GList *a; - GSocketAddress *sockaddr; + GList *a, *socket_addresses = NULL; for (a = addresses; a; a = a->next) { - sockaddr = g_inet_socket_address_new (a->data, addr->priv->port); - addr->priv->sockaddrs = g_list_append (addr->priv->sockaddrs, sockaddr); + GSocketAddress *sockaddr = g_inet_socket_address_new (a->data, addr->priv->port); + socket_addresses = g_list_append (socket_addresses, g_steal_pointer (&sockaddr)); g_object_unref (a->data); } + g_list_free (addresses); + return socket_addresses; +} +/* + * g_network_address_set_cached_addresses: + * @addr: A #GNetworkAddress + * @addresses: (transfer full): List of #GInetAddress or #GInetSocketAddress + * @resolver_serial: Serial of #GResolver used + * + * Consumes @addresses and uses them to replace the current internal list. + */ +static void +g_network_address_set_cached_addresses (GNetworkAddress *addr, + GList *addresses, + guint64 resolver_serial) +{ + g_assert (addresses != NULL); + + if (addr->priv->cached_sockaddrs) + g_list_free_full (addr->priv->cached_sockaddrs, g_object_unref); + + if (G_IS_INET_SOCKET_ADDRESS (addresses->data)) + addr->priv->cached_sockaddrs = g_steal_pointer (&addresses); + else + addr->priv->cached_sockaddrs = inet_addresses_to_inet_socket_addresses (addr, g_steal_pointer (&addresses)); addr->priv->resolver_serial = resolver_serial; } @@ -252,11 +277,13 @@ g_network_address_parse_sockaddr (GNetworkAddress *addr) { GSocketAddress *sockaddr; + g_assert (addr->priv->cached_sockaddrs == NULL); + sockaddr = g_inet_socket_address_new_from_string (addr->priv->hostname, addr->priv->port); if (sockaddr) { - addr->priv->sockaddrs = g_list_append (addr->priv->sockaddrs, sockaddr); + addr->priv->cached_sockaddrs = g_list_append (addr->priv->cached_sockaddrs, sockaddr); return TRUE; } else @@ -325,7 +352,7 @@ g_network_address_new_loopback (guint16 port) addrs = g_list_append (addrs, g_inet_address_new_loopback (AF_INET6)); addrs = g_list_append (addrs, g_inet_address_new_loopback (AF_INET)); - g_network_address_add_addresses (addr, g_steal_pointer (&addrs), 0); + g_network_address_set_cached_addresses (addr, g_steal_pointer (&addrs), 0); return G_SOCKET_CONNECTABLE (addr); } @@ -894,7 +921,6 @@ typedef struct { GNetworkAddress *addr; /* (owned) */ GList *addresses; /* (owned) (nullable) */ - GList *last_tail; /* (unowned) (nullable) */ GList *current_item; /* (unowned) (nullable) */ GTask *queued_task; /* (owned) (nullable) */ GTask *waiting_task; /* (owned) (nullable) */ @@ -927,8 +953,8 @@ g_network_address_address_enumerator_finalize (GObject *object) g_clear_object (&addr_enum->waiting_task); g_clear_error (&addr_enum->last_error); g_object_unref (addr_enum->addr); - g_clear_pointer (&addr_enum->addresses, g_list_free); g_clear_pointer (&addr_enum->context, g_main_context_unref); + g_list_free_full (addr_enum->addresses, g_object_unref); G_OBJECT_CLASS (_g_network_address_address_enumerator_parent_class)->finalize (object); } @@ -1014,16 +1040,19 @@ list_copy_interleaved (GList *list) } /* list_concat_interleaved: - * @current_item: (transfer container): Already existing list - * @new_list: (transfer none): New list to be interleaved and concatenated + * @parent_list: (transfer container): Already existing list + * @current_item: (transfer container): Item after which to resort + * @new_list: (transfer container): New list to be interleaved and concatenated * * This differs from g_list_concat() + list_copy_interleaved() in that it sorts - * items in the previous list starting from @current_item. + * items in the previous list starting from @current_item and concats the results + * to @parent_list. * * Returns: (transfer container): New start of list */ static GList * -list_concat_interleaved (GList *current_item, +list_concat_interleaved (GList *parent_list, + GList *current_item, GList *new_list) { GList *ipv4 = NULL, *ipv6 = NULL, *interleaved, *trailing = NULL; @@ -1040,6 +1069,7 @@ list_concat_interleaved (GList *current_item, list_split_families (trailing, &ipv4, &ipv6); list_split_families (new_list, &ipv4, &ipv6); + g_list_free (new_list); if (trailing) g_list_free (trailing); @@ -1049,7 +1079,73 @@ list_concat_interleaved (GList *current_item, else interleaved = list_interleave_families (ipv4, ipv6); - return g_list_concat (current_item, interleaved); + return g_list_concat (parent_list, interleaved); +} + +static void +maybe_update_address_cache (GNetworkAddressAddressEnumerator *addr_enum, + GResolver *resolver) +{ + GList *addresses, *p; + + /* Only cache complete results */ + if (addr_enum->state & RESOLVE_STATE_WAITING_ON_IPV4 || addr_enum->state & RESOLVE_STATE_WAITING_ON_IPV6) + return; + + /* The enumerators list will not necessarily be fully sorted */ + addresses = list_copy_interleaved (addr_enum->addresses); + for (p = addresses; p; p = p->next) + g_object_ref (p->data); + + g_network_address_set_cached_addresses (addr_enum->addr, g_steal_pointer (&addresses), g_resolver_get_serial (resolver)); +} + +static void +g_network_address_address_enumerator_add_addresses (GNetworkAddressAddressEnumerator *addr_enum, + GList *addresses, + GResolver *resolver) +{ + GList *new_addresses = inet_addresses_to_inet_socket_addresses (addr_enum->addr, addresses); + + if (addr_enum->addresses == NULL) + addr_enum->addresses = g_steal_pointer (&new_addresses); + else + addr_enum->addresses = list_concat_interleaved (addr_enum->addresses, addr_enum->current_item, g_steal_pointer (&new_addresses)); + + maybe_update_address_cache (addr_enum, resolver); +} + +static gpointer +copy_object (gconstpointer src, + gpointer user_data) +{ + return g_object_ref (G_OBJECT (src)); +} + +static GSocketAddress * +init_and_query_next_address (GNetworkAddressAddressEnumerator *addr_enum) +{ + GList *next_item; + + if (addr_enum->addresses == NULL) + addr_enum->addresses = g_list_copy_deep (addr_enum->addr->priv->cached_sockaddrs, + copy_object, NULL); + + /* We always want to look at the next item at call time to get the latest results. + That means that sometimes ->next is NULL this call but is valid next call. + */ + if (addr_enum->current_item == NULL) + next_item = addr_enum->current_item = addr_enum->addresses; + else + next_item = g_list_next (addr_enum->current_item); + + if (next_item) + { + addr_enum->current_item = next_item; + return g_object_ref (addr_enum->current_item->data); + } + else + return NULL; } static GSocketAddress * @@ -1059,7 +1155,6 @@ g_network_address_address_enumerator_next (GSocketAddressEnumerator *enumerator { GNetworkAddressAddressEnumerator *addr_enum = G_NETWORK_ADDRESS_ADDRESS_ENUMERATOR (enumerator); - GSocketAddress *sockaddr; if (addr_enum->addresses == NULL) { @@ -1071,13 +1166,13 @@ g_network_address_address_enumerator_next (GSocketAddressEnumerator *enumerator addr->priv->resolver_serial != serial) { /* Resolver has reloaded, discard cached addresses */ - g_list_free_full (addr->priv->sockaddrs, g_object_unref); - addr->priv->sockaddrs = NULL; + g_list_free_full (addr->priv->cached_sockaddrs, g_object_unref); + addr->priv->cached_sockaddrs = NULL; } - if (!addr->priv->sockaddrs) + if (!addr->priv->cached_sockaddrs) g_network_address_parse_sockaddr (addr); - if (!addr->priv->sockaddrs) + if (!addr->priv->cached_sockaddrs) { GList *addresses; @@ -1090,62 +1185,13 @@ g_network_address_address_enumerator_next (GSocketAddressEnumerator *enumerator return NULL; } - g_network_address_add_addresses (addr, g_steal_pointer (&addresses), serial); + g_network_address_set_cached_addresses (addr, g_steal_pointer (&addresses), serial); } - addr_enum->current_item = addr_enum->addresses = list_copy_interleaved (addr->priv->sockaddrs); - addr_enum->last_tail = g_list_last (addr->priv->sockaddrs); g_object_unref (resolver); } - if (addr_enum->current_item == NULL) - return NULL; - - sockaddr = addr_enum->current_item->data; - addr_enum->current_item = g_list_next (addr_enum->current_item); - return g_object_ref (sockaddr); -} - -/* - * Each enumeration lazily initializes the internal address list from the - * master list. It does this since addresses come in asynchronously and - * they need to be resorted into the list already in use. - */ -static GSocketAddress * -init_and_query_next_address (GNetworkAddressAddressEnumerator *addr_enum) -{ - GNetworkAddress *addr = addr_enum->addr; - GSocketAddress *sockaddr; - - if (addr_enum->addresses == NULL) - { - addr_enum->current_item = addr_enum->addresses = list_copy_interleaved (addr->priv->sockaddrs); - addr_enum->last_tail = g_list_last (addr_enum->addr->priv->sockaddrs); - if (addr_enum->current_item) - sockaddr = g_object_ref (addr_enum->current_item->data); - else - sockaddr = NULL; - } - else - { - GList *parent_tail = g_list_last (addr_enum->addr->priv->sockaddrs); - - if (addr_enum->last_tail != parent_tail) - { - addr_enum->current_item = list_concat_interleaved (addr_enum->current_item, g_list_next (addr_enum->last_tail)); - addr_enum->last_tail = parent_tail; - } - - if (addr_enum->current_item->next) - { - addr_enum->current_item = g_list_next (addr_enum->current_item); - sockaddr = g_object_ref (addr_enum->current_item->data); - } - else - sockaddr = NULL; - } - - return sockaddr; + return init_and_query_next_address (addr_enum); } static void @@ -1153,12 +1199,13 @@ complete_queued_task (GNetworkAddressAddressEnumerator *addr_enum, GTask *task, GError *error) { - GSocketAddress *sockaddr = init_and_query_next_address (addr_enum); - if (error) g_task_return_error (task, error); else - g_task_return_pointer (task, sockaddr, g_object_unref); + { + GSocketAddress *sockaddr = init_and_query_next_address (addr_enum); + g_task_return_pointer (task, g_steal_pointer (&sockaddr), g_object_unref); + } g_object_unref (task); } @@ -1197,13 +1244,7 @@ got_ipv6_addresses (GObject *source_object, addresses = g_resolver_lookup_by_name_with_flags_finish (resolver, result, &error); if (!error) - { - /* Regardless of which responds first we add them to the enumerator - * which does mean the timing of next_async() will potentially change - * the results */ - g_network_address_add_addresses (addr_enum->addr, g_steal_pointer (&addresses), - g_resolver_get_serial (resolver)); - } + g_network_address_address_enumerator_add_addresses (addr_enum, g_steal_pointer (&addresses), resolver); else g_debug ("IPv6 DNS error: %s", error->message); @@ -1264,10 +1305,7 @@ got_ipv4_addresses (GObject *source_object, addresses = g_resolver_lookup_by_name_with_flags_finish (resolver, result, &error); if (!error) - { - g_network_address_add_addresses (addr_enum->addr, g_steal_pointer (&addresses), - g_resolver_get_serial (resolver)); - } + g_network_address_address_enumerator_add_addresses (addr_enum, g_steal_pointer (&addresses), resolver); else g_debug ("IPv4 DNS error: %s", error->message); @@ -1331,11 +1369,11 @@ g_network_address_address_enumerator_next_async (GSocketAddressEnumerator *enum addr->priv->resolver_serial != serial) { /* Resolver has reloaded, discard cached addresses */ - g_list_free_full (addr->priv->sockaddrs, g_object_unref); - addr->priv->sockaddrs = NULL; + g_list_free_full (addr->priv->cached_sockaddrs, g_object_unref); + addr->priv->cached_sockaddrs = NULL; } - if (addr->priv->sockaddrs == NULL) + if (addr->priv->cached_sockaddrs == NULL) { if (g_network_address_parse_sockaddr (addr)) complete_queued_task (addr_enum, task, NULL); @@ -1347,7 +1385,7 @@ g_network_address_address_enumerator_next_async (GSocketAddressEnumerator *enum addr_enum->state = RESOLVE_STATE_WAITING_ON_IPV4 | RESOLVE_STATE_WAITING_ON_IPV6; addr_enum->queued_task = g_steal_pointer (&task); - /* Lookup in parallel as per RFC 8305 */ + /* Look up in parallel as per RFC 8305 */ g_resolver_lookup_by_name_with_flags_async (resolver, addr->priv->hostname, G_RESOLVER_NAME_LOOKUP_FLAGS_IPV6_ONLY, diff --git a/gio/gnetworkmonitornm.c b/gio/gnetworkmonitornm.c index 4e2a35e8a..7bb480f54 100644 --- a/gio/gnetworkmonitornm.c +++ b/gio/gnetworkmonitornm.c @@ -52,6 +52,19 @@ typedef enum { NM_CONNECTIVITY_FULL } NMConnectivityState; +/* Copied from https://developer.gnome.org/libnm-util/stable/libnm-util-NetworkManager.html#NMState; + * used inline to avoid a NetworkManager dependency from GLib. */ +typedef enum { + NM_STATE_UNKNOWN = 0, + NM_STATE_ASLEEP = 10, + NM_STATE_DISCONNECTED = 20, + NM_STATE_DISCONNECTING = 30, + NM_STATE_CONNECTING = 40, + NM_STATE_CONNECTED_LOCAL = 50, + NM_STATE_CONNECTED_SITE = 60, + NM_STATE_CONNECTED_GLOBAL = 70, +} NMState; + struct _GNetworkMonitorNMPrivate { GDBusProxy *proxy; @@ -155,11 +168,19 @@ sync_properties (GNetworkMonitorNM *nm, gboolean emit_signals) { GVariant *v; + NMState nm_state; NMConnectivityState nm_connectivity; gboolean new_network_available; gboolean new_network_metered; GNetworkConnectivity new_connectivity; + v = g_dbus_proxy_get_cached_property (nm->priv->proxy, "State"); + if (!v) + return; + + nm_state = g_variant_get_uint32 (v); + g_variant_unref (v); + v = g_dbus_proxy_get_cached_property (nm->priv->proxy, "Connectivity"); if (!v) return; @@ -167,14 +188,26 @@ sync_properties (GNetworkMonitorNM *nm, nm_connectivity = g_variant_get_uint32 (v); g_variant_unref (v); - if (nm_connectivity == NM_CONNECTIVITY_UNKNOWN || - nm_connectivity == NM_CONNECTIVITY_NONE) + if (nm_state <= NM_STATE_CONNECTED_LOCAL) { new_network_available = FALSE; new_network_metered = FALSE; new_connectivity = G_NETWORK_CONNECTIVITY_LOCAL; } - else + else if (nm_state <= NM_STATE_CONNECTED_SITE) + { + new_network_available = FALSE; + new_network_metered = FALSE; + if (nm_connectivity == NM_CONNECTIVITY_PORTAL) + { + new_connectivity = G_NETWORK_CONNECTIVITY_PORTAL; + } + else + { + new_connectivity = G_NETWORK_CONNECTIVITY_LIMITED; + } + } + else /* nm_state == NM_STATE_CONNECTED_FULL */ { /* this is only available post NM 1.0 */ diff --git a/gio/gproxy.c b/gio/gproxy.c index b7e322101..60bb5b8e5 100644 --- a/gio/gproxy.c +++ b/gio/gproxy.c @@ -52,8 +52,8 @@ g_proxy_default_init (GProxyInterface *iface) * g_proxy_get_default_for_protocol: * @protocol: the proxy protocol name (e.g. http, socks, etc) * - * Lookup "gio-proxy" extension point for a proxy implementation that supports - * specified protocol. + * Find the `gio-proxy` extension point for a proxy implementation that supports + * the specified protocol. * * Returns: (transfer full): return a #GProxy or NULL if protocol * is not supported. diff --git a/gio/gresolver.c b/gio/gresolver.c index 7f064322b..3e61ccaff 100644 --- a/gio/gresolver.c +++ b/gio/gresolver.c @@ -1041,8 +1041,8 @@ g_resolver_free_targets (GList *targets) /** * g_resolver_lookup_records: * @resolver: a #GResolver - * @rrname: the DNS name to lookup the record for - * @record_type: the type of DNS record to lookup + * @rrname: the DNS name to look up the record for + * @record_type: the type of DNS record to look up * @cancellable: (nullable): a #GCancellable, or %NULL * @error: return location for a #GError, or %NULL * @@ -1086,8 +1086,8 @@ g_resolver_lookup_records (GResolver *resolver, /** * g_resolver_lookup_records_async: * @resolver: a #GResolver - * @rrname: the DNS name to lookup the record for - * @record_type: the type of DNS record to lookup + * @rrname: the DNS name to look up the record for + * @record_type: the type of DNS record to look up * @cancellable: (nullable): a #GCancellable, or %NULL * @callback: (scope async): callback to call after resolution completes * @user_data: (closure): data for @callback diff --git a/gio/gschema.dtd b/gio/gschema.dtd index 1599f8de7..3a903e7ab 100644 --- a/gio/gschema.dtd +++ b/gio/gschema.dtd @@ -62,7 +62,8 @@ <!ELEMENT aliases (alias+) > <!-- each alias element specifies an alias for one of the possible values --> <!ELEMENT alias EMPTY > -<!ATTLIST alias value CDATA #REQUIRED > +<!ATTLIST alias value CDATA #REQUIRED + target CDATA #REQUIRED > <!ELEMENT child EMPTY > <!ATTLIST child name CDATA #REQUIRED diff --git a/gio/gsettings-mapping.c b/gio/gsettings-mapping.c index bba8a8f7c..8c64b02a5 100644 --- a/gio/gsettings-mapping.c +++ b/gio/gsettings-mapping.c @@ -498,7 +498,7 @@ g_settings_get_mapping (GValue *value, return TRUE; } - g_warning ("Unable to lookup enum nick '%s' via GType", nick); + g_warning ("Unable to look up enum nick ‘%s’ via GType", nick); return FALSE; } } diff --git a/gio/gsocket.c b/gio/gsocket.c index d4372c544..06514d102 100644 --- a/gio/gsocket.c +++ b/gio/gsocket.c @@ -4540,7 +4540,8 @@ input_message_from_msghdr (const struct msghdr *msg, * @messages: (array length=num_messages) (nullable): a pointer to an * array of #GSocketControlMessages, or %NULL. * @num_messages: number of elements in @messages, or -1. - * @flags: an int containing #GSocketMsgFlags flags + * @flags: an int containing #GSocketMsgFlags flags, which may additionally + * contain [other platform specific flags](http://man7.org/linux/man-pages/man2/recv.2.html) * @cancellable: (nullable): a %GCancellable or %NULL * @error: #GError for error reporting, or %NULL to ignore. * @@ -4629,7 +4630,8 @@ g_socket_send_message (GSocket *socket, * @messages: (array length=num_messages) (nullable): a pointer to an * array of #GSocketControlMessages, or %NULL. * @num_messages: number of elements in @messages, or -1. - * @flags: an int containing #GSocketMsgFlags flags + * @flags: an int containing #GSocketMsgFlags flags, which may additionally + * contain [other platform specific flags](http://man7.org/linux/man-pages/man2/recv.2.html) * @timeout_us: the maximum time (in microseconds) to wait, or -1 * @bytes_written: (out) (optional): location to store the number of bytes that were written to the socket * @cancellable: (nullable): a %GCancellable or %NULL @@ -4862,7 +4864,8 @@ g_socket_send_message_with_timeout (GSocket *socket, * @socket: a #GSocket * @messages: (array length=num_messages): an array of #GOutputMessage structs * @num_messages: the number of elements in @messages - * @flags: an int containing #GSocketMsgFlags flags + * @flags: an int containing #GSocketMsgFlags flags, which may additionally + * contain [other platform specific flags](http://man7.org/linux/man-pages/man2/recv.2.html) * @cancellable: (nullable): a %GCancellable or %NULL * @error: #GError for error reporting, or %NULL to ignore. * @@ -5362,7 +5365,9 @@ g_socket_receive_message_with_timeout (GSocket *socket, * @socket: a #GSocket * @messages: (array length=num_messages): an array of #GInputMessage structs * @num_messages: the number of elements in @messages - * @flags: an int containing #GSocketMsgFlags flags for the overall operation + * @flags: an int containing #GSocketMsgFlags flags for the overall operation, + * which may additionally contain + * [other platform specific flags](http://man7.org/linux/man-pages/man2/recv.2.html) * @cancellable: (nullable): a %GCancellable or %NULL * @error: #GError for error reporting, or %NULL to ignore * @@ -5648,7 +5653,9 @@ g_socket_receive_messages_with_timeout (GSocket *socket, * which may be filled with an array of #GSocketControlMessages, or %NULL * @num_messages: (out): a pointer which will be filled with the number of * elements in @messages, or %NULL - * @flags: (inout): a pointer to an int containing #GSocketMsgFlags flags + * @flags: (inout): a pointer to an int containing #GSocketMsgFlags flags, + * which may additionally contain + * [other platform specific flags](http://man7.org/linux/man-pages/man2/recv.2.html) * @cancellable: a %GCancellable or %NULL * @error: a #GError pointer, or %NULL * diff --git a/gio/gsocketclient.c b/gio/gsocketclient.c index 83cb945c7..59af25abf 100644 --- a/gio/gsocketclient.c +++ b/gio/gsocketclient.c @@ -1427,15 +1427,24 @@ g_socket_client_async_connect_complete (GSocketClientAsyncConnectData *data) data->connection = (GIOStream *)wrapper_connection; } - if (!g_task_return_error_if_cancelled (data->task)) + if (!data->completed) { - g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, data->connection); - g_task_return_pointer (data->task, g_steal_pointer (&data->connection), g_object_unref); + GError *error = NULL; + + if (g_cancellable_set_error_if_cancelled (g_task_get_cancellable (data->task), &error)) + { + g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, NULL); + g_task_return_error (data->task, g_steal_pointer (&error)); + } + else + { + g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, data->connection); + g_task_return_pointer (data->task, g_steal_pointer (&data->connection), g_object_unref); + } + + data->completed = TRUE; } - else - g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, NULL); - data->completed = TRUE; g_object_unref (data->task); } @@ -1607,6 +1616,7 @@ g_socket_client_connected_callback (GObject *source, set_last_error (data, error); connection_attempt_remove (attempt); enumerator_next_async (data, FALSE); + connection_attempt_unref (attempt); } else { diff --git a/gio/gtask.c b/gio/gtask.c index f6c89c974..9950bb36b 100644 --- a/gio/gtask.c +++ b/gio/gtask.c @@ -626,11 +626,14 @@ static gint tasks_running; * The base and multiplier below gives us 10 extra threads after about * a second of blocking, 30 after 5 seconds, 100 after a minute, and * 200 after 20 minutes. + * + * We specify maximum pool size of 330 to increase the waiting time up + * to around 30 minutes. */ #define G_TASK_POOL_SIZE 10 #define G_TASK_WAIT_TIME_BASE 100000 #define G_TASK_WAIT_TIME_MULTIPLIER 1.03 -#define G_TASK_WAIT_TIME_MAX (30 * 60 * 1000000) +#define G_TASK_WAIT_TIME_MAX_POOL_SIZE 330 static void g_task_init (GTask *task) @@ -1366,7 +1369,7 @@ g_task_thread_setup (void) if (tasks_running == G_TASK_POOL_SIZE) task_wait_time = G_TASK_WAIT_TIME_BASE; - else if (tasks_running > G_TASK_POOL_SIZE && task_wait_time < G_TASK_WAIT_TIME_MAX) + else if (tasks_running > G_TASK_POOL_SIZE && tasks_running < G_TASK_WAIT_TIME_MAX_POOL_SIZE) task_wait_time *= G_TASK_WAIT_TIME_MULTIPLIER; if (tasks_running >= G_TASK_POOL_SIZE) @@ -1388,6 +1391,9 @@ g_task_thread_cleanup (void) else if (tasks_running + tasks_pending < G_TASK_POOL_SIZE) g_source_set_ready_time (task_pool_manager, -1); + if (tasks_running > G_TASK_POOL_SIZE && tasks_running < G_TASK_WAIT_TIME_MAX_POOL_SIZE) + task_wait_time /= G_TASK_WAIT_TIME_MULTIPLIER; + tasks_running--; g_mutex_unlock (&task_pool_mutex); g_private_set (&task_private, GUINT_TO_POINTER (FALSE)); diff --git a/gio/gtlsdatabase.c b/gio/gtlsdatabase.c index 58da11df3..f06dabf0a 100644 --- a/gio/gtlsdatabase.c +++ b/gio/gtlsdatabase.c @@ -35,7 +35,7 @@ * @short_description: TLS database type * @include: gio/gio.h * - * #GTlsDatabase is used to lookup certificates and other information + * #GTlsDatabase is used to look up certificates and other information * from a certificate or key store. It is an abstract base class which * TLS library specific subtypes override. * @@ -658,7 +658,7 @@ g_tls_database_create_certificate_handle (GTlsDatabase *self, * @cancellable: (nullable): a #GCancellable, or %NULL * @error: (nullable): a #GError, or %NULL * - * Lookup a certificate by its handle. + * Look up a certificate by its handle. * * The handle should have been created by calling * g_tls_database_create_certificate_handle() on a #GTlsDatabase object of @@ -709,7 +709,7 @@ g_tls_database_lookup_certificate_for_handle (GTlsDatabase *self, * @callback: callback to call when the operation completes * @user_data: the data to pass to the callback function * - * Asynchronously lookup a certificate by its handle in the database. See + * Asynchronously look up a certificate by its handle in the database. See * g_tls_database_lookup_certificate_for_handle() for more information. * * Since: 2.30 @@ -777,7 +777,7 @@ g_tls_database_lookup_certificate_for_handle_finish (GTlsDatabase *se * @cancellable: (nullable): a #GCancellable, or %NULL * @error: (nullable): a #GError, or %NULL * - * Lookup the issuer of @certificate in the database. + * Look up the issuer of @certificate in the database. * * The #GTlsCertificate:issuer property * of @certificate is not modified, and the two certificates are not hooked @@ -823,7 +823,7 @@ g_tls_database_lookup_certificate_issuer (GTlsDatabase *self, * @callback: callback to call when the operation completes * @user_data: the data to pass to the callback function * - * Asynchronously lookup the issuer of @certificate in the database. See + * Asynchronously look up the issuer of @certificate in the database. See * g_tls_database_lookup_certificate_issuer() for more information. * * Since: 2.30 @@ -889,7 +889,7 @@ g_tls_database_lookup_certificate_issuer_finish (GTlsDatabase *self, * @cancellable: (nullable): a #GCancellable, or %NULL * @error: (nullable): a #GError, or %NULL * - * Lookup certificates issued by this issuer in the database. + * Look up certificates issued by this issuer in the database. * * This function can block, use g_tls_database_lookup_certificates_issued_by_async() to perform * the lookup operation asynchronously. @@ -931,7 +931,7 @@ g_tls_database_lookup_certificates_issued_by (GTlsDatabase *self, * @callback: callback to call when the operation completes * @user_data: the data to pass to the callback function * - * Asynchronously lookup certificates issued by this issuer in the database. See + * Asynchronously look up certificates issued by this issuer in the database. See * g_tls_database_lookup_certificates_issued_by() for more information. * * The database may choose to hold a reference to the issuer byte array for the duration diff --git a/gio/gvfs.h b/gio/gvfs.h index 46ad792c8..72fe2dd32 100644 --- a/gio/gvfs.h +++ b/gio/gvfs.h @@ -39,7 +39,7 @@ G_BEGIN_DECLS /** * GVfsFileLookupFunc: * @vfs: a #GVfs - * @identifier: the identifier to lookup a #GFile for. This can either + * @identifier: the identifier to look up a #GFile for. This can either * be an URI or a parse name as returned by g_file_get_parse_name() * @user_data: user data passed to the function * diff --git a/gio/meson.build b/gio/meson.build index 4e5e021e9..f0e08b40f 100644 --- a/gio/meson.build +++ b/gio/meson.build @@ -994,4 +994,8 @@ if enable_systemtap endif subdir('fam') -subdir('tests') +# Don’t build the tests unless we can run them (either natively or in an exe wrapper) +build_tests = not meson.is_cross_build() or (meson.is_cross_build() and meson.has_exe_wrapper()) +if build_tests + subdir('tests') +endif
\ No newline at end of file diff --git a/gio/strinfo.c b/gio/strinfo.c index cd47215da..f5e92a41d 100644 --- a/gio/strinfo.c +++ b/gio/strinfo.c @@ -61,24 +61,24 @@ * * The operations that someone may want to perform with the map: * - * - lookup if a string is valid (and not an alias) - * - lookup the integer value for a enum 'nick' - * - lookup the integer value for the target of an alias - * - lookup an alias and convert it to its target string - * - lookup the enum nick for a given value + * - look up if a string is valid (and not an alias) + * - look up the integer value for a enum 'nick' + * - look up the integer value for the target of an alias + * - look up an alias and convert it to its target string + * - look up the enum nick for a given value * - * In order to lookup if a string is valid, it is padded on either side + * In order to look up if a string is valid, it is padded on either side * (as described) and scanned for in the array. For example, you might * look for "foo": * * xff 'f' 'o' 'o' x00 x00 x00 xff * - * In order to lookup the integer value for a nick, the string is padded + * In order to look up the integer value for a nick, the string is padded * on either side and scanned for in the array, as above. Instead of * merely succeeding, we look at the integer value to the left of the * match. This is the enum value. * - * In order to lookup an alias and convert it to its target enum value, + * In order to look up an alias and convert it to its target enum value, * the string is padded on either side (as described, with 0xfe) and * scanned for. For example, you might look for "baz": * @@ -92,7 +92,7 @@ * added past the start of the integer value to find the start of the * string. * - * To lookup the enum nick for a given value, the value is searched for + * To look up the enum nick for a given value, the value is searched for * in the array. To ensure that the value isn't matching the inside of a * string, we must check that it is either the first item in the array or * immediately preceded by the byte 0xff. It must also be immediately diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c index ed2f89111..f4e509a59 100644 --- a/gio/tests/desktop-app-info.c +++ b/gio/tests/desktop-app-info.c @@ -659,7 +659,7 @@ test_search (void) assert_search ("konq", "kde4-konqbrowser.desktop\n", TRUE, TRUE, NULL, NULL); assert_search ("kate", "kde4-kate.desktop\n", TRUE, TRUE, NULL, NULL); - /* make sure we can lookup apps by name properly */ + /* make sure we can look up apps by name properly */ assert_info ("kde4-kate.desktop", "kde4-kate.desktop\n" "Kate\n" diff --git a/gio/tests/gapplication.c b/gio/tests/gapplication.c index ec57977a5..900e7ac97 100644 --- a/gio/tests/gapplication.c +++ b/gio/tests/gapplication.c @@ -140,7 +140,7 @@ basic (void) main_loop = g_main_loop_new (NULL, 0); - /* spawn the master */ + /* spawn the main instance */ spawn ("activated\n" "open file:///a file:///b\n" "exit status: 0\n", NULL, @@ -191,7 +191,7 @@ test_remote_command_line (void) NULL); g_object_unref (file); - /* spawn the master */ + /* spawn the main instance */ spawn (replies, NULL, "./cmd", NULL); @@ -255,7 +255,7 @@ test_remote_actions (void) main_loop = g_main_loop_new (NULL, 0); - /* spawn the master */ + /* spawn the main instance */ spawn ("got ./cmd 0\n" "activate action1\n" "change action2 1\n" diff --git a/gio/tests/meson.build b/gio/tests/meson.build index f13458181..a0c09444b 100644 --- a/gio/tests/meson.build +++ b/gio/tests/meson.build @@ -54,7 +54,6 @@ gio_tests = { 'io-stream' : {}, 'memory-input-stream' : {}, 'memory-output-stream' : {}, - 'monitor' : {}, 'mount-operation' : {}, 'network-address' : {'extra_sources': ['mock-resolver.c']}, 'network-monitor' : {}, @@ -141,13 +140,17 @@ if host_machine.system() != 'windows' } if have_rtld_next + # FIXME: This list will probably grow; see + # https://gitlab.gnome.org/GNOME/glib/issues/1739 + no_libdl_systems = ['freebsd', 'netbsd', 'openbsd'] + gio_tests += { 'gsocketclient-slow' : { 'depends' : [ shared_library('slow-connect-preload', 'slow-connect-preload.c', name_prefix : '', - dependencies: cc.find_library('dl'), + dependencies: cc.find_library('dl', required: not no_libdl_systems.contains(host_machine.system())), install_dir : installed_tests_execdir, install: installed_tests_enabled, ) @@ -675,7 +678,6 @@ foreach test_name, extra_args : gio_tests env : local_test_env, timeout : timeout, suite : suite, - args : ['--tap'], is_parallel : extra_args.get('is_parallel', true), depends : extra_args.get('depends', []), ) diff --git a/gio/tests/monitor.c b/gio/tests/monitor.c deleted file mode 100644 index 4d64fa826..000000000 --- a/gio/tests/monitor.c +++ /dev/null @@ -1,220 +0,0 @@ -#include <gio/gio.h> -#include <gstdio.h> - -typedef struct -{ - gchar *tmp_dir; -} Fixture; - -static void -setup (Fixture *fixture, - gconstpointer user_data) -{ - GError *error = NULL; - - fixture->tmp_dir = g_dir_make_tmp ("gio-test-file-monitor_XXXXXX", &error); - g_assert_no_error (error); - - g_test_message ("Using temporary directory: %s", fixture->tmp_dir); -} - -static void -teardown (Fixture *fixture, - gconstpointer user_data) -{ - g_assert_cmpint (g_rmdir (fixture->tmp_dir), ==, 0); - g_clear_pointer (&fixture->tmp_dir, g_free); -} - -typedef struct { - GFile *file; - GOutputStream *stream; - GMainLoop *loop; - gint state; -} MonitorData; - -static gboolean -create_file_idle (gpointer data) -{ - MonitorData *d = data; - GError *error = NULL; - - g_assert (d->state == 0); - - d->stream = (GOutputStream*)g_file_create (d->file, 0, NULL, &error); - g_assert_no_error (error); - - d->state = 1; - - return G_SOURCE_REMOVE; -} - -static gboolean -write_file_idle (gpointer data) -{ - MonitorData *d = data; - GError *error = NULL; - - g_assert (d->state == 2); - - g_output_stream_write (d->stream, "abcd", 4, NULL, &error); - g_assert_no_error (error); - g_object_unref (d->stream); - d->stream = NULL; - - d->state = 3; - - - return G_SOURCE_REMOVE; -} - -static gboolean -delete_file_idle (gpointer data) -{ - MonitorData *d = data; - GError *error = NULL; - - g_assert (d->state == 4); - - g_file_delete (d->file, NULL, &error); - g_assert_no_error (error); - - d->state = 5; - - return G_SOURCE_REMOVE; -} - -static gboolean -stop_loop_idle (gpointer data) -{ - MonitorData *d = data; - - g_assert (d->state == 6); - - if (d->loop) - g_main_loop_quit (d->loop); - - return G_SOURCE_REMOVE; -} - -static void -changed_cb (GFileMonitor *monitor, - GFile *file, - GFile *other_file, - GFileMonitorEvent event, - gpointer data) -{ - MonitorData *d = data; - - switch (d->state) - { - case 1: - g_assert (event == G_FILE_MONITOR_EVENT_CREATED); - d->state = 2; - g_idle_add (write_file_idle, data); - break; - case 3: - g_assert (event == G_FILE_MONITOR_EVENT_CHANGED || - event == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT); - if (event == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT) - { - d->state = 4; - g_idle_add (delete_file_idle, data); - } - break; - case 5: - g_assert (event == G_FILE_MONITOR_EVENT_DELETED); - d->state = 6; - g_idle_add (stop_loop_idle, data); - break; - default: - g_assert_not_reached (); - break; - } -} - -static void -file_changed_cb (GFileMonitor *monitor, - GFile *file, - GFile *other_file, - GFileMonitorEvent event, - gpointer data) -{ - gint *state = data; - - switch (*state) - { - case 0: - g_assert (event == G_FILE_MONITOR_EVENT_CREATED); - *state = 1; - break; - case 1: - g_assert (event == G_FILE_MONITOR_EVENT_CHANGED || - event == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT); - if (event == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT) - *state = 2; - break; - case 2: - g_assert (event == G_FILE_MONITOR_EVENT_DELETED); - *state = 3; - break; - default: - g_assert_not_reached (); - break; - } -} - -static void -test_directory_monitor (Fixture *fixture, - gconstpointer user_data) -{ - GFile *file; - GFile *child; - GFileMonitor *dir_monitor; - GFileMonitor *file_monitor; - GError *error = NULL; - MonitorData data; - gint state; - GMainLoop *loop; - - file = g_file_new_for_path (fixture->tmp_dir); - dir_monitor = g_file_monitor_directory (file, 0, NULL, &error); - g_assert_no_error (error); - - child = g_file_get_child (file, "test-file"); - file_monitor = g_file_monitor_file (child, 0, NULL, &error); - g_assert_no_error (error); - - loop = g_main_loop_new (NULL, FALSE); - - g_signal_connect (dir_monitor, "changed", G_CALLBACK (changed_cb), &data); - g_signal_connect (file_monitor, "changed", G_CALLBACK (file_changed_cb), &state); - - data.loop = loop; - data.file = child; - data.state = 0; - state = 0; - - g_idle_add (create_file_idle, &data); - - g_main_loop_run (loop); - - g_assert_cmpint (data.state, ==, 6); - g_assert_cmpint (state, ==, 3); - - g_main_loop_unref (loop); - g_object_unref (dir_monitor); - g_object_unref (file_monitor); - g_object_unref (child); - g_object_unref (file); -} - -int -main (int argc, char *argv[]) -{ - g_test_init (&argc, &argv, NULL); - - g_test_add ("/monitor/directory", Fixture, NULL, setup, test_directory_monitor, teardown); - - return g_test_run (); -} diff --git a/gio/tests/network-address.c b/gio/tests/network-address.c index c62afccd2..0dcd7b292 100644 --- a/gio/tests/network-address.c +++ b/gio/tests/network-address.c @@ -426,7 +426,9 @@ typedef struct { } AsyncData; static void -got_addr (GObject *source_object, GAsyncResult *result, gpointer user_data) +got_addr (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { GSocketAddressEnumerator *enumerator; AsyncData *data; @@ -466,6 +468,30 @@ got_addr (GObject *source_object, GAsyncResult *result, gpointer user_data) } static void +got_addr_ignored (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + GSocketAddressEnumerator *enumerator; + GSocketAddress *a; /* owned */ + GError *error = NULL; + + /* This function simply ignores the returned addresses but keeps enumerating */ + + enumerator = G_SOCKET_ADDRESS_ENUMERATOR (source_object); + + a = g_socket_address_enumerator_next_finish (enumerator, result, &error); + g_assert_no_error (error); + if (a != NULL) + { + g_object_unref (a); + g_socket_address_enumerator_next_async (enumerator, NULL, + got_addr_ignored, user_data); + } +} + + +static void test_loopback_async (void) { GSocketConnectable *addr; /* owned */ @@ -647,6 +673,39 @@ test_happy_eyeballs_basic (HappyEyeballsFixture *fixture, } static void +test_happy_eyeballs_parallel (HappyEyeballsFixture *fixture, + gconstpointer user_data) +{ + AsyncData data = { 0 }; + GSocketAddressEnumerator *enumerator2; + + enumerator2 = g_socket_connectable_enumerate (fixture->addr); + + data.delay_ms = FAST_DELAY_LESS_THAN_TIMEOUT; + data.loop = fixture->loop; + + /* We run multiple enumerations at once, the results shouldn't be affected. */ + + g_socket_address_enumerator_next_async (enumerator2, NULL, got_addr_ignored, &data); + g_socket_address_enumerator_next_async (fixture->enumerator, NULL, got_addr, &data); + g_main_loop_run (fixture->loop); + + assert_list_matches_expected (data.addrs, fixture->input_all_results); + + /* Run again to ensure the cache from the previous one is correct */ + + data.addrs = NULL; + g_object_unref (enumerator2); + + enumerator2 = g_socket_connectable_enumerate (fixture->addr); + g_socket_address_enumerator_next_async (enumerator2, NULL, got_addr, &data); + g_main_loop_run (fixture->loop); + + assert_list_matches_expected (data.addrs, fixture->input_all_results); + g_object_unref (enumerator2); +} + +static void test_happy_eyeballs_slow_ipv4 (HappyEyeballsFixture *fixture, gconstpointer user_data) { @@ -958,6 +1017,8 @@ main (int argc, char *argv[]) g_test_add ("/network-address/happy-eyeballs/basic", HappyEyeballsFixture, NULL, happy_eyeballs_setup, test_happy_eyeballs_basic, happy_eyeballs_teardown); + g_test_add ("/network-address/happy-eyeballs/parallel", HappyEyeballsFixture, NULL, + happy_eyeballs_setup, test_happy_eyeballs_parallel, happy_eyeballs_teardown); g_test_add ("/network-address/happy-eyeballs/slow-ipv4", HappyEyeballsFixture, NULL, happy_eyeballs_setup, test_happy_eyeballs_slow_ipv4, happy_eyeballs_teardown); g_test_add ("/network-address/happy-eyeballs/slow-ipv6", HappyEyeballsFixture, NULL, diff --git a/gio/tests/resolver.c b/gio/tests/resolver.c index 85d512428..c57b81867 100644 --- a/gio/tests/resolver.c +++ b/gio/tests/resolver.c @@ -49,7 +49,7 @@ usage (void) fprintf (stderr, " Use -s to do synchronous lookups.\n"); fprintf (stderr, " Use -c NUMBER (and only a single resolvable argument) to test GSocketConnectable.\n"); fprintf (stderr, " The given NUMBER determines how many times the connectable will be enumerated.\n"); - fprintf (stderr, " Use -t with MX, TXT, NS or SOA to lookup DNS records of those types.\n"); + fprintf (stderr, " Use -t with MX, TXT, NS or SOA to look up DNS records of those types.\n"); exit (1); } @@ -222,6 +222,7 @@ print_resolved_txt (const char *rrname, for (i = 0; contents[i] != NULL; i++) printf ("%s\n", contents[i]); g_variant_unref (t->data); + g_free (contents); } g_list_free (records); } @@ -739,6 +740,7 @@ main (int argc, char **argv) g_source_remove (watch); #endif g_object_unref (cancellable); + g_option_context_free (context); return 0; } diff --git a/gio/tests/socket-client.c b/gio/tests/socket-client.c index 803f4d6e9..8df1c28f3 100644 --- a/gio/tests/socket-client.c +++ b/gio/tests/socket-client.c @@ -431,7 +431,7 @@ main (int argc, { if (!g_socket_close (socket, &error)) { - g_printerr ("Error closing master socket: %s\n", + g_printerr ("Error closing socket: %s\n", error->message); return 1; } diff --git a/gio/tests/socket-server.c b/gio/tests/socket-server.c index decf3ecd1..24cf0182e 100644 --- a/gio/tests/socket-server.c +++ b/gio/tests/socket-server.c @@ -356,7 +356,7 @@ main (int argc, if (!g_socket_close (socket, &error)) { - g_printerr ("Error closing master socket: %s\n", + g_printerr ("Error closing socket: %s\n", error->message); return 1; } |