netx

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadUUID added in v0.3.0

func LoadUUID(ctx context.Context) string

LoadUUID reads a connection UUID from a context.Context using a globally unique key. Returns an empty string if the UUID is not found in the context.

Types

type Conn

type Conn struct {
	net.Conn
	// contains filtered or unexported fields
}

Conn is an extended net.Conn that stores its accept time, a copy of the underlying socket's file descriptor, and counters for read/written bytes.

func FromTCPLikeConn added in v0.4.0

func FromTCPLikeConn(tcpConn TCPLikeConn) (*Conn, error)

FromTCPLikeConn creates a netx.Conn from a TCPLikeConn.

func (*Conn) AcceptTime

func (c *Conn) AcceptTime() time.Time

AcceptTime returns this connection's accept time.

func (*Conn) ByteCounters

func (c *Conn) ByteCounters() (uint64, uint64)

ByteCounters returns the read and written byte counters, in this order.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the underlying net.Conn and the duplicate file descriptor.

func (*Conn) GetCC

func (c *Conn) GetCC() (string, error)

GetCC gets the current congestion control algorithm from the underlying file descriptor.

func (*Conn) Info

func (c *Conn) Info() (inetdiag.BBRInfo, tcp.LinuxTCPInfo, error)

Info returns the BBRInfo and TCPInfo structs associated with the underlying socket. It returns an error if TCPInfo cannot be read.

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

Read reads from the underlying net.Conn and updates the read bytes counter.

func (*Conn) SaveUUID added in v0.3.0

func (c *Conn) SaveUUID(ctx context.Context) context.Context

SaveUUID saves this connection's UUID in a context.Context using a globally unique key. LoadUUID should be used to retrieve the uuid from the context.

func (*Conn) SetCC

func (c *Conn) SetCC(cc string) error

SetCC sets the congestion control algorithm on the underlying file descriptor.

func (*Conn) UUID

func (c *Conn) UUID() string

UUID returns an M-Lab UUID. On platforms not supporting SO_COOKIE, it returns a google/uuid as a fallback. If the fallback fails, it panics.

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

Write writes to the underlying net.Conn and updates the written bytes counter.

type ConnInfo

type ConnInfo interface {
	ByteCounters() (uint64, uint64)
	Info() (inetdiag.BBRInfo, tcp.LinuxTCPInfo, error)
	AcceptTime() time.Time
	UUID() string
	GetCC() (string, error)
	SetCC(string) error
	SaveUUID(context.Context) context.Context
}

ConnInfo provides operations on a net.Conn's underlying file descriptor.

func ToConnInfo

func ToConnInfo(netConn net.Conn) ConnInfo

ToConnInfo is a helper function to convert a net.Conn into a netx.ConnInfo. It panics if netConn does not contain a type supporting ConnInfo.

type Listener

type Listener struct {
	*net.TCPListener
}

Listener is a TCPListener. Connections accepted by this listener provide extra methods to interact with the connection's underlying file descriptor.

func NewListener

func NewListener(l *net.TCPListener) *Listener

NewListener returns a netx.Listener.

func (*Listener) Accept

func (ln *Listener) Accept() (net.Conn, error)

Accept accepts a connection and returns a netx.Conn which includes the connection's "accept time" and provides operations on the underlying file descriptor.

type TCPLikeConn added in v0.4.0

type TCPLikeConn interface {
	net.Conn
	File() (*os.File, error)
}

TCPLikeConn is a net.Conn with a File() method. This is useful for creating a netx.Conn based on a custom TCPConn-like type - e.g. for testing.

Jump to

Keyboard shortcuts

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