Documentation
¶
Overview ¶
Package freeport provides a shared, dependency-free TCP host-port allocator: a dual-stack bindability probe and a predicate-injected free-port search. It is a leaf package (stdlib only) so both internal/cli (host-proxy dev servers) and internal/serviceops (the service port-ownership guard) can import it without an import cycle, and so the search logic stays unit-testable without binding real sockets.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bindable ¶
Bindable reports whether a TCP port can be bound on both loopback stacks (127.0.0.1 and [::1]) — the two addresses lerd's published quadlets and host-proxy dev servers bind. A bind test is stricter and more accurate than a dial test for "can we publish here": it catches a port reserved on either stack, not just one with a live listener. A host with no IPv6 loopback at all is tolerated — the v6 check is skipped rather than treated as busy. The v4 listener is held open (deferred close) through the v6 bind so the pair is tested atomically — closing it early would let another process grab v4 in the window between the two checks.
func FirstFree ¶
FirstFree returns the first port at or above start for which taken reports false. The predicate is injected so the search is unit-testable without binding real sockets; callers compose it from Bindable plus any reserved-port set of their own. start is clamped to >= 1. Returns 0 when nothing in [start, 65535] is free, so callers can decide their own fallback.
Types ¶
This section is empty.