common

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2019 License: BSD-3-Clause Imports: 12 Imported by: 1

Documentation

Overview

Package common contains basic routines needed by other modules in go-dpdk package.

Index

Constants

View Source
const (
	SocketIDAny = int(C.SOCKET_ID_ANY)
)

SocketIDAny represents selection for any NUMA socket.

Variables

View Source
var (
	ErrNoConfig  = errors.New("Missing rte_config")
	ErrSecondary = errors.New("Operation not allowed in secondary processes")
)
View Source
var (
	ErrUnprintable  = errors.New("unprintable char")
	ErrOpenQuote    = errors.New("no closing quote")
	DefaultSplitter = &Splitter{
		unicode.IsSpace,
		func(r rune) (rune, bool) {
			if r == '"' {
				return '"', true
			}
			if r == '\'' {
				return '\'', true
			}
			return ' ', false
		},
		false,
	}
)

Functions

func Assert

func Assert(t testing.TB, fail bool) func(bool, ...interface{})

Assert allows to perform one-lined tests and, optionally, print some diagnostic info if the test failed.

If fail is true, test failure will cause panic and cease test execution.

func CBytes added in v0.0.3

func CBytes(a Allocator, b []byte) unsafe.Pointer

CBytes creates a copy of byte slice with given Allocator. It's analogous to C.CBytes.

func CString added in v0.0.3

func CString(a Allocator, s string) *C.char

CString a copy of a string with given Allocator. It's analogous to C.CString.

func CopyFromBytes added in v0.0.3

func CopyFromBytes(dst unsafe.Pointer, src []byte, max int) int

CopyFromBytes copies no more than max bytes from src to an area pointed to by dst.

func CopyToBytes added in v0.0.3

func CopyToBytes(dst []byte, src unsafe.Pointer, max int) int

CopyFromBytes copies no more than max bytes from an area pointed to by src to dst.

func IntOrErr

func IntOrErr(n interface{}) (int, error)

IntOrErr returns error as in Errno in case n is negative. Otherwise, the value itself with nil error will be returned.

If n is nil, then n = RteErrno() if n is not nil and not a signed integer, function panics.

func IntToErr added in v0.0.3

func IntToErr(n interface{}) error

IntToErr converts n into an 'errno' error. If n is not a signed integer it will panic.

func MakeSlice added in v0.0.3

func MakeSlice(buf unsafe.Pointer, max int) []byte

MakeSlice returns byte slice specified by pointer and of len max.

func MallocT added in v0.0.3

func MallocT(a Allocator, ptr interface{}) unsafe.Pointer

MallocT allocates an object by its type. The type and its size is derived from ptr which is a pointer to pointer of required type where new object will be stored. For example:

var x *int
a := NewAlloc()
defer a.Flush()
MallocT(a, &x)
/* x is now an allocated pointer */

func PutUint16 added in v0.0.3

func PutUint16(b binary.ByteOrder, dst unsafe.Pointer, d uint16)

PutUint16 stores uint16 value into an area pointed to dst.

func PutUint32 added in v0.0.3

func PutUint32(b binary.ByteOrder, dst unsafe.Pointer, d uint32)

PutUint32 stores uint32 value into an area pointed to dst.

func PutUint64 added in v0.0.3

func PutUint64(b binary.ByteOrder, dst unsafe.Pointer, d uint64)

PutUint64 stores uint64 value into an area pointed to dst.

func RteErrno

func RteErrno() error

RteErrno returns rte_errno variable.

func SplitFunc

func SplitFunc(s *Splitter) bufio.SplitFunc

Types

type Allocator added in v0.0.3

type Allocator interface {
	// Malloc allocates memory of length size.
	Malloc(size uintptr) unsafe.Pointer
	// Free releases previously allocated memory pointed to by p.
	Free(p unsafe.Pointer)
	// Realloc allocates memory of length size.
	Realloc(p unsafe.Pointer, size uintptr) unsafe.Pointer
}

Allocator provides allocating and freeing of objects. It should be used with Cgo to withstand the rule of not allowing Go pointers inside a Go pointer. The allocator allows to defer freeing of objects so instead of freeing objects individually you may delete them by Flush at once and abandon allocator instance.

type AllocatorSession added in v0.0.3

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

AllocatorSession wraps Allocator and storage for allocated pointers. Useful to perform allocations and free them with one call.

func NewAllocatorSession added in v0.0.3

func NewAllocatorSession(mem Allocator) *AllocatorSession

NewAllocatorSession creates new AllocatorSession.

func (*AllocatorSession) Flush added in v0.0.3

func (s *AllocatorSession) Flush()

Flush releases all previously allocated memory in this session.

func (*AllocatorSession) Free added in v0.0.3

func (s *AllocatorSession) Free(p unsafe.Pointer)

Free implements Allocator.

func (*AllocatorSession) Malloc added in v0.0.3

func (s *AllocatorSession) Malloc(size uintptr) unsafe.Pointer

Malloc implements Allocator.

func (*AllocatorSession) Realloc added in v0.0.3

func (s *AllocatorSession) Realloc(p unsafe.Pointer, size uintptr) unsafe.Pointer

Realloc implements Allocator.

type ObjectID

type ObjectID uint64

type Registry

type Registry interface {
	Create(interface{}) ObjectID
	Read(ObjectID) interface{}
	Update(ObjectID, interface{})
	Delete(ObjectID)
}

Registry implements CRUD operations to map ID and objects.

func NewRegistryArray

func NewRegistryArray() Registry

func NewRegistryMap

func NewRegistryMap() Registry

type RteAlloc added in v0.0.3

type RteAlloc struct {
	// Requested alignment.
	Align uint

	// Requested NUMA node. Set to SocketIDAny if meaningless.
	Socket int
}

RteAlloc implements allocator based on DPDK rte_malloc.h.

func (*RteAlloc) Free added in v0.0.3

func (mem *RteAlloc) Free(p unsafe.Pointer)

Free implements Allocator.

func (*RteAlloc) Malloc added in v0.0.3

func (mem *RteAlloc) Malloc(size uintptr) unsafe.Pointer

Malloc implements Allocator.

func (*RteAlloc) Realloc added in v0.0.3

func (mem *RteAlloc) Realloc(p unsafe.Pointer, size uintptr) unsafe.Pointer

Realloc implements Allocator.

Note: rte_realloc() may not reside on the same NUMA node.

type Splitter

type Splitter struct {
	// True if rune is a white space.
	IsSpace func(rune) bool

	// True if rune is quote. Any rune embraced by the one of these
	// pairs is considered a part of a token even if IsSpace returns
	// true.  A pairs must not contradict white space and another
	// pair.
	//
	// If true, return closing quote rune.
	IsQuote func(rune) (rune, bool)

	// If true, final token is allowed not to contain closing quote.
	// If false, ErrOpenQuote error will be returned if no closing
	// quote found.
	AllowOpenQuote bool
}

type StdAlloc added in v0.0.3

type StdAlloc struct{}

func (*StdAlloc) Free added in v0.0.3

func (mem *StdAlloc) Free(p unsafe.Pointer)

Free implements Allocator.

func (*StdAlloc) Malloc added in v0.0.3

func (mem *StdAlloc) Malloc(size uintptr) unsafe.Pointer

Malloc implements Allocator.

func (*StdAlloc) Realloc added in v0.0.3

func (mem *StdAlloc) Realloc(p unsafe.Pointer, size uintptr) unsafe.Pointer

Realloc implements Allocator.

Jump to

Keyboard shortcuts

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