Trait gio::prelude::NetworkMonitorExt
source · pub trait NetworkMonitorExt: IsA<NetworkMonitor> + Sealed + '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 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 can_reach_async()
.
connectable
cancellable
a Cancellable
, 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 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
cancellable
a Cancellable
, 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
is_network_available()
.
If network-available
is false
, then the
connectivity state will be NetworkConnectivity::Local
.
If 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 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 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 network-available