pub trait NetworkMonitorExt: IsA<NetworkMonitor> + 'static {
// Provided methods
fn can_reach(
&self,
connectable: &impl IsA<SocketConnectable>,
cancellable: Option<&impl IsA<Cancellable>>,
) -> Result<(), Error> { ... }
fn can_reach_async<P: FnOnce(Result<(), Error>) + 'static>(
&self,
connectable: &impl IsA<SocketConnectable>,
cancellable: Option<&impl IsA<Cancellable>>,
callback: P,
) { ... }
fn can_reach_future(
&self,
connectable: &(impl IsA<SocketConnectable> + Clone + 'static),
) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>> { ... }
fn connectivity(&self) -> NetworkConnectivity { ... }
fn is_network_available(&self) -> bool { ... }
fn is_network_metered(&self) -> bool { ... }
fn connect_network_changed<F: Fn(&Self, bool) + 'static>(
&self,
f: F,
) -> SignalHandlerId { ... }
fn connect_connectivity_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId { ... }
fn connect_network_available_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId { ... }
fn connect_network_metered_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId { ... }
}
Expand description
Provided Methods§
Sourcefn can_reach(
&self,
connectable: &impl IsA<SocketConnectable>,
cancellable: Option<&impl IsA<Cancellable>>,
) -> Result<(), Error>
fn can_reach( &self, connectable: &impl IsA<SocketConnectable>, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<(), Error>
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, @self can determine that
@connectable refers to a host on a local network.
If @self 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
IOErrorEnum::HostUnreachable
).
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().
§connectable
a #GSocketConnectable
§cancellable
a #GCancellable, or None
§Returns
Sourcefn can_reach_async<P: FnOnce(Result<(), Error>) + 'static>(
&self,
connectable: &impl IsA<SocketConnectable>,
cancellable: Option<&impl IsA<Cancellable>>,
callback: P,
)
fn can_reach_async<P: FnOnce(Result<(), Error>) + 'static>( &self, connectable: &impl IsA<SocketConnectable>, cancellable: Option<&impl IsA<Cancellable>>, callback: P, )
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.
§connectable
a #GSocketConnectable
§cancellable
a #GCancellable, or None
§callback
a #GAsyncReadyCallback to call when the request is satisfied
fn can_reach_future( &self, connectable: &(impl IsA<SocketConnectable> + Clone + 'static), ) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>>
Sourcefn connectivity(&self) -> NetworkConnectivity
fn connectivity(&self) -> NetworkConnectivity
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 NetworkConnectivity::Local
.
If #GNetworkMonitor:network-available is true
, then the
connectivity state will be NetworkConnectivity::Full
(if there
is full Internet connectivity), NetworkConnectivity::Limited
(if
the host has a default route, but appears to be unable to actually
reach the full Internet), or NetworkConnectivity::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 NetworkConnectivity::Limited
and
NetworkConnectivity::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
the network connectivity state
Sourcefn is_network_available(&self) -> bool
fn is_network_available(&self) -> bool
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.
§Returns
whether the network is available
Sourcefn is_network_metered(&self) -> bool
fn is_network_metered(&self) -> bool
Checks if the network is metered. See #GNetworkMonitor:network-metered for more details.
§Returns
whether the connection is metered
Sourcefn connect_network_changed<F: Fn(&Self, bool) + 'static>(
&self,
f: F,
) -> SignalHandlerId
fn connect_network_changed<F: Fn(&Self, bool) + 'static>( &self, f: F, ) -> SignalHandlerId
Emitted when the network configuration changes.
§network_available
the current value of #GNetworkMonitor:network-available
fn connect_connectivity_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId
fn connect_network_available_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId
fn connect_network_metered_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.