listener

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package listener creates listeners that serve a single IP address family.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TCP

func TCP(ctx context.Context, addr netip.Addr, port int) (net.Listener, error)

TCP listens on addr and port, serving only addr's address family.

The network is selected per family deliberately. Go turns a wildcard listen on "tcp" into a dual-stack socket, so a later IPv6 wildcard on the same port fails as already in use. "tcp6" sets IPV6_V6ONLY, which lets an IPv4 and an IPv6 listener share a port.

func UDP

func UDP(addr netip.AddrPort) (*net.UDPConn, error)

UDP listens on addr, serving only addr's address family.

The network is selected per family for the same reason as in TCP: a bare "udp" listen on a wildcard address yields a dual-stack socket, so binding both families to one port fails on the second bind. Services that listen on the same port in both families, such as TFTP and syslog, need this.

Types

type Bind

type Bind struct {
	Addr    netip.Addr
	Port    uint16
	Enabled bool
}

Bind is the listen address of a single address family. Enabled selects whether the family is served, and an enabled Bind must carry an address: serving is a decision made once rather than inferred from an address that may simply be unset.

Addr and Port are separate because each is set by its own flag, which a netip.AddrPort cannot expose.

func (Bind) AddrPort

func (b Bind) AddrPort() netip.AddrPort

AddrPort returns the address and port to listen on.

Jump to

Keyboard shortcuts

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