Documentation
¶
Overview ¶
Package netstate provides notification of network interface state changes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change uint
A Change is a bitmask of possible changes to a network interface's state.
const ( // RFC 2863 "ifOperStatus" values which indicate network interface // state changes. LinkUp Change = 1 << iota LinkDown LinkTesting LinkUnknown LinkDormant LinkNotPresent LinkLowerLayerDown // LinkAny is a convenience bitmask which indicates interest in all // Link* Changes. LinkAny Change = LinkUp | LinkDown | LinkTesting | LinkUnknown | LinkDormant | LinkNotPresent | LinkLowerLayerDown )
Possible state changes which may occur to a network interface.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
A Watcher watches for interface state changes and notifies listeners via a channel.
func (*Watcher) Subscribe ¶
Subscribe registers interest for the specified bitmask of state changes on a network interface, returning a buffered channel of Changes. The channel will be closed when the context passed to Watch is canceled. If the caller does not drain Change events from the channel and it reaches capacity, they will be dropped.
func (*Watcher) Watch ¶
Watch runs the Watcher and blocks until the specified context is canceled, or an error occurs.
If Watch is not supported on the current operating system, it will return an error which can be checked using errors.Is(err, os.ErrNotExist).
If Watch is called multiple times, it will panic.