Documentation
¶
Overview ¶
Package porttest picks free ports for gcpemu's own tests.
A test that listens on port 0, closes the listener and binds the port again later leaves a window in which another process can take it: the OS hands out port-0 and outgoing-connection ports from its ephemeral range, which test packages running in parallel use all the time. So ports come from 20000-32767 instead, below the ephemeral range on Linux (32768-60999), macOS and Windows (49152-65535), where only explicit binds take them. Each call starts at a random port, so parallel packages do not all probe the same ones.
A test whose code under test can take a listener the test already holds should hold its port and hand it over instead (#643, #648). Tests use this package rather than probing port 0 themselves (#743, #750).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FreeUDP ¶
FreeUDP returns a port that a plain udp4 bind on 0.0.0.0 can take, scanning from a random port of the range. A port any IPv4 UDP socket holds is not free, even one bound with SO_REUSEADDR or SO_REUSEPORT, so a test's own mDNS port meets no other test's traffic. The code under test, or a child process, binds the port itself with SO_REUSEADDR, so the test can't hold it and hand it over.
Types ¶
This section is empty.