netw

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package netw is a wrapper around network connections that stores annotations and records metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Listen

func Listen(network, laddr string) (net.Listener, error)

Listen creates a net listener that is instrumented to store per connection annotations and metrics.

func SetAnnotation

func SetAnnotation(conn net.Conn, key string, value any)

SetAnnotation sets an annotation on a connection. The value can be any go value.

Types

type Conn

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

Conn is a wrapper around net.Conn that stores annotations and metrics.

func (*Conn) Annotation

func (c *Conn) Annotation(key string, defaultValue any) any

Annotation retrieves an annotation that was previously set on the connection. The defaultValue is returned if the annotation was never set.

func (*Conn) BytesReceived

func (c *Conn) BytesReceived() int64

BytesReceived returns the number of bytes received on this connection so far.

func (*Conn) BytesSent

func (c *Conn) BytesSent() int64

BytesSent returns the number of bytes sent on this connection so far.

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) CopyAnnotationsFrom added in v0.3.0

func (c *Conn) CopyAnnotationsFrom(cc *Conn)

func (*Conn) OnClose

func (c *Conn) OnClose(f func())

OnClose sets a callback function that will be called when the connection is closed.

func (*Conn) Peek

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

func (*Conn) Read

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

func (*Conn) SetAnnotation

func (c *Conn) SetAnnotation(key string, value any)

SetAnnotation sets an annotation. The value can be any go value.

func (*Conn) SetLimiters added in v0.0.34

func (c *Conn) SetLimiters(ingress, egress *rate.Limiter)

SetLimiter sets the rate limiters for this connection. It must be called before the first Read() or Write(). Peek() is OK.

func (*Conn) StreamID added in v0.3.0

func (c *Conn) StreamID() int64

func (*Conn) Write

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

type QUICConn added in v0.3.0

type QUICConn struct {
	net.Conn
}

func (*QUICConn) Streams added in v0.3.0

func (*QUICConn) Streams() []*QUICStream

type QUICStream added in v0.3.0

type QUICStream struct {
	Conn
}

func (*QUICStream) BridgeAddr added in v0.3.0

func (*QUICStream) BridgeAddr() string

func (*QUICStream) Dir added in v0.3.0

func (*QUICStream) Dir() string

Jump to

Keyboard shortcuts

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