packetio

package
Version: v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2021 License: MIT Imports: 5 Imported by: 26

Documentation

Overview

Package packetio provides packet buffer

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFull is returned when the buffer has hit the configured limits.
	ErrFull = errors.New("packetio.Buffer is full, discarding write")

	// ErrTimeout is returned when a deadline has expired
	ErrTimeout = errors.New("i/o timeout")
)

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.

func (*Buffer) Close

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

Close the buffer, unblocking any pending reads. Data in the buffer can still be read, Read will return io.EOF only when empty.

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 means 4MB since v0.11.0.

User can set packetioSizeHardlimit build tag to enable 4MB hardlimit. When packetioSizeHardlimit build tag is set, SetLimitSize exceeding the hardlimit will be silently discarded.

func (*Buffer) SetReadDeadline added in v0.10.0

func (b *Buffer) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for the Read operation. Setting to zero means no deadline.

func (*Buffer) Size

func (b *Buffer) Size() int

Size returns the total byte size of packets in the buffer, including a small amount of administrative overhead.

func (*Buffer) Write

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

Write appends a copy of the packet data to the buffer. Returns ErrFull if the packet doesn't fit.

Note that the packet size is limited to 65536 bytes since v0.11.0 due to the internal data structure.

type BufferPacketType added in v0.12.2

type BufferPacketType int

BufferPacketType allow the Buffer to know which packet protocol is writing.

const (
	// RTPBufferPacket indicates the Buffer that is handling RTP packets
	RTPBufferPacket BufferPacketType = 1
	// RTCPBufferPacket indicates the Buffer that is handling RTCP packets
	RTCPBufferPacket BufferPacketType = 2
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL