Module: Gio::NetworkMonitor

Defined in:
(unknown)

Overview

GNetwork::Monitor 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.

Instance Method Summary collapse

Instance Method Details

#can_reach(connectable, cancellable) ⇒ TrueClass

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 GNetwork::Monitor: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().

Parameters:

Returns:

  • (TrueClass)

    true if connectable is reachable, false if not.

#can_reach_async(connectable, cancellable, callback, user_data) ⇒ nil

Asynchronously attempts to determine whether or not the host pointed to by connectable can be reached, without actually trying to connect to it.

For more details, see g_network_monitor_can_reach().

When the operation is finished, callback will be called. You can then call g_network_monitor_can_reach_finish() to get the result of the operation.

Parameters:

  • connectable (Gio::SocketConnectable)

    a GSocket::Connectable

  • cancellable (Gio::Cancellable)

    a #GCancellable, or nil

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the request is satisfied

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#can_reach_finish(result) ⇒ TrueClass

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

Parameters:

Returns:

  • (TrueClass)

    true if network is reachable, false if not.

#connectivityGio::NetworkConnectivity

Gets a more detailed networking state than g_network_monitor_get_network_available().

If GNetwork::Monitor:network-available is false, then the connectivity state will be %G_NETWORK_CONNECTIVITY_LOCAL.

If GNetwork::Monitor: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.

Returns:

#network_availableTrueClass

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 GNetwork::Monitor:network-available for more details.

Returns:

  • (TrueClass)

    whether the network is available

#network_changed(network_available) ⇒ nil

Parameters:

  • network_available (TrueClass)

Returns:

  • (nil)

#network_meteredTrueClass

Checks if the network is metered. See GNetwork::Monitor:network-metered for more details.

Returns:

  • (TrueClass)

    whether the connection is metered