Gio.Resolver

g GObject.Object GObject.Object Gio.Resolver Gio.Resolver GObject.Object->Gio.Resolver

Subclasses:

Gio.ThreadedResolver

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

get_default ()

get_timeout ()

lookup_by_address (address, cancellable)

lookup_by_address_async (address, cancellable, callback, *user_data)

lookup_by_address_finish (result)

lookup_by_name (hostname, cancellable)

lookup_by_name_async (hostname, cancellable, callback, *user_data)

lookup_by_name_finish (result)

lookup_by_name_with_flags (hostname, flags, cancellable)

lookup_by_name_with_flags_async (hostname, flags, cancellable, callback, *user_data)

lookup_by_name_with_flags_finish (result)

lookup_records (rrname, record_type, cancellable)

lookup_records_async (rrname, record_type, cancellable, callback, *user_data)

lookup_records_finish (result)

lookup_service (service, protocol, domain, cancellable)

lookup_service_async (service, protocol, domain, cancellable, callback, *user_data)

lookup_service_finish (result)

set_default ()

set_timeout (timeout_ms)

Virtual Methods

Inherited:

GObject.Object (7)

do_lookup_by_address (address, cancellable)

do_lookup_by_address_async (address, cancellable, callback, *user_data)

do_lookup_by_address_finish (result)

do_lookup_by_name (hostname, cancellable)

do_lookup_by_name_async (hostname, cancellable, callback, *user_data)

do_lookup_by_name_finish (result)

do_lookup_by_name_with_flags (hostname, flags, cancellable)

do_lookup_by_name_with_flags_async (hostname, flags, cancellable, callback, *user_data)

do_lookup_by_name_with_flags_finish (result)

do_lookup_records (rrname, record_type, cancellable)

do_lookup_records_async (rrname, record_type, cancellable, callback, *user_data)

do_lookup_records_finish (result)

do_lookup_service_async (rrname, cancellable, callback, *user_data)

do_lookup_service_finish (result)

do_reload ()

Properties

Name

Type

Flags

Short Description

timeout

int

r/w/en

Signals

Inherited:

GObject.Object (1)

Name

Short Description

reload

Emitted when the resolver notices that the system resolver configuration has changed.

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class Gio.Resolver(**kwargs)
Bases:

GObject.Object

Abstract:

Yes

Structure:

Gio.ResolverClass

The object that handles DNS resolution. Use [func`Gio`.Resolver.get_default] to get the default resolver.

GResolver provides cancellable synchronous and asynchronous DNS resolution, for hostnames ([method`Gio`.Resolver.lookup_by_address], [method`Gio`.Resolver.lookup_by_name] and their async variants) and SRV (service) records ([method`Gio`.Resolver.lookup_service]).

[class`Gio`.NetworkAddress] and [class`Gio`.NetworkService] provide wrappers around GResolver functionality that also implement [iface`Gio`.SocketConnectable], making it easy to connect to a remote host/service.

The default resolver (see [func`Gio`.Resolver.get_default]) has a timeout of 30s set on it since GLib 2.78. Earlier versions of GLib did not support resolver timeouts.

This is an abstract type; subclasses of it implement different resolvers for different platforms and situations.

classmethod get_default()[source]
Returns:

the default Gio.Resolver.

Return type:

Gio.Resolver

Gets the default Gio.Resolver. You should unref it when you are done with it. Gio.Resolver may use its reference count as a hint about how many threads it should allocate for concurrent DNS resolutions.

New in version 2.22.

get_timeout()[source]
Returns:

the resolver timeout, in milliseconds, or 0 for no timeout

Return type:

int

Get the timeout applied to all resolver lookups. See Gio.Resolver :timeout.

New in version 2.78.

lookup_by_address(address, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a hostname (either ASCII-only, or in ASCII-encoded form), or None on error.

Return type:

str

Synchronously reverse-resolves address to determine its associated hostname.

If the DNS resolution fails, error (if non-None) will be set to a value from Gio.ResolverError.

If cancellable is non-None, it can be used to cancel the operation, in which case error (if non-None) will be set to Gio.IOErrorEnum.CANCELLED.

New in version 2.22.

lookup_by_address_async(address, cancellable, callback, *user_data)[source]
Parameters:

Begins asynchronously reverse-resolving address to determine its associated hostname, and eventually calls callback, which must call Gio.Resolver.lookup_by_address_finish() to get the final result.

New in version 2.22.

lookup_by_address_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – the result passed to your Gio.AsyncReadyCallback

Raises:

GLib.Error

Returns:

a hostname (either ASCII-only, or in ASCII-encoded form), or None on error.

Return type:

str

Retrieves the result of a previous call to Gio.Resolver.lookup_by_address_async().

If the DNS resolution failed, error (if non-None) will be set to a value from Gio.ResolverError. If the operation was cancelled, error will be set to Gio.IOErrorEnum.CANCELLED.

New in version 2.22.

lookup_by_name(hostname, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a non-empty GLib.List of Gio.InetAddress, or None on error. You must unref each of the addresses and free the list when you are done with it. (You can use g_resolver_free_addresses() to do this.)

Return type:

[Gio.InetAddress]

Synchronously resolves hostname to determine its associated IP address(es). hostname may be an ASCII-only or UTF-8 hostname, or the textual form of an IP address (in which case this just becomes a wrapper around Gio.InetAddress.new_from_string()).

On success, Gio.Resolver.lookup_by_name() will return a non-empty GLib.List of Gio.InetAddress, sorted in order of preference and guaranteed to not contain duplicates. That is, if using the result to connect to hostname, you should attempt to connect to the first address first, then the second if the first fails, etc. If you are using the result to listen on a socket, it is appropriate to add each result using e.g. Gio.SocketListener.add_address().

If the DNS resolution fails, error (if non-None) will be set to a value from Gio.ResolverError and None will be returned.

If cancellable is non-None, it can be used to cancel the operation, in which case error (if non-None) will be set to Gio.IOErrorEnum.CANCELLED.

If you are planning to connect to a socket on the resolved IP address, it may be easier to create a Gio.NetworkAddress and use its Gio.SocketConnectable interface.

New in version 2.22.

lookup_by_name_async(hostname, cancellable, callback, *user_data)[source]
Parameters:

Begins asynchronously resolving hostname to determine its associated IP address(es), and eventually calls callback, which must call Gio.Resolver.lookup_by_name_finish() to get the result. See Gio.Resolver.lookup_by_name() for more details.

New in version 2.22.

lookup_by_name_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – the result passed to your Gio.AsyncReadyCallback

Raises:

GLib.Error

Returns:

a GLib.List of Gio.InetAddress, or None on error. See Gio.Resolver.lookup_by_name() for more details.

Return type:

[Gio.InetAddress]

Retrieves the result of a call to Gio.Resolver.lookup_by_name_async().

If the DNS resolution failed, error (if non-None) will be set to a value from Gio.ResolverError. If the operation was cancelled, error will be set to Gio.IOErrorEnum.CANCELLED.

New in version 2.22.

lookup_by_name_with_flags(hostname, flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a non-empty GLib.List of Gio.InetAddress, or None on error. You must unref each of the addresses and free the list when you are done with it. (You can use g_resolver_free_addresses() to do this.)

Return type:

[Gio.InetAddress]

This differs from Gio.Resolver.lookup_by_name() in that you can modify the lookup behavior with flags. For example this can be used to limit results with Gio.ResolverNameLookupFlags.IPV4_ONLY.

New in version 2.60.

lookup_by_name_with_flags_async(hostname, flags, cancellable, callback, *user_data)[source]
Parameters:

Begins asynchronously resolving hostname to determine its associated IP address(es), and eventually calls callback, which must call Gio.Resolver.lookup_by_name_with_flags_finish() to get the result. See Gio.Resolver.lookup_by_name() for more details.

New in version 2.60.

lookup_by_name_with_flags_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – the result passed to your Gio.AsyncReadyCallback

Raises:

GLib.Error

Returns:

a GLib.List of Gio.InetAddress, or None on error. See Gio.Resolver.lookup_by_name() for more details.

Return type:

[Gio.InetAddress]

Retrieves the result of a call to Gio.Resolver.lookup_by_name_with_flags_async().

If the DNS resolution failed, error (if non-None) will be set to a value from Gio.ResolverError. If the operation was cancelled, error will be set to Gio.IOErrorEnum.CANCELLED.

New in version 2.60.

lookup_records(rrname, record_type, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a non-empty GLib.List of GLib.Variant, or None on error. You must free each of the records and the list when you are done with it. (You can use g_list_free_full() with GLib.Variant.unref() to do this.)

Return type:

[GLib.Variant]

Synchronously performs a DNS record lookup for the given rrname and returns a list of records as GLib.Variant tuples. See Gio.ResolverRecordType for information on what the records contain for each record_type.

If the DNS resolution fails, error (if non-None) will be set to a value from Gio.ResolverError and None will be returned.

If cancellable is non-None, it can be used to cancel the operation, in which case error (if non-None) will be set to Gio.IOErrorEnum.CANCELLED.

New in version 2.34.

lookup_records_async(rrname, record_type, cancellable, callback, *user_data)[source]
Parameters:

Begins asynchronously performing a DNS lookup for the given rrname, and eventually calls callback, which must call Gio.Resolver.lookup_records_finish() to get the final result. See Gio.Resolver.lookup_records() for more details.

New in version 2.34.

lookup_records_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – the result passed to your Gio.AsyncReadyCallback

Raises:

GLib.Error

Returns:

a non-empty GLib.List of GLib.Variant, or None on error. You must free each of the records and the list when you are done with it. (You can use g_list_free_full() with GLib.Variant.unref() to do this.)

Return type:

[GLib.Variant]

Retrieves the result of a previous call to Gio.Resolver.lookup_records_async(). Returns a non-empty list of records as GLib.Variant tuples. See Gio.ResolverRecordType for information on what the records contain.

If the DNS resolution failed, error (if non-None) will be set to a value from Gio.ResolverError. If the operation was cancelled, error will be set to Gio.IOErrorEnum.CANCELLED.

New in version 2.34.

lookup_service(service, protocol, domain, cancellable)[source]
Parameters:
  • service (str) – the service type to look up (eg, “ldap”)

  • protocol (str) – the networking protocol to use for service (eg, “tcp”)

  • domain (str) – the DNS domain to look up the service in

  • cancellable (Gio.Cancellable or None) – a Gio.Cancellable, or None

Raises:

GLib.Error

Returns:

a non-empty GLib.List of Gio.SrvTarget, or None on error. You must free each of the targets and the list when you are done with it. (You can use g_resolver_free_targets() to do this.)

Return type:

[Gio.SrvTarget]

Synchronously performs a DNS SRV lookup for the given service and protocol in the given domain and returns an array of Gio.SrvTarget. domain may be an ASCII-only or UTF-8 hostname. Note also that the service and protocol arguments do not include the leading underscore that appears in the actual DNS entry.

On success, Gio.Resolver.lookup_service() will return a non-empty GLib.List of Gio.SrvTarget, sorted in order of preference. (That is, you should attempt to connect to the first target first, then the second if the first fails, etc.)

If the DNS resolution fails, error (if non-None) will be set to a value from Gio.ResolverError and None will be returned.

If cancellable is non-None, it can be used to cancel the operation, in which case error (if non-None) will be set to Gio.IOErrorEnum.CANCELLED.

If you are planning to connect to the service, it is usually easier to create a Gio.NetworkService and use its Gio.SocketConnectable interface.

New in version 2.22.

lookup_service_async(service, protocol, domain, cancellable, callback, *user_data)[source]
Parameters:

Begins asynchronously performing a DNS SRV lookup for the given service and protocol in the given domain, and eventually calls callback, which must call Gio.Resolver.lookup_service_finish() to get the final result. See Gio.Resolver.lookup_service() for more details.

New in version 2.22.

lookup_service_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – the result passed to your Gio.AsyncReadyCallback

Raises:

GLib.Error

Returns:

a non-empty GLib.List of Gio.SrvTarget, or None on error. See Gio.Resolver.lookup_service() for more details.

Return type:

[Gio.SrvTarget]

Retrieves the result of a previous call to Gio.Resolver.lookup_service_async().

If the DNS resolution failed, error (if non-None) will be set to a value from Gio.ResolverError. If the operation was cancelled, error will be set to Gio.IOErrorEnum.CANCELLED.

New in version 2.22.

set_default()[source]

Sets self to be the application’s default resolver (reffing self, and unreffing the previous default resolver, if any). Future calls to Gio.Resolver.get_default() will return this resolver.

This can be used if an application wants to perform any sort of DNS caching or “pinning”; it can implement its own Gio.Resolver that calls the original default resolver for DNS operations, and implements its own cache policies on top of that, and then set itself as the default resolver for all later code to use.

New in version 2.22.

set_timeout(timeout_ms)[source]
Parameters:

timeout_ms (int) – timeout in milliseconds, or 0 for no timeouts

Set the timeout applied to all resolver lookups. See Gio.Resolver :timeout.

New in version 2.78.

do_lookup_by_address(address, cancellable) virtual
Parameters:
Returns:

a hostname (either ASCII-only, or in ASCII-encoded form), or None on error.

Return type:

str

Synchronously reverse-resolves address to determine its associated hostname.

If the DNS resolution fails, error (if non-None) will be set to a value from Gio.ResolverError.

If cancellable is non-None, it can be used to cancel the operation, in which case error (if non-None) will be set to Gio.IOErrorEnum.CANCELLED.

New in version 2.22.

do_lookup_by_address_async(address, cancellable, callback, *user_data) virtual
Parameters:

Begins asynchronously reverse-resolving address to determine its associated hostname, and eventually calls callback, which must call Gio.Resolver.lookup_by_address_finish() to get the final result.

New in version 2.22.

do_lookup_by_address_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – the result passed to your Gio.AsyncReadyCallback

Returns:

a hostname (either ASCII-only, or in ASCII-encoded form), or None on error.

Return type:

str

Retrieves the result of a previous call to Gio.Resolver.lookup_by_address_async().

If the DNS resolution failed, error (if non-None) will be set to a value from Gio.ResolverError. If the operation was cancelled, error will be set to Gio.IOErrorEnum.CANCELLED.

New in version 2.22.

do_lookup_by_name(hostname, cancellable) virtual
Parameters:
Returns:

a non-empty GLib.List of Gio.InetAddress, or None on error. You must unref each of the addresses and free the list when you are done with it. (You can use g_resolver_free_addresses() to do this.)

Return type:

[Gio.InetAddress]

Synchronously resolves hostname to determine its associated IP address(es). hostname may be an ASCII-only or UTF-8 hostname, or the textual form of an IP address (in which case this just becomes a wrapper around Gio.InetAddress.new_from_string()).

On success, Gio.Resolver.lookup_by_name() will return a non-empty GLib.List of Gio.InetAddress, sorted in order of preference and guaranteed to not contain duplicates. That is, if using the result to connect to hostname, you should attempt to connect to the first address first, then the second if the first fails, etc. If you are using the result to listen on a socket, it is appropriate to add each result using e.g. Gio.SocketListener.add_address().

If the DNS resolution fails, error (if non-None) will be set to a value from Gio.ResolverError and None will be returned.

If cancellable is non-None, it can be used to cancel the operation, in which case error (if non-None) will be set to Gio.IOErrorEnum.CANCELLED.

If you are planning to connect to a socket on the resolved IP address, it may be easier to create a Gio.NetworkAddress and use its Gio.SocketConnectable interface.

New in version 2.22.

do_lookup_by_name_async(hostname, cancellable, callback, *user_data) virtual
Parameters:

Begins asynchronously resolving hostname to determine its associated IP address(es), and eventually calls callback, which must call Gio.Resolver.lookup_by_name_finish() to get the result. See Gio.Resolver.lookup_by_name() for more details.

New in version 2.22.

do_lookup_by_name_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – the result passed to your Gio.AsyncReadyCallback

Returns:

a GLib.List of Gio.InetAddress, or None on error. See Gio.Resolver.lookup_by_name() for more details.

Return type:

[Gio.InetAddress]

Retrieves the result of a call to Gio.Resolver.lookup_by_name_async().

If the DNS resolution failed, error (if non-None) will be set to a value from Gio.ResolverError. If the operation was cancelled, error will be set to Gio.IOErrorEnum.CANCELLED.

New in version 2.22.

do_lookup_by_name_with_flags(hostname, flags, cancellable) virtual
Parameters:
Returns:

a non-empty GLib.List of Gio.InetAddress, or None on error. You must unref each of the addresses and free the list when you are done with it. (You can use g_resolver_free_addresses() to do this.)

Return type:

[Gio.InetAddress]

This differs from Gio.Resolver.lookup_by_name() in that you can modify the lookup behavior with flags. For example this can be used to limit results with Gio.ResolverNameLookupFlags.IPV4_ONLY.

New in version 2.60.

do_lookup_by_name_with_flags_async(hostname, flags, cancellable, callback, *user_data) virtual
Parameters:

Begins asynchronously resolving hostname to determine its associated IP address(es), and eventually calls callback, which must call Gio.Resolver.lookup_by_name_with_flags_finish() to get the result. See Gio.Resolver.lookup_by_name() for more details.

New in version 2.60.

do_lookup_by_name_with_flags_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – the result passed to your Gio.AsyncReadyCallback

Returns:

a GLib.List of Gio.InetAddress, or None on error. See Gio.Resolver.lookup_by_name() for more details.

Return type:

[Gio.InetAddress]

Retrieves the result of a call to Gio.Resolver.lookup_by_name_with_flags_async().

If the DNS resolution failed, error (if non-None) will be set to a value from Gio.ResolverError. If the operation was cancelled, error will be set to Gio.IOErrorEnum.CANCELLED.

New in version 2.60.

do_lookup_records(rrname, record_type, cancellable) virtual
Parameters:
Returns:

a non-empty GLib.List of GLib.Variant, or None on error. You must free each of the records and the list when you are done with it. (You can use g_list_free_full() with GLib.Variant.unref() to do this.)

Return type:

[GLib.Variant]

Synchronously performs a DNS record lookup for the given rrname and returns a list of records as GLib.Variant tuples. See Gio.ResolverRecordType for information on what the records contain for each record_type.

If the DNS resolution fails, error (if non-None) will be set to a value from Gio.ResolverError and None will be returned.

If cancellable is non-None, it can be used to cancel the operation, in which case error (if non-None) will be set to Gio.IOErrorEnum.CANCELLED.

New in version 2.34.

do_lookup_records_async(rrname, record_type, cancellable, callback, *user_data) virtual
Parameters:

Begins asynchronously performing a DNS lookup for the given rrname, and eventually calls callback, which must call Gio.Resolver.lookup_records_finish() to get the final result. See Gio.Resolver.lookup_records() for more details.

New in version 2.34.

do_lookup_records_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – the result passed to your Gio.AsyncReadyCallback

Returns:

a non-empty GLib.List of GLib.Variant, or None on error. You must free each of the records and the list when you are done with it. (You can use g_list_free_full() with GLib.Variant.unref() to do this.)

Return type:

[GLib.Variant]

Retrieves the result of a previous call to Gio.Resolver.lookup_records_async(). Returns a non-empty list of records as GLib.Variant tuples. See Gio.ResolverRecordType for information on what the records contain.

If the DNS resolution failed, error (if non-None) will be set to a value from Gio.ResolverError. If the operation was cancelled, error will be set to Gio.IOErrorEnum.CANCELLED.

New in version 2.34.

do_lookup_service_async(rrname, cancellable, callback, *user_data) virtual
Parameters:
do_lookup_service_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – the result passed to your Gio.AsyncReadyCallback

Returns:

a non-empty GLib.List of Gio.SrvTarget, or None on error. See Gio.Resolver.lookup_service() for more details.

Return type:

[Gio.SrvTarget]

Retrieves the result of a previous call to Gio.Resolver.lookup_service_async().

If the DNS resolution failed, error (if non-None) will be set to a value from Gio.ResolverError. If the operation was cancelled, error will be set to Gio.IOErrorEnum.CANCELLED.

New in version 2.22.

do_reload() virtual

Signal Details

Gio.Resolver.signals.reload(resolver)
Signal Name:

reload

Flags:

RUN_LAST

Parameters:

resolver (Gio.Resolver) – The object which received the signal

Emitted when the resolver notices that the system resolver configuration has changed.

Property Details

Gio.Resolver.props.timeout
Name:

timeout

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The timeout applied to all resolver lookups, in milliseconds.

This may be changed through the lifetime of the Gio.Resolver. The new value will apply to any lookups started after the change, but not to any already-ongoing lookups.

If this is 0, no timeout is applied to lookups.

No timeout was applied to lookups before this property was added in GLib 2.78.

New in version 2.78.