netstate

package module
v0.0.0-...-95bdfed Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2020 License: MIT Imports: 8 Imported by: 0

README

netstate builds.sr.ht status GoDoc Go Report Card

Package netstate provides notification of network interface state changes. MIT Licensed.

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.

func (Change) String

func (c Change) String() string

String returns the string representation of a Change.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

A Watcher watches for interface state changes and notifies listeners via a channel.

func NewWatcher

func NewWatcher() *Watcher

NewWatcher creates a Watcher.

func (*Watcher) Subscribe

func (w *Watcher) Subscribe(iface string, changes Change) <-chan Change

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

func (w *Watcher) Watch(ctx context.Context) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL