packetio

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2019 License: MIT Imports: 3 Imported by: 61

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFull = errors.New("full buffer")

ErrFull is returned when the buffer has hit the configured limits.

Functions

This section is empty.

Types

type Buffer

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

Buffer allows writing packets to an intermediate buffer, which can then be read form. This is verify similar to bytes.Buffer but avoids combining multiple writes into a single read.

func NewBuffer

func NewBuffer() *Buffer

NewBuffer creates a new Buffer object.

func (*Buffer) Close

func (b *Buffer) Close() (err error)

Close will unblock any readers and prevent future writes. Data in the buffer can still be read, returning io.EOF when fully depleted.

func (*Buffer) Count

func (b *Buffer) Count() int

Count returns the number of packets in the buffer.

func (*Buffer) Read

func (b *Buffer) Read(packet []byte) (n int, err error)

Read populates the given byte slice, returning the number of bytes read. Blocks until data is available or the buffer is closed. Returns io.ErrShortBuffer is the packet is too small to copy the Write. Returns io.EOF if the buffer is closed.

func (*Buffer) SetLimitCount

func (b *Buffer) SetLimitCount(limit int)

SetLimitCount controls the maximum number of packets that can be buffered. Causes Write to return ErrFull when this limit is reached. A zero value will disable this limit.

func (*Buffer) SetLimitSize

func (b *Buffer) SetLimitSize(limit int)

SetLimitSize controls the maximum number of bytes that can be buffered. Causes Write to return ErrFull when this limit is reached. A zero value will disable this limit.

func (*Buffer) Size

func (b *Buffer) Size() int

Size returns the total byte size of packets in the buffer.

func (*Buffer) Write

func (b *Buffer) Write(packet []byte) (n int, err error)

Write appends a copy of the packet data to the buffer. If any defined limits are hit, returns ErrFull.

Jump to

Keyboard shortcuts

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