utils

package
v1.5.7 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2020 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IPv4UdpMaxPayload = 1472 // MTU 1500 - 20 IPv4 header - 8 udp header
	IPv6UdpMaxPayload = 1452 // MTU 1500 - 40 IPv6 header - 8 udp header
)

Variables

This section is empty.

Functions

func GetMsgBuf added in v1.5.7

func GetMsgBuf(size int) []byte

func GetMsgBufFor added in v1.5.7

func GetMsgBufFor(m *dns.Msg) ([]byte, error)

func GetTimer added in v1.5.5

func GetTimer(t time.Duration) *time.Timer

func ReadMsgFromTCP added in v1.4.4

func ReadMsgFromTCP(c io.Reader) (m *dns.Msg, n int, err error)

ReadMsgFromTCP reads msg from a tcp connection. brokenDataLeft indicates the frame size which have not be read from c. if brokenDataLeft is unknownBrokenDataSize(-1), c should not be reused anymore. n represents how many bytes are read from c.

func ReadMsgFromUDP added in v1.4.4

func ReadMsgFromUDP(c io.Reader, bufSize int) (m *dns.Msg, n int, err error)

func ReadUDPMsgFrom added in v1.4.4

func ReadUDPMsgFrom(c net.PacketConn, bufSize int) (m *dns.Msg, from net.Addr, n int, err error)

func ReleaseMsgBuf added in v1.5.7

func ReleaseMsgBuf(buf []byte)

func ReleaseTimer added in v1.5.5

func ReleaseTimer(timer *time.Timer)

func ResetAndDrainTimer added in v1.5.5

func ResetAndDrainTimer(timer *time.Timer, d time.Duration)

func WriteMsgToTCP added in v1.4.4

func WriteMsgToTCP(c io.Writer, m *dns.Msg) (n int, err error)

WriteMsgToTCP writes m to c. n represents how many bytes are wrote to c. This includes 2 bytes tcp length header.

func WriteMsgToUDP added in v1.4.4

func WriteMsgToUDP(c io.Writer, m *dns.Msg) (n int, err error)

func WriteRawMsgToTCP added in v1.4.4

func WriteRawMsgToTCP(c io.Writer, b []byte) (n int, err error)

WriteRawMsgToTCP writes b to c. n represents how many bytes are wrote to c. This includes 2 bytes tcp length header.

func WriteRawMsgToUDP added in v1.4.4

func WriteRawMsgToUDP(c io.Writer, b []byte) (n int, err error)

func WriteUDPMsgTo added in v1.4.4

func WriteUDPMsgTo(m *dns.Msg, c net.PacketConn, to net.Addr) (n int, err error)

Types

type Allocator added in v1.5.7

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

func NewAllocator added in v1.5.7

func NewAllocator() *Allocator

NewAllocator initiates a []byte allocator for dns.Msg less than 65536 bytes, the waste(memory fragmentation) of space allocation is guaranteed to be no more than 50%.

func (*Allocator) Get added in v1.5.7

func (alloc *Allocator) Get(size int) []byte

Get a []byte from pool with most appropriate cap

func (*Allocator) Put added in v1.5.7

func (alloc *Allocator) Put(buf []byte)

Put returns a []byte to pool for future use, which the cap must be exactly 2^n

type LoadOnceCache added in v1.5.5

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

func NewCache added in v1.5.5

func NewCache() *LoadOnceCache

func (*LoadOnceCache) Load added in v1.5.5

func (c *LoadOnceCache) Load(key string) (interface{}, bool)

func (*LoadOnceCache) LoadFromCacheOrRawDisk added in v1.5.7

func (c *LoadOnceCache) LoadFromCacheOrRawDisk(file string) (interface{}, []byte, error)

func (*LoadOnceCache) Put added in v1.5.5

func (c *LoadOnceCache) Put(key string, data interface{}, ttl time.Duration)

func (*LoadOnceCache) Remove added in v1.5.5

func (c *LoadOnceCache) Remove(key string)

Jump to

Keyboard shortcuts

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