Back to godoc.org
github.com/orkunkaraduman/go-ioshape

Package ioshape

v0.0.0-...-b008879
Latest Go to latest

The highest tagged major version is .

Published: Jun 7, 2018 | License: BSD-3-Clause | Module: github.com/orkunkaraduman/go-ioshape

Overview

Package ioshape provides I/O structures and functions for Traffic Shaping using token-bucket algorithm.

Index

Variables

var ErrOutOfRange = errors.New("out of range")

ErrOutOfRange is the error used for the result of r/w is out of range.

func CopyB

func CopyB(dst io.Writer, src io.Reader, b *Bucket) (written int64, err error)

CopyB is identical to io.Copy except that it shapes traffic by b *Bucket.

func CopyBN

func CopyBN(dst io.Writer, src io.Reader, b *Bucket, n int64) (written int64, err error)

CopyBN is identical to io.CopyN except that it shapes traffic by b *Bucket.

func CopyRate

func CopyRate(dst io.Writer, src io.Reader, rate int64) (written int64, err error)

CopyRate is identical to io.Copy except that it shapes traffic with rate in bytes per second.

func CopyRateN

func CopyRateN(dst io.Writer, src io.Reader, rate int64, n int64) (written int64, err error)

CopyRateN is identical to io.CopyN except that it shapes traffic with rate in bytes per second.

type Bucket

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

Bucket shapes traffic by given rate, burst and Reader/Writer priorities.

func NewBucket

func NewBucket() (bu *Bucket)

NewBucket returns a new Bucket.

func NewBucketRate

func NewBucketRate(rate int64) (bu *Bucket)

NewBucketRate returns a new Bucket and sets rate.

func (*Bucket) Set

func (bu *Bucket) Set(rate, burst int64)

Set sets buckets rate and burst in bytes per second. The burst should be greater or equal than the rate. Otherwise burst will be equal rate.

func (*Bucket) SetRate

func (bu *Bucket) SetRate(rate int64)

SetRate sets rate and burst to the rate in bytes per second.

func (*Bucket) Stop

func (bu *Bucket) Stop()

Stop turns off a bucket. After Stop, bucket won't shape traffic. Stop must be call to free resources, after the bucket doesn't be needing.

type Reader

type Reader struct {
	R  io.Reader // underlying reader
	B  *Bucket   // bucket
	Pr int       // priority
}

Reader is a traffic shaper struct that implements io.Reader interface. A Reader reads from R by B. Priority changes between 0(highest) and 15(lowest).

func (*Reader) Read

func (rr *Reader) Read(p []byte) (n int, err error)

Read reads from R by b.

type Writer

type Writer struct {
	W  io.Writer // underlying reader
	B  *Bucket   // bucket
	Pr int       // priority
}

Writer is a traffic shaper struct that implements io.Writer interface. A Writer writes to W by B. Priority changes between 0(highest) and 15(lowest).

func (*Writer) Write

func (wr *Writer) Write(p []byte) (n int, err error)

Write writes to W by b.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier