Documentation
¶
Overview ¶
Package common contains basic routines needed by other modules in go-dpdk package.
Index ¶
- Constants
- Variables
- func Assert(t testing.TB, fail bool) func(bool, ...interface{})
- func CBytes(a Allocator, b []byte) unsafe.Pointer
- func CString(a Allocator, s string) *C.char
- func CopyFromBytes(dst unsafe.Pointer, src []byte, max int) int
- func CopyToBytes(dst []byte, src unsafe.Pointer, max int) int
- func IntOrErr(n interface{}) (int, error)
- func IntToErr(n interface{}) error
- func MakeSlice(buf unsafe.Pointer, max int) []byte
- func MallocT(a Allocator, ptr interface{}) unsafe.Pointer
- func PutUint16(b binary.ByteOrder, dst unsafe.Pointer, d uint16)
- func PutUint32(b binary.ByteOrder, dst unsafe.Pointer, d uint32)
- func PutUint64(b binary.ByteOrder, dst unsafe.Pointer, d uint64)
- func RteErrno() error
- func SplitFunc(s *Splitter) bufio.SplitFunc
- type Allocator
- type AllocatorSession
- type ObjectID
- type Registry
- type RteAlloc
- type Splitter
- type StdAlloc
Constants ¶
const (
SocketIDAny = int(C.SOCKET_ID_ANY)
)
SocketIDAny represents selection for any NUMA socket.
Variables ¶
var ( ErrNoConfig = errors.New("Missing rte_config") ErrSecondary = errors.New("Operation not allowed in secondary processes") )
Functions ¶
func Assert ¶
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
CBytes creates a copy of byte slice with given Allocator. It's analogous to C.CBytes.
func CString ¶ added in v0.0.3
CString a copy of a string with given Allocator. It's analogous to C.CString.
func CopyFromBytes ¶ added in v0.0.3
CopyFromBytes copies no more than max bytes from src to an area pointed to by dst.
func CopyToBytes ¶ added in v0.0.3
CopyFromBytes copies no more than max bytes from an area pointed to by src to dst.
func IntOrErr ¶
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 MallocT ¶ added in v0.0.3
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 */
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.
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.
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
}