buffer

package
v2.6.6 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DataPool = &Pool{
	pool: sync.Pool{
		New: func() any {
			return NewData(defaultMTU + maxIPHeader)
		}},
	MTU: defaultMTU,
}

Functions

This section is empty.

Types

type Data

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

func NewData added in v2.6.5

func NewData(sz int) *Data

func (*Data) Buf

func (b *Data) Buf() []byte

Buf returns this Data's buffer. This is the buffer that should be used everywhere except for the tun.Device ReadPacket and WritePacket methods.

func (*Data) Raw

func (b *Data) Raw() []byte

Raw returns this Data's raw buffer. This is the buffer that should be used by the tun.Device ReadPacket and WritePacket methods. It uses the same underlying byte array as Buf but might be offset before Buf to allow for leading bytes that are provided before the IP header.

type Pool

type Pool struct {
	MTU int
	// contains filtered or unexported fields
}

A Pool is a specialized sync.Pool for Data. The Data struct is platform specific

func (*Pool) Copy added in v2.6.5

func (p *Pool) Copy(s *Data, n int) *Data

Copy copies n bytes from the given Data buffer into a new Data which is obtained from the pool, and returns the new data.

func (*Pool) Get

func (p *Pool) Get(size int) *Data

Get returns an entry from the pool if the requested size is less than or equal to the pool's MTU. For sizes larger than the MTU, a new entry is allocated and returned, but it is not pooled.

func (*Pool) Put

func (p *Pool) Put(b *Data)

Put will put entries with a size less than or equal to MTU back to the pool.

Jump to

Keyboard shortcuts

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