bwlimit

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: MIT Imports: 5 Imported by: 3

README

build coverage goreport Docs

bwlimit

Go net.Conn bandwidth limiter.

Only depends on the standard library.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	net.Conn // underlying net.Conn
	*Limiter // Limiter to use
}

func (*Conn) Read

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

func (*Conn) Write

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

type DialContextFn added in v0.3.0

type DialContextFn func(ctx context.Context, network string, address string) (net.Conn, error)

type Dialer

type Dialer struct {
	DialContextFn // DialContext function we wrap, if nil use net.Dialer.DialContext
	*Limiter      // Limiter to use
}

func (*Dialer) Dial

func (d *Dialer) Dial(network string, address string) (net.Conn, error)

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, address string) (conn net.Conn, err error)

type Limiter

type Limiter struct {
	Reads  *Operation
	Writes *Operation
}

func NewLimiter

func NewLimiter(ctx context.Context) *Limiter

type Listener

type Listener struct {
	net.Listener // underlying net.Listener
	*Limiter     // Limiter to use
}

func (*Listener) Accept

func (l *Listener) Accept() (conn net.Conn, err error)

type Operation

type Operation struct {
	Limit atomic.Int32 // bandwith limit in bytes/sec
	Rate  atomic.Int32 // current rate in bytes/sec
	// contains filtered or unexported fields
}

func NewOperation

func NewOperation(ctx context.Context, reader bool) (op *Operation)

Jump to

Keyboard shortcuts

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