|
Packit |
ae235b |
/* GIO - GLib Input, Output and Streaming Library
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Copyright (C) 2008 Red Hat, Inc.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* This library is free software; you can redistribute it and/or
|
|
Packit |
ae235b |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
ae235b |
* License as published by the Free Software Foundation; either
|
|
Packit |
ae235b |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
ae235b |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
ae235b |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
ae235b |
* Lesser General Public License for more details.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* You should have received a copy of the GNU Lesser General
|
|
Packit |
ae235b |
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
#include "config.h"
|
|
Packit |
ae235b |
#include "gsocketaddressenumerator.h"
|
|
Packit |
ae235b |
#include "glibintl.h"
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
#include "gtask.h"
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
G_DEFINE_ABSTRACT_TYPE (GSocketAddressEnumerator, g_socket_address_enumerator, G_TYPE_OBJECT)
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void g_socket_address_enumerator_real_next_async (GSocketAddressEnumerator *enumerator,
|
|
Packit |
ae235b |
GCancellable *cancellable,
|
|
Packit |
ae235b |
GAsyncReadyCallback callback,
|
|
Packit |
ae235b |
gpointer user_data);
|
|
Packit |
ae235b |
static GSocketAddress *g_socket_address_enumerator_real_next_finish (GSocketAddressEnumerator *enumerator,
|
|
Packit |
ae235b |
GAsyncResult *result,
|
|
Packit |
ae235b |
GError **error);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
g_socket_address_enumerator_init (GSocketAddressEnumerator *enumerator)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
g_socket_address_enumerator_class_init (GSocketAddressEnumeratorClass *enumerator_class)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
enumerator_class->next_async = g_socket_address_enumerator_real_next_async;
|
|
Packit |
ae235b |
enumerator_class->next_finish = g_socket_address_enumerator_real_next_finish;
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/**
|
|
Packit |
ae235b |
* g_socket_address_enumerator_next:
|
|
Packit |
ae235b |
* @enumerator: a #GSocketAddressEnumerator
|
|
Packit |
ae235b |
* @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
|
|
Packit |
ae235b |
* @error: a #GError.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Retrieves the next #GSocketAddress from @enumerator. Note that this
|
|
Packit |
ae235b |
* may block for some amount of time. (Eg, a #GNetworkAddress may need
|
|
Packit |
ae235b |
* to do a DNS lookup before it can return an address.) Use
|
|
Packit |
ae235b |
* g_socket_address_enumerator_next_async() if you need to avoid
|
|
Packit |
ae235b |
* blocking.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* If @enumerator is expected to yield addresses, but for some reason
|
|
Packit |
ae235b |
* is unable to (eg, because of a DNS error), then the first call to
|
|
Packit |
ae235b |
* g_socket_address_enumerator_next() will return an appropriate error
|
|
Packit |
ae235b |
* in *@error. However, if the first call to
|
|
Packit |
ae235b |
* g_socket_address_enumerator_next() succeeds, then any further
|
|
Packit |
ae235b |
* internal errors (other than @cancellable being triggered) will be
|
|
Packit |
ae235b |
* ignored.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Returns: (transfer full): a #GSocketAddress (owned by the caller), or %NULL on
|
|
Packit |
ae235b |
* error (in which case *@error will be set) or if there are no
|
|
Packit |
ae235b |
* more addresses.
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
GSocketAddress *
|
|
Packit |
ae235b |
g_socket_address_enumerator_next (GSocketAddressEnumerator *enumerator,
|
|
Packit |
ae235b |
GCancellable *cancellable,
|
|
Packit |
ae235b |
GError **error)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GSocketAddressEnumeratorClass *klass;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_return_val_if_fail (G_IS_SOCKET_ADDRESS_ENUMERATOR (enumerator), NULL);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
klass = G_SOCKET_ADDRESS_ENUMERATOR_GET_CLASS (enumerator);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
return (* klass->next) (enumerator, cancellable, error);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* Default implementation just calls the synchronous method; this can
|
|
Packit |
ae235b |
* be used if the implementation already knows all of its addresses,
|
|
Packit |
ae235b |
* and so the synchronous method will never block.
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
g_socket_address_enumerator_real_next_async (GSocketAddressEnumerator *enumerator,
|
|
Packit |
ae235b |
GCancellable *cancellable,
|
|
Packit |
ae235b |
GAsyncReadyCallback callback,
|
|
Packit |
ae235b |
gpointer user_data)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GTask *task;
|
|
Packit |
ae235b |
GSocketAddress *address;
|
|
Packit |
ae235b |
GError *error = NULL;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
task = g_task_new (enumerator, NULL, callback, user_data);
|
|
Packit |
ae235b |
g_task_set_source_tag (task, g_socket_address_enumerator_real_next_async);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
address = g_socket_address_enumerator_next (enumerator, cancellable, &error);
|
|
Packit |
ae235b |
if (error)
|
|
Packit |
ae235b |
g_task_return_error (task, error);
|
|
Packit |
ae235b |
else
|
|
Packit |
ae235b |
g_task_return_pointer (task, address, g_object_unref);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_object_unref (task);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/**
|
|
Packit |
ae235b |
* g_socket_address_enumerator_next_async:
|
|
Packit |
ae235b |
* @enumerator: a #GSocketAddressEnumerator
|
|
Packit |
ae235b |
* @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
|
|
Packit |
ae235b |
* @callback: (scope async): a #GAsyncReadyCallback to call when the request
|
|
Packit |
ae235b |
* is satisfied
|
|
Packit |
ae235b |
* @user_data: (closure): the data to pass to callback function
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Asynchronously retrieves the next #GSocketAddress from @enumerator
|
|
Packit |
ae235b |
* and then calls @callback, which must call
|
|
Packit |
ae235b |
* g_socket_address_enumerator_next_finish() to get the result.
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
void
|
|
Packit |
ae235b |
g_socket_address_enumerator_next_async (GSocketAddressEnumerator *enumerator,
|
|
Packit |
ae235b |
GCancellable *cancellable,
|
|
Packit |
ae235b |
GAsyncReadyCallback callback,
|
|
Packit |
ae235b |
gpointer user_data)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GSocketAddressEnumeratorClass *klass;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_return_if_fail (G_IS_SOCKET_ADDRESS_ENUMERATOR (enumerator));
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
klass = G_SOCKET_ADDRESS_ENUMERATOR_GET_CLASS (enumerator);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
(* klass->next_async) (enumerator, cancellable, callback, user_data);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static GSocketAddress *
|
|
Packit |
ae235b |
g_socket_address_enumerator_real_next_finish (GSocketAddressEnumerator *enumerator,
|
|
Packit |
ae235b |
GAsyncResult *result,
|
|
Packit |
ae235b |
GError **error)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
g_return_val_if_fail (g_task_is_valid (result, enumerator), NULL);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
return g_task_propagate_pointer (G_TASK (result), error);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/**
|
|
Packit |
ae235b |
* g_socket_address_enumerator_next_finish:
|
|
Packit |
ae235b |
* @enumerator: a #GSocketAddressEnumerator
|
|
Packit |
ae235b |
* @result: a #GAsyncResult
|
|
Packit |
ae235b |
* @error: a #GError
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Retrieves the result of a completed call to
|
|
Packit |
ae235b |
* g_socket_address_enumerator_next_async(). See
|
|
Packit |
ae235b |
* g_socket_address_enumerator_next() for more information about
|
|
Packit |
ae235b |
* error handling.
|
|
Packit |
ae235b |
*
|
|
Packit |
ae235b |
* Returns: (transfer full): a #GSocketAddress (owned by the caller), or %NULL on
|
|
Packit |
ae235b |
* error (in which case *@error will be set) or if there are no
|
|
Packit |
ae235b |
* more addresses.
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
GSocketAddress *
|
|
Packit |
ae235b |
g_socket_address_enumerator_next_finish (GSocketAddressEnumerator *enumerator,
|
|
Packit |
ae235b |
GAsyncResult *result,
|
|
Packit |
ae235b |
GError **error)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GSocketAddressEnumeratorClass *klass;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_return_val_if_fail (G_IS_SOCKET_ADDRESS_ENUMERATOR (enumerator), NULL);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
klass = G_SOCKET_ADDRESS_ENUMERATOR_GET_CLASS (enumerator);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
return (* klass->next_finish) (enumerator, result, error);
|
|
Packit |
ae235b |
}
|