Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( CurrentOpenConns = promauto.NewGauge( prometheus.GaugeOpts{ Name: "netx_current_open_conns", Help: "A gauge of currently open netx.Conns with open file pointers.", }, ) )
Metrics for resource accounting in the netx package.
Functions ¶
Types ¶
type Addr ¶
Addr supports the net.Addr interface and allows mediated access to operations on the parent Conn.
Why is this necessary? The Conn type accessible to application code is a function of the server protocol. In particular, the tls.Conn is created by a TLS Server, regardless of the underlying Listener type. Because a tls.Conn is a struct, not an interface, and because tls.Conn does not provide access to the underlying net.Conn, we still need a way to access the underlying Conn type in order to access and operate on the underlying connection file descriptor.
So, to support all server protocols using the Listener, we "piggyback" on the net.Conn interface supported by tls.Conns. In particular, the LocalAddr and RemoteAddr methods return an Addr type, which includes a parent reference to the associated Conn.
Because the Addr includes references to the parent Conn, all Addrs should be released before calling Conn.Close.
type Conn ¶
Conn is returned by Listener.Accept and provides mediated access to additional operations on the Conn file descriptor.
func (*Conn) Close ¶
Close the underlying net.Conn and dup'd file descriptor. Note: all net.Addr's returned by LocalAddr and RemoteAddr should be released before calling Close.
func (*Conn) EnableBBR ¶
EnableBBR sets the BBR congestion control on the TCP connection, if supported by the kernel. If unsupported, EnableBBR has no effect.
func (*Conn) LocalAddr ¶
LocalAddr returns an Addr supporting the net.Addr interface, which provides access to the parent Conn.
func (*Conn) ReadInfo ¶
ReadInfo reads metadata about the TCP connections. If BBR was not enabled on the underlying connection, then ReadInfo will return an empty BBRInfo struct. If TCP info metrics cannot be read, an error is returned.
func (*Conn) RemoteAddr ¶
RemoteAddr returns an Addr supporting the net.Addr interface, which provides access to the parent Conn.
type ConnInfo ¶
type ConnInfo interface { GetUUID() (string, error) EnableBBR() error ReadInfo() (inetdiag.BBRInfo, tcp.LinuxTCPInfo, error) }
ConnInfo provides operations on a Conn's underlying file descriptor.
func ToConnInfo ¶
ToConnInfo is a helper function for extracting the ConnInfo interface from the net.Conn of various origins. ToConnInfo panics if conn does not contain a type supporting ConnInfo.
type Listener ¶
type Listener struct { *net.TCPListener // contains filtered or unexported fields }
Listener is a TCPListener that is suitable for raw TCP servers, HTTP servers, and TLS HTTP servers. The Conn's returned by Listener.Accept mediate access to the underlying Conn file descriptor, allowing callers to perform meta operations on the connection, e.g. GetUUID, EnableBBR, ReadInfo.
func NewListener ¶
func NewListener(l *net.TCPListener) *Listener
NewListener creates a new Listener using the given net.TCPListener.