ratelimit

package module
v0.0.0-...-52a5587 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2020 License: MIT Imports: 6 Imported by: 3

README

ratelimit

global ratelimiter for network connections in golang

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRLConn

func NewRLConn(conn net.Conn, rl *RateLimit, cancel <-chan struct{}) net.Conn

NewRLConn wrap a net.Conn into a rlReadWriter.

func NewRLReadWriter

func NewRLReadWriter(rw io.ReadWriter, rl *RateLimit, cancel <-chan struct{}) io.ReadWriter

NewRLReadWriter wraps a io.ReadWriter into a rlReadWriter.

Types

type RateLimit

type RateLimit struct {
	// contains filtered or unexported fields
}

RateLimit declares the global rate limit for read and write operations on a io.ReadWriter. Whenever a caller wants to read or write, they have to wait until readBlock/writeBlock to start the actual read or write operation. Each caller also pushes these timestamps into the future to prevent other callers to read or write prematurely.

func NewRateLimit

func NewRateLimit(readBPS, writeBPS int64, packetSize uint64) *RateLimit

NewRateLimit creates a new rateLimit object that can be used to initialize rate-limited readers and writers.

func (*RateLimit) Limits

func (rl *RateLimit) Limits() (int64, int64, uint64)

Limits gets the current limits for the global rate limiter.

func (*RateLimit) SetLimits

func (rl *RateLimit) SetLimits(readBPS, writeBPS int64, packetSize uint64)

SetLimits sets new limits for the global rate limiter.

Jump to

Keyboard shortcuts

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