Class SocketAddressEnumerator

All Implemented Interfaces:
Proxy
Direct Known Subclasses:
ProxyAddressEnumerator, SocketAddressEnumerator.SocketAddressEnumerator$Impl

@Generated("org.javagi.JavaGI") public abstract class SocketAddressEnumerator extends GObject

GSocketAddressEnumerator is an enumerator type for SocketAddress instances. It is returned by enumeration functions such as SocketConnectable.enumerate(), which returns a GSocketAddressEnumerator to list each SocketAddress which could be used to connect to that SocketConnectable.

Enumeration is typically a blocking operation, so the asynchronous methods nextAsync(Cancellable, AsyncReadyCallback) and nextFinish(AsyncResult) should be used where possible.

Each GSocketAddressEnumerator can only be enumerated once. Once next(Cancellable) has returned NULL, further enumeration with that GSocketAddressEnumerator is not possible, and it can be unreffed.

  • Constructor Details

    • SocketAddressEnumerator

      public SocketAddressEnumerator(MemorySegment address)
      Create a SocketAddressEnumerator instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • SocketAddressEnumerator

      public SocketAddressEnumerator()
      Create a new SocketAddressEnumerator.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the SocketAddressEnumerator class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected SocketAddressEnumerator asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • next

      public @Nullable SocketAddress next(@Nullable Cancellable cancellable) throws GErrorException

      Retrieves the next GSocketAddress from enumerator. Note that this may block for some amount of time. (Eg, a GNetworkAddress may need to do a DNS lookup before it can return an address.) Use g_socket_address_enumerator_next_async() if you need to avoid blocking.

      If this SocketAddressEnumerator is expected to yield addresses, but for some reason is unable to (eg, because of a DNS error), then the first call to g_socket_address_enumerator_next() will return an appropriate error in *error. However, if the first call to g_socket_address_enumerator_next() succeeds, then any further internal errors (other than cancellable being triggered) will be ignored.

      Parameters:
      cancellable - optional GCancellable object, null to ignore.
      Returns:
      a GSocketAddress (owned by the caller), or null on error (in which case *error will be set) or if there are no more addresses.
      Throws:
      GErrorException - see GError
    • nextAsync

      public void nextAsync(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously retrieves the next GSocketAddress from this SocketAddressEnumerator and then calls callback, which must call g_socket_address_enumerator_next_finish() to get the result.

      It is an error to call this multiple times before the previous callback has finished.

      Parameters:
      cancellable - optional GCancellable object, null to ignore.
      callback - a GAsyncReadyCallback to call when the request is satisfied
    • nextFinish

      public @Nullable SocketAddress nextFinish(AsyncResult result) throws GErrorException
      Retrieves the result of a completed call to g_socket_address_enumerator_next_async(). See g_socket_address_enumerator_next() for more information about error handling.
      Parameters:
      result - a GAsyncResult
      Returns:
      a GSocketAddress (owned by the caller), or null on error (in which case *error will be set) or if there are no more addresses.
      Throws:
      GErrorException - see GError