Gio.Resolver¶
- Subclasses:
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/en |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Emitted when the resolver notices that the system resolver configuration has changed. |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_instance |
r |
Class Details¶
- class Gio.Resolver(**kwargs)¶
- Bases:
- Abstract:
Yes
- Structure:
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:
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:
Get the timeout applied to all resolver lookups. See
Gio.Resolver
:timeout
.New in version 2.78.
- lookup_by_address(address, cancellable)[source]¶
- Parameters:
address (
Gio.InetAddress
) – the address to reverse-resolvecancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
- Raises:
- Returns:
a hostname (either ASCII-only, or in ASCII-encoded form), or
None
on error.- Return type:
Synchronously reverse-resolves address to determine its associated hostname.
If the DNS resolution fails, error (if non-
None
) will be set to a value fromGio.ResolverError
.If cancellable is non-
None
, it can be used to cancel the operation, in which case error (if non-None
) will be set toGio.IOErrorEnum.CANCELLED
.New in version 2.22.
- lookup_by_address_async(address, cancellable, callback, *user_data)[source]¶
- Parameters:
address (
Gio.InetAddress
) – the address to reverse-resolvecancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
callback (
Gio.AsyncReadyCallback
orNone
) – callback to call after resolution completes
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 yourGio.AsyncReadyCallback
- Raises:
- Returns:
a hostname (either ASCII-only, or in ASCII-encoded form), or
None
on error.- Return type:
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 fromGio.ResolverError
. If the operation was cancelled, error will be set toGio.IOErrorEnum.CANCELLED
.New in version 2.22.
- lookup_by_name(hostname, cancellable)[source]¶
- Parameters:
hostname (
str
) – the hostname to look upcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
- Raises:
- Returns:
a non-empty
GLib.List
ofGio.InetAddress
, orNone
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:
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-emptyGLib.List
ofGio.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 fromGio.ResolverError
andNone
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 toGio.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 itsGio.SocketConnectable
interface.New in version 2.22.
- lookup_by_name_async(hostname, cancellable, callback, *user_data)[source]¶
- Parameters:
hostname (
str
) – the hostname to look up the address ofcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
callback (
Gio.AsyncReadyCallback
orNone
) – callback to call after resolution completes
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. SeeGio.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 yourGio.AsyncReadyCallback
- Raises:
- Returns:
a
GLib.List
ofGio.InetAddress
, orNone
on error. SeeGio.Resolver.lookup_by_name
() for more details.- Return type:
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 fromGio.ResolverError
. If the operation was cancelled, error will be set toGio.IOErrorEnum.CANCELLED
.New in version 2.22.
- lookup_by_name_with_flags(hostname, flags, cancellable)[source]¶
- Parameters:
hostname (
str
) – the hostname to look upflags (
Gio.ResolverNameLookupFlags
) – extraGio.ResolverNameLookupFlags
for the lookupcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
- Raises:
- Returns:
a non-empty
GLib.List
ofGio.InetAddress
, orNone
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:
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 withGio.ResolverNameLookupFlags.IPV4_ONLY
.New in version 2.60.
- lookup_by_name_with_flags_async(hostname, flags, cancellable, callback, *user_data)[source]¶
- Parameters:
hostname (
str
) – the hostname to look up the address offlags (
Gio.ResolverNameLookupFlags
) – extraGio.ResolverNameLookupFlags
for the lookupcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
callback (
Gio.AsyncReadyCallback
orNone
) – callback to call after resolution completes
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. SeeGio.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 yourGio.AsyncReadyCallback
- Raises:
- Returns:
a
GLib.List
ofGio.InetAddress
, orNone
on error. SeeGio.Resolver.lookup_by_name
() for more details.- Return type:
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 fromGio.ResolverError
. If the operation was cancelled, error will be set toGio.IOErrorEnum.CANCELLED
.New in version 2.60.
- lookup_records(rrname, record_type, cancellable)[source]¶
- Parameters:
rrname (
str
) – the DNS name to look up the record forrecord_type (
Gio.ResolverRecordType
) – the type of DNS record to look upcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
- Raises:
- Returns:
a non-empty
GLib.List
ofGLib.Variant
, orNone
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() withGLib.Variant.unref
() to do this.)- Return type:
Synchronously performs a DNS record lookup for the given rrname and returns a list of records as
GLib.Variant
tuples. SeeGio.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 fromGio.ResolverError
andNone
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 toGio.IOErrorEnum.CANCELLED
.New in version 2.34.
- lookup_records_async(rrname, record_type, cancellable, callback, *user_data)[source]¶
- Parameters:
rrname (
str
) – the DNS name to look up the record forrecord_type (
Gio.ResolverRecordType
) – the type of DNS record to look upcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
callback (
Gio.AsyncReadyCallback
orNone
) – callback to call after resolution completes
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. SeeGio.Resolver.lookup_records
() for more details.New in version 2.34.
- lookup_records_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – the result passed to yourGio.AsyncReadyCallback
- Raises:
- Returns:
a non-empty
GLib.List
ofGLib.Variant
, orNone
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() withGLib.Variant.unref
() to do this.)- Return type:
Retrieves the result of a previous call to
Gio.Resolver.lookup_records_async
(). Returns a non-empty list of records asGLib.Variant
tuples. SeeGio.ResolverRecordType
for information on what the records contain.If the DNS resolution failed, error (if non-
None
) will be set to a value fromGio.ResolverError
. If the operation was cancelled, error will be set toGio.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 incancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
- Raises:
- Returns:
a non-empty
GLib.List
ofGio.SrvTarget
, orNone
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:
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-emptyGLib.List
ofGio.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 fromGio.ResolverError
andNone
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 toGio.IOErrorEnum.CANCELLED
.If you are planning to connect to the service, it is usually easier to create a
Gio.NetworkService
and use itsGio.SocketConnectable
interface.New in version 2.22.
- lookup_service_async(service, protocol, domain, cancellable, callback, *user_data)[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 incancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
callback (
Gio.AsyncReadyCallback
orNone
) – callback to call after resolution completes
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. SeeGio.Resolver.lookup_service
() for more details.New in version 2.22.
- lookup_service_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – the result passed to yourGio.AsyncReadyCallback
- Raises:
- Returns:
a non-empty
GLib.List
ofGio.SrvTarget
, orNone
on error. SeeGio.Resolver.lookup_service
() for more details.- Return type:
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 fromGio.ResolverError
. If the operation was cancelled, error will be set toGio.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, or0
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:
address (
Gio.InetAddress
) – the address to reverse-resolvecancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
- Returns:
a hostname (either ASCII-only, or in ASCII-encoded form), or
None
on error.- Return type:
Synchronously reverse-resolves address to determine its associated hostname.
If the DNS resolution fails, error (if non-
None
) will be set to a value fromGio.ResolverError
.If cancellable is non-
None
, it can be used to cancel the operation, in which case error (if non-None
) will be set toGio.IOErrorEnum.CANCELLED
.New in version 2.22.
- do_lookup_by_address_async(address, cancellable, callback, *user_data) virtual¶
- Parameters:
address (
Gio.InetAddress
) – the address to reverse-resolvecancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
callback (
Gio.AsyncReadyCallback
orNone
) – callback to call after resolution completes
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 yourGio.AsyncReadyCallback
- Returns:
a hostname (either ASCII-only, or in ASCII-encoded form), or
None
on error.- Return type:
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 fromGio.ResolverError
. If the operation was cancelled, error will be set toGio.IOErrorEnum.CANCELLED
.New in version 2.22.
- do_lookup_by_name(hostname, cancellable) virtual¶
- Parameters:
hostname (
str
) – the hostname to look upcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
- Returns:
a non-empty
GLib.List
ofGio.InetAddress
, orNone
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:
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-emptyGLib.List
ofGio.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 fromGio.ResolverError
andNone
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 toGio.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 itsGio.SocketConnectable
interface.New in version 2.22.
- do_lookup_by_name_async(hostname, cancellable, callback, *user_data) virtual¶
- Parameters:
hostname (
str
) – the hostname to look up the address ofcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
callback (
Gio.AsyncReadyCallback
orNone
) – callback to call after resolution completes
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. SeeGio.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 yourGio.AsyncReadyCallback
- Returns:
a
GLib.List
ofGio.InetAddress
, orNone
on error. SeeGio.Resolver.lookup_by_name
() for more details.- Return type:
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 fromGio.ResolverError
. If the operation was cancelled, error will be set toGio.IOErrorEnum.CANCELLED
.New in version 2.22.
- do_lookup_by_name_with_flags(hostname, flags, cancellable) virtual¶
- Parameters:
hostname (
str
) – the hostname to look upflags (
Gio.ResolverNameLookupFlags
) – extraGio.ResolverNameLookupFlags
for the lookupcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
- Returns:
a non-empty
GLib.List
ofGio.InetAddress
, orNone
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:
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 withGio.ResolverNameLookupFlags.IPV4_ONLY
.New in version 2.60.
- do_lookup_by_name_with_flags_async(hostname, flags, cancellable, callback, *user_data) virtual¶
- Parameters:
hostname (
str
) – the hostname to look up the address offlags (
Gio.ResolverNameLookupFlags
) – extraGio.ResolverNameLookupFlags
for the lookupcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
callback (
Gio.AsyncReadyCallback
orNone
) – callback to call after resolution completes
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. SeeGio.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 yourGio.AsyncReadyCallback
- Returns:
a
GLib.List
ofGio.InetAddress
, orNone
on error. SeeGio.Resolver.lookup_by_name
() for more details.- Return type:
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 fromGio.ResolverError
. If the operation was cancelled, error will be set toGio.IOErrorEnum.CANCELLED
.New in version 2.60.
- do_lookup_records(rrname, record_type, cancellable) virtual¶
- Parameters:
rrname (
str
) – the DNS name to look up the record forrecord_type (
Gio.ResolverRecordType
) – the type of DNS record to look upcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
- Returns:
a non-empty
GLib.List
ofGLib.Variant
, orNone
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() withGLib.Variant.unref
() to do this.)- Return type:
Synchronously performs a DNS record lookup for the given rrname and returns a list of records as
GLib.Variant
tuples. SeeGio.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 fromGio.ResolverError
andNone
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 toGio.IOErrorEnum.CANCELLED
.New in version 2.34.
- do_lookup_records_async(rrname, record_type, cancellable, callback, *user_data) virtual¶
- Parameters:
rrname (
str
) – the DNS name to look up the record forrecord_type (
Gio.ResolverRecordType
) – the type of DNS record to look upcancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
, orNone
callback (
Gio.AsyncReadyCallback
orNone
) – callback to call after resolution completes
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. SeeGio.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 yourGio.AsyncReadyCallback
- Returns:
a non-empty
GLib.List
ofGLib.Variant
, orNone
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() withGLib.Variant.unref
() to do this.)- Return type:
Retrieves the result of a previous call to
Gio.Resolver.lookup_records_async
(). Returns a non-empty list of records asGLib.Variant
tuples. SeeGio.ResolverRecordType
for information on what the records contain.If the DNS resolution failed, error (if non-
None
) will be set to a value fromGio.ResolverError
. If the operation was cancelled, error will be set toGio.IOErrorEnum.CANCELLED
.New in version 2.34.
- do_lookup_service_async(rrname, cancellable, callback, *user_data) virtual¶
- Parameters:
rrname (
str
) –cancellable (
Gio.Cancellable
orNone
) –callback (
Gio.AsyncReadyCallback
orNone
) –
- do_lookup_service_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – the result passed to yourGio.AsyncReadyCallback
- Returns:
a non-empty
GLib.List
ofGio.SrvTarget
, orNone
on error. SeeGio.Resolver.lookup_service
() for more details.- Return type:
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 fromGio.ResolverError
. If the operation was cancelled, error will be set toGio.IOErrorEnum.CANCELLED
.New in version 2.22.
- do_reload() virtual¶
Signal Details¶
- Gio.Resolver.signals.reload(resolver)¶
- Signal Name:
reload
- Flags:
- 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:
- Default Value:
0
- Flags:
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.