iorate

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2021 License: MIT Imports: 7 Imported by: 0

README

iorate

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoBurstAvilable = fmt.Errorf("burst value too low for i/o operation")

Functions

This section is empty.

Types

type Bandwidth

type Bandwidth float64
const (
	Bps Bandwidth = 1 << (10 * iota)
	KBps
	MBps
	GBps
	TBps
	PBps
)

func (Bandwidth) String

func (b Bandwidth) String() string

String formats bandwidth value in human readable format.

type Conn

type Conn interface {
	// Conn implements the net.Conn interface.
	net.Conn

	// SetLimit sets the bandwith limit for future i/o ops.
	SetLimit(bps Bandwidth)

	// Limit returns the current bandwith limit.
	Limit() Bandwidth
}

Conn is a generic stream-oriented network connection with Bandwith limiting capability.

func NewLimitedConn

func NewLimitedConn(nc net.Conn, bps Bandwidth) Conn

NewLimitedConn creates new rate limiting connection.

type LimitedListener

type LimitedListener interface {
	// Listener implements net.Listener interface.
	net.Listener

	// SetLimits sets the per listener and per connection bandwith limits
	SetLimits(listenerLimit, connLimit Bandwidth)

	// Limits return the per listener and per connection  bandwith limits.
	Limits() (listenerLimit, connLimit Bandwidth)
}

LimitedListener controlls how often read and writes bandwitch for connections spawned by a listener.

func NewLimitedListener

func NewLimitedListener(l net.Listener) LimitedListener

type LimitedReader

type LimitedReader interface {
	io.Reader

	// SetReadLimit sets the bandwidth limtis for future read.
	SetReadLimit(bps Bandwidth)

	// ReadLimit returns the read i/o bandwidth limit.
	ReadLimit() Bandwidth
}

LimitedReader controlls how often reads are allowed to happen.

func NewLimitedReader

func NewLimitedReader(r io.Reader, bps Bandwidth) LimitedReader

NewLimitedReader creates new LimitedReader.

type LimitedWriter

type LimitedWriter interface {
	io.Writer

	// SetWriteLimit sets the bandwidth limit for future write i/o ops.
	SetWriteLimit(bps Bandwidth)

	// WriteLimit returns the write i/o bandwidth limit.
	WriteLimit() Bandwidth
}

LimitedWriter controlls how often writes are allowed to happen.

func NewLimitedWriter

func NewLimitedWriter(w io.Writer, bps Bandwidth) LimitedWriter

NewLimitedWriter creates new Writer and sets

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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