go-ioshape: github.com/orkunkaraduman/go-ioshape Index | Files

package ioshape

import "github.com/orkunkaraduman/go-ioshape"

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

Index

Package Files

bucket.go ioshape.go reader.go writer.go

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

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

func NewBucket Uses

func NewBucket() (bu *Bucket)

NewBucket returns a new Bucket.

func NewBucketRate Uses

func NewBucketRate(rate int64) (bu *Bucket)

NewBucketRate returns a new Bucket and sets rate.

func (*Bucket) Set Uses

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 Uses

func (bu *Bucket) SetRate(rate int64)

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

func (*Bucket) Stop Uses

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 Uses

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 Uses

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

Read reads from R by b.

type Writer Uses

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 Uses

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

Write writes to W by b.

Package ioshape imports 5 packages (graph). Updated 2018-06-07. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).