portal

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MPL-2.0 Imports: 6 Imported by: 3

Documentation

Overview

Package portal (Port Allocator) provides a helper for reserving free TCP ports across multiple processes on the same machine. This works by asking the kernel for available ports in the ephemeral port range. It does so by binding to an address with port 0 (e.g. 127.0.0.1:0), modifying the socket to disable SO_LINGER, close the connection, and finally return the port that was used. This *probably* works well, because the kernel re-uses ports in an LRU fashion, implying the test code asking for the ports *should* be the only thing immediately asking to bind that port again.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FatalTester

type FatalTester interface {
	Fatalf(msg string, args ...any)
}

type Grabber

type Grabber interface {
	// Grab n port allocations.
	Grab(n int) []int

	// One port allocation.
	One() int
}

A Grabber is used to grab open ports.

func New

func New(t FatalTester, opts ...Option) Grabber

New creates a new Grabber with the given options.

type Option

type Option func(Grabber)

func WithAddress

func WithAddress(address string) Option

WithAddress specifies which address on which to allocate ports.

Jump to

Keyboard shortcuts

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