Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: NetworkMonitor

[16:7] extends: object

GNetworkMonitor provides an easy-to-use cross-platform API for monitoring network connectivity. On Linux, the available implementations are based on the kernel's netlink interface and on NetworkManager. There is also an implementation for use inside Flatpak sandboxes.

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • NetworkMonitor (Handle = null)

    Creates a new NetworkMonitor by wrapping a native handle or another wrapper.

    • @p Handle is the native handle or another wrapper whose handle to adopt.
  • toNativeHandle (Source)

    Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from fn.call(...), another generated wrapper exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • connectSignal (string Name, CallbackObj)

    Connects one generated callback wrapper to a named signal.

    • @p Name is the signal name.
    • @p CallbackObj is the generated callback wrapper to connect.
    • @r The connected handler id.
  • disconnectSignalHandler (int HandlerId)

    Disconnects one retained signal handler id.

    • @p HandlerId is the signal handler id to disconnect.
    • @r None.
  • setOnNetworkchanged (callback Fn, UserData = null)

    Emitted when the network configuration changes.

    • @p Fn is the Aussom callback.
    • @p Fn is called with (NetworkMonitor Self, bool Network_available).
    • @p UserData is retained and passed through to the generated callback wrapper when provided.
    • @r The connected handler id.
  • can_reach (object connectable, object cancellable)

    Attempts to determine whether or not the host pointed to by @connectable can be reached, without actually trying to connect to it. This may return %TRUE even when #GNetworkMonitor:network-available is %FALSE, if, for example, @monitor can determine that @connectable refers to a host on a local network. If @monitor believes that an attempt to connect to

    • @connectable will succeed, it will return %TRUE. Otherwise, it will return %FALSE and set @error to an appropriate error (such as %G_IO_ERROR_HOST_UNREACHABLE). Note that although this does not attempt to connect to @connectable, it may still block for a brief period of time (eg, trying to do multicast DNS on the local network), so if you do not want to block, you should use g_network_monitor_can_reach_async().
    • @p connectable is a #GSocketConnectable.
    • @p cancellable is a #GCancellable, or %NULL.
  • can_reach_finish (object result)

    Finishes an async network connectivity test. See g_network_monitor_can_reach_async().

    • @p result is a #GAsyncResult.
  • get_connectivity ()

    Gets a more detailed networking state than g_network_monitor_get_network_available(). If #GNetworkMonitor:network-available is %FALSE, then the connectivity state will be %G_NETWORK_CONNECTIVITY_LOCAL. If #GNetworkMonitor:network-available is %TRUE, then the connectivity state will be %G_NETWORK_CONNECTIVITY_FULL (if there is full Internet connectivity), %G_NETWORK_CONNECTIVITY_LIMITED (if the host has a default route, but appears to be unable to actually reach the full Internet), or %G_NETWORK_CONNECTIVITY_PORTAL (if the host is trapped behind a "captive portal" that requires some sort of login or acknowledgement before allowing full Internet access). Note that in the case of %G_NETWORK_CONNECTIVITY_LIMITED and %G_NETWORK_CONNECTIVITY_PORTAL, it is possible that some sites are reachable but others are not. In this case, applications can attempt to connect to remote servers, but should gracefully fall back to their "offline" behavior if the connection attempt fails.

  • get_network_available ()

    Checks if the network is available. "Available" here means that the system has a default route available for at least one of IPv4 or IPv6. It does not necessarily imply that the public Internet is reachable. See #GNetworkMonitor:network-available for more details.

  • get_network_metered ()

    Checks if the network is metered. See #GNetworkMonitor:network-metered for more details.

class: NetworkMonitorMeta

[298:14] static extends: object

Generated metadata helpers for NetworkMonitor interface surfaces.

Methods

  • properties ()

    Returns property metadata for NetworkMonitor.

    • @r A list.
  • signals ()

    Returns signal metadata for NetworkMonitor.

    • @r A list.

class: NetworkMonitorNetworkchangedCallback

[227:7] extends: object

Generated low-level callback wrapper for GIR callback network-changed.

Members

  • callbackObj
  • userFn
  • userData
  • hasUserData

Methods

  • NetworkMonitorNetworkchangedCallback (callback Fn, UserData = null)

    Creates one native callback wrapper. The wrapper owns a trampoline that converts native pointers into generated wrapper objects before invoking Fn.

    • @p Fn is the Aussom callback implementation.
    • @p UserData is retained and passed through to Fn on each invocation when provided.
  • trampoline (nativeSelf, network_available, nativeUserData)

    Internal trampoline. Converts native pointer arguments into generated wrapper instances, then invokes the user's callback.

  • callback ()

    Returns the wrapped NativeCallback.

  • handle ()

    Returns the callback as a NativeHandle.

  • close ()

    Closes the underlying NativeCallback.

  • isClosed ()

    Returns true when the callback has been closed.