resolve_async
Description:
Asynchronously resolves the missing half of this (its IP address if it was created with Address, or its hostname if it was created with Address.from_sockaddr or Address.any.
)
If cancellable
is non-%NULL, it can be used to cancel the resolution. callback
will still be invoked in this case,
with a status of CANCELLED.
It is safe to call this more than once on a given address, from the same thread, with the same async_context
(and doing so will
not result in redundant DNS queries being made). But it is not safe to call from multiple threads, or with different async_contexts
, or mixed with calls to resolve_sync.
Example: Resolve an address, async:
public static int main (string[] args) {
MainLoop loop = new MainLoop ();
MainContext context = loop.get_context ();
Soup.Address address = new Soup.Address ("www.gnome.org", 80);
Cancellable cancellable = new Cancellable ();
// Use cancellable.cancel () to abort the resolution
address.resolve_async (context, cancellable, (addr, status) => {
switch (status) {
case Soup.Status.OK:
print ("Resolved! %s\n", addr.get_physical ());
break;
case Soup.Status.CANT_RESOLVE:
print ("Error: Unable to resolve destination host name.\n");
break;
case Soup.Status.CANCELLED:
print ("Error: Message was cancelled locally.\n");
break;
default:
assert_not_reached ();
}
loop.quit ();
});
loop.run ();
return 0;
}
valac --pkg libsoup-2.4 message-resolve-async.vala
Parameters:
this |
a Address |
async_context |
the MainContext to call |
cancellable |
a Cancellable object, or |
callback |
callback to call with the result |
user_data |
data for |