ciol

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ciol 实现 net.conn 网络io限速器接口

Index

Constants

View Source
const MaxBurst = 1000 * 1000 * 1000

MaxBurst 默认读写最大容量限制

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn limiter conn

func New

func New(c net.Conn, opts ...Options) *Conn

New new a rate limit (bytes/sec) with option to the Conn read and write. if not set,it will not any limit

func (*Conn) Close

func (sf *Conn) Close() (err error)

Close close the Conn

func (*Conn) Read

func (sf *Conn) Read(p []byte) (int, error)

Read reads data from the connection.

func (*Conn) ReadLimit

func (sf *Conn) ReadLimit() rate.Limit

ReadLimit returns the maximum overall event read rate.

func (*Conn) SetReadBurst

func (sf *Conn) SetReadBurst(newBurst int)

SetReadBurst sets a new read burst size for the limiter.

func (*Conn) SetReadBurstAt

func (sf *Conn) SetReadBurstAt(now time.Time, newBurst int)

SetReadBurstAt sets a new read read size for the limiter.

func (*Conn) SetReadLimit

func (sf *Conn) SetReadLimit(newLimit rate.Limit)

SetReadLimit sets a new read Limit for the limiter.

func (*Conn) SetReadLimitAt

func (sf *Conn) SetReadLimitAt(now time.Time, newLimit rate.Limit)

SetReadLimitAt sets a new read Limit for the limiter.

func (*Conn) SetWriteBurst

func (sf *Conn) SetWriteBurst(newBurst int)

SetWriteBurst sets a new read write size for the limiter.

func (*Conn) SetWriteBurstAt

func (sf *Conn) SetWriteBurstAt(now time.Time, newBurst int)

SetWriteBurstAt sets a new read write size for the limiter.

func (*Conn) SetWriteLimit

func (sf *Conn) SetWriteLimit(newLimit rate.Limit)

SetWriteLimit sets a new write Limit for the limiter.

func (*Conn) SetWriteLimitAt

func (sf *Conn) SetWriteLimitAt(now time.Time, newLimit rate.Limit)

SetWriteLimitAt sets a new write Limit for the limiter.

func (*Conn) Write

func (sf *Conn) Write(p []byte) (int, error)

Write writes data to the connection.

func (*Conn) WriteLimit

func (sf *Conn) WriteLimit() rate.Limit

WriteLimit returns the maximum overall event write rate.

type Options

type Options func(*Conn)

Options Conn options

func WithReadLimiter

func WithReadLimiter(bytesPerSec rate.Limit, bursts ...int) Options

WithReadLimiter 读限速

func WithWriteLimiter

func WithWriteLimiter(bytesPerSec rate.Limit, bursts ...int) Options

WithWriteLimiter 写限速

Jump to

Keyboard shortcuts

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