Copyright | Will Thompson, Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com) |
Safe Haskell | None |
Language | Haskell2010 |
NetworkMonitor
provides an easy-to-use cross-platform API
for monitoring network connectivity. On Linux, the implementation
is based on the kernel's netlink interface.
- newtype NetworkMonitor = NetworkMonitor (ManagedPtr NetworkMonitor)
- noNetworkMonitor :: Maybe NetworkMonitor
- class GObject o => IsNetworkMonitor o
- toNetworkMonitor :: IsNetworkMonitor o => o -> IO NetworkMonitor
- data NetworkMonitorCanReachMethodInfo
- networkMonitorCanReach :: (HasCallStack, MonadIO m, IsNetworkMonitor a, IsSocketConnectable b, IsCancellable c) => a -> b -> Maybe c -> m ()
- data NetworkMonitorCanReachAsyncMethodInfo
- networkMonitorCanReachAsync :: (HasCallStack, MonadIO m, IsNetworkMonitor a, IsSocketConnectable b, IsCancellable c) => a -> b -> Maybe c -> Maybe AsyncReadyCallback -> m ()
- data NetworkMonitorCanReachFinishMethodInfo
- networkMonitorCanReachFinish :: (HasCallStack, MonadIO m, IsNetworkMonitor a, IsAsyncResult b) => a -> b -> m ()
- data NetworkMonitorGetConnectivityMethodInfo
- networkMonitorGetConnectivity :: (HasCallStack, MonadIO m, IsNetworkMonitor a) => a -> m NetworkConnectivity
- networkMonitorGetDefault :: (HasCallStack, MonadIO m) => m NetworkMonitor
- data NetworkMonitorGetNetworkAvailableMethodInfo
- networkMonitorGetNetworkAvailable :: (HasCallStack, MonadIO m, IsNetworkMonitor a) => a -> m Bool
- data NetworkMonitorGetNetworkMeteredMethodInfo
- networkMonitorGetNetworkMetered :: (HasCallStack, MonadIO m, IsNetworkMonitor a) => a -> m Bool
- data NetworkMonitorConnectivityPropertyInfo
- getNetworkMonitorConnectivity :: (MonadIO m, IsNetworkMonitor o) => o -> m NetworkConnectivity
- networkMonitorConnectivity :: AttrLabelProxy "connectivity"
- data NetworkMonitorNetworkAvailablePropertyInfo
- getNetworkMonitorNetworkAvailable :: (MonadIO m, IsNetworkMonitor o) => o -> m Bool
- networkMonitorNetworkAvailable :: AttrLabelProxy "networkAvailable"
- data NetworkMonitorNetworkMeteredPropertyInfo
- getNetworkMonitorNetworkMetered :: (MonadIO m, IsNetworkMonitor o) => o -> m Bool
- networkMonitorNetworkMetered :: AttrLabelProxy "networkMetered"
- type C_NetworkMonitorNetworkChangedCallback = Ptr () -> CInt -> Ptr () -> IO ()
- type NetworkMonitorNetworkChangedCallback = Bool -> IO ()
- data NetworkMonitorNetworkChangedSignalInfo
- afterNetworkMonitorNetworkChanged :: (IsNetworkMonitor a, MonadIO m) => a -> NetworkMonitorNetworkChangedCallback -> m SignalHandlerId
- genClosure_NetworkMonitorNetworkChanged :: NetworkMonitorNetworkChangedCallback -> IO Closure
- mk_NetworkMonitorNetworkChangedCallback :: C_NetworkMonitorNetworkChangedCallback -> IO (FunPtr C_NetworkMonitorNetworkChangedCallback)
- noNetworkMonitorNetworkChangedCallback :: Maybe NetworkMonitorNetworkChangedCallback
- onNetworkMonitorNetworkChanged :: (IsNetworkMonitor a, MonadIO m) => a -> NetworkMonitorNetworkChangedCallback -> m SignalHandlerId
- wrap_NetworkMonitorNetworkChangedCallback :: NetworkMonitorNetworkChangedCallback -> Ptr () -> CInt -> Ptr () -> IO ()
Exported types
newtype NetworkMonitor Source #
GObject NetworkMonitor Source # | |
IsObject NetworkMonitor Source # | |
IsInitable NetworkMonitor Source # | |
IsNetworkMonitor NetworkMonitor Source # | |
((~) * info (ResolveNetworkMonitorMethod t NetworkMonitor), MethodInfo * info NetworkMonitor p) => IsLabel t (NetworkMonitor -> p) Source # | |
((~) * info (ResolveNetworkMonitorMethod t NetworkMonitor), MethodInfo * info NetworkMonitor p) => IsLabelProxy t (NetworkMonitor -> p) Source # | |
HasAttributeList * NetworkMonitor Source # | |
type AttributeList NetworkMonitor Source # | |
type SignalList NetworkMonitor Source # | |
class GObject o => IsNetworkMonitor o Source #
toNetworkMonitor :: IsNetworkMonitor o => o -> IO NetworkMonitor Source #
Methods
canReach
data NetworkMonitorCanReachMethodInfo Source #
((~) * signature (b -> Maybe c -> m ()), MonadIO m, IsNetworkMonitor a, IsSocketConnectable b, IsCancellable c) => MethodInfo * NetworkMonitorCanReachMethodInfo a signature Source # | |
networkMonitorCanReach Source #
:: (HasCallStack, MonadIO m, IsNetworkMonitor a, IsSocketConnectable b, IsCancellable c) | |
=> a |
|
-> b |
|
-> Maybe c |
|
-> m () | (Can throw |
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 NetworkMonitor
: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
IOErrorEnumHostUnreachable
).
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 networkMonitorCanReachAsync
.
Since: 2.32
canReachAsync
data NetworkMonitorCanReachAsyncMethodInfo Source #
((~) * signature (b -> Maybe c -> Maybe AsyncReadyCallback -> m ()), MonadIO m, IsNetworkMonitor a, IsSocketConnectable b, IsCancellable c) => MethodInfo * NetworkMonitorCanReachAsyncMethodInfo a signature Source # | |
networkMonitorCanReachAsync Source #
:: (HasCallStack, MonadIO m, IsNetworkMonitor a, IsSocketConnectable b, IsCancellable c) | |
=> a |
|
-> b |
|
-> Maybe c |
|
-> Maybe AsyncReadyCallback |
|
-> m () |
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 networkMonitorCanReach
.
When the operation is finished, callback
will be called.
You can then call networkMonitorCanReachFinish
to get the result of the operation.
canReachFinish
data NetworkMonitorCanReachFinishMethodInfo Source #
((~) * signature (b -> m ()), MonadIO m, IsNetworkMonitor a, IsAsyncResult b) => MethodInfo * NetworkMonitorCanReachFinishMethodInfo a signature Source # | |
networkMonitorCanReachFinish Source #
:: (HasCallStack, MonadIO m, IsNetworkMonitor a, IsAsyncResult b) | |
=> a |
|
-> b |
|
-> m () | (Can throw |
Finishes an async network connectivity test.
See networkMonitorCanReachAsync
.
getConnectivity
data NetworkMonitorGetConnectivityMethodInfo Source #
((~) * signature (m NetworkConnectivity), MonadIO m, IsNetworkMonitor a) => MethodInfo * NetworkMonitorGetConnectivityMethodInfo a signature Source # | |
networkMonitorGetConnectivity Source #
:: (HasCallStack, MonadIO m, IsNetworkMonitor a) | |
=> a |
|
-> m NetworkConnectivity | Returns: the network connectivity state |
Gets a more detailed networking state than
networkMonitorGetNetworkAvailable
.
If NetworkMonitor
:network-available
is False
, then the
connectivity state will be NetworkConnectivityLocal
.
If NetworkMonitor
:network-available
is True
, then the
connectivity state will be NetworkConnectivityFull
(if there
is full Internet connectivity), NetworkConnectivityLimited
(if
the host has a default route, but appears to be unable to actually
reach the full Internet), or NetworkConnectivityPortal
(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 NetworkConnectivityLimited
and
NetworkConnectivityPortal
, 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.
Since: 2.44
getDefault
networkMonitorGetDefault Source #
:: (HasCallStack, MonadIO m) | |
=> m NetworkMonitor | Returns: a |
Gets the default NetworkMonitor
for the system.
Since: 2.32
getNetworkAvailable
data NetworkMonitorGetNetworkAvailableMethodInfo Source #
((~) * signature (m Bool), MonadIO m, IsNetworkMonitor a) => MethodInfo * NetworkMonitorGetNetworkAvailableMethodInfo a signature Source # | |
networkMonitorGetNetworkAvailable Source #
:: (HasCallStack, MonadIO m, IsNetworkMonitor a) | |
=> a |
|
-> m Bool | Returns: whether the network is 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 NetworkMonitor
:network-available
for more details.
Since: 2.32
getNetworkMetered
data NetworkMonitorGetNetworkMeteredMethodInfo Source #
((~) * signature (m Bool), MonadIO m, IsNetworkMonitor a) => MethodInfo * NetworkMonitorGetNetworkMeteredMethodInfo a signature Source # | |
networkMonitorGetNetworkMetered Source #
:: (HasCallStack, MonadIO m, IsNetworkMonitor a) | |
=> a |
|
-> m Bool | Returns: whether the connection is metered |
Checks if the network is metered.
See NetworkMonitor
:network-metered
for more details.
Since: 2.46
Properties
connectivity
data NetworkMonitorConnectivityPropertyInfo Source #
getNetworkMonitorConnectivity :: (MonadIO m, IsNetworkMonitor o) => o -> m NetworkConnectivity Source #
networkMonitorConnectivity :: AttrLabelProxy "connectivity" Source #
networkAvailable
data NetworkMonitorNetworkAvailablePropertyInfo Source #
getNetworkMonitorNetworkAvailable :: (MonadIO m, IsNetworkMonitor o) => o -> m Bool Source #
networkMonitorNetworkAvailable :: AttrLabelProxy "networkAvailable" Source #
networkMetered
data NetworkMonitorNetworkMeteredPropertyInfo Source #
getNetworkMonitorNetworkMetered :: (MonadIO m, IsNetworkMonitor o) => o -> m Bool Source #
networkMonitorNetworkMetered :: AttrLabelProxy "networkMetered" Source #
Signals
networkChanged
type NetworkMonitorNetworkChangedCallback = Bool -> IO () Source #
afterNetworkMonitorNetworkChanged :: (IsNetworkMonitor a, MonadIO m) => a -> NetworkMonitorNetworkChangedCallback -> m SignalHandlerId Source #
genClosure_NetworkMonitorNetworkChanged :: NetworkMonitorNetworkChangedCallback -> IO Closure Source #
mk_NetworkMonitorNetworkChangedCallback :: C_NetworkMonitorNetworkChangedCallback -> IO (FunPtr C_NetworkMonitorNetworkChangedCallback) Source #
onNetworkMonitorNetworkChanged :: (IsNetworkMonitor a, MonadIO m) => a -> NetworkMonitorNetworkChangedCallback -> m SignalHandlerId Source #
wrap_NetworkMonitorNetworkChangedCallback :: NetworkMonitorNetworkChangedCallback -> Ptr () -> CInt -> Ptr () -> IO () Source #