common

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2016 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IpcCreate flag tells a function to create an object if key is nonexistent.
	IpcCreate = 00001000
	// IpcExcl flag tells a function to create an object if key is nonexistent and fail if key exists.
	IpcExcl = 00002000
	// IpcNoWait flag tell a function to return error on wait.
	IpcNoWait = 00004000

	// IpcRmid flag tells a function to remove resource.
	IpcRmid = 0
	// IpcSet flag tells a function to set ipc_perm options.
	IpcSet = 1
	// IpcStat flag tells a function to get ipc_perm options.
	IpcStat = 2
	// IpcInfo flag tells a function to retrieve information about an object.
	IpcInfo = 3
)
View Source
const (
	// O_NONBLOCK flag tell some functions not to block.
	// Its value does not interfere with O_* constants from 'os' package.
	O_NONBLOCK = syscall.O_NONBLOCK
)

Variables

This section is empty.

Functions

func AbsTimeoutToTimeSpec

func AbsTimeoutToTimeSpec(timeout time.Duration) *unix.Timespec

AbsTimeoutToTimeSpec converts given timeout value to absulute value of unix.Timespec.

func CallTimeout added in v0.4.0

func CallTimeout(f func(time.Duration) bool, timeout time.Duration)

CallTimeout calls f in a loop allowing it to run for at least 'timeout'. It calls f, measuring its runtime:

if f returned false, or its cumulative runtime exceeded timeout, CallTimeout returns.
otherwise CallTimeout subtracts runtime from timeout anf calls 'f' with the updated value.

func FlagsForAccess

func FlagsForAccess(flag int) int

FlagsForAccess extracts os.O_RDONLY, os.O_WRONLY, os.O_RDWR, and O_NONBLOCK flag values.

func FlagsForOpen

func FlagsForOpen(flag int) int

FlagsForOpen extracts os.O_CREATE and os.O_EXCL flag values.

func IsInterruptedSyscallErr

func IsInterruptedSyscallErr(err error) bool

IsInterruptedSyscallErr returns true, if the given error is a syscall.EINTR error.

func IsTimeoutErr

func IsTimeoutErr(err error) bool

IsTimeoutErr returns true, if the given error is a temporary syscall error.

func NewTimeoutError added in v0.5.0

func NewTimeoutError(op string) error

NewTimeoutError returns new syscall error with EAGAIN code.

func OpenOrCreate

func OpenOrCreate(creator func(bool) error, flag int) (bool, error)

OpenOrCreate performs open/create file operation according to the given mode. It allows to find out if the object was opened or created.

creator is the function which performs actual operation:
	if is called with 'true', if it must create an object, and with false otherwise.
	it must return an 'not exists error' if the param is false, and the object does not exist.
	it must return an 'already exists error' if the param is true, and the object already exists.
flag is the combination of open flags from os package.
	If flag == os.O_CREATE, OpenOrCreate makes several attempts to open or create an object,
	and analyzes the return error. It tries to open the object first.

func SyscallErrHasCode

func SyscallErrHasCode(err error, code syscall.Errno) bool

SyscallErrHasCode returns true, if given error is a syscall error with given code.

func SyscallNameFromErr

func SyscallNameFromErr(err error) string

SyscallNameFromErr returns name of a syscall from a syscall errror.

func TimeoutToTimeSpec

func TimeoutToTimeSpec(timeout time.Duration) *unix.Timespec

TimeoutToTimeSpec converts given timeout value to relative value of unix.Timespec.

func TmpFilename

func TmpFilename(name string) string

TmpFilename returns a full path for a temporary file with the given name.

func UninterruptedSyscall

func UninterruptedSyscall(f func() error) error

UninterruptedSyscall runs a function in a loop. If an error, returned by the function is a syscall.EINTR error, it runs the function again. Otherwise, it returns the error.

func UninterruptedSyscallTimeout

func UninterruptedSyscallTimeout(f func(time.Duration) error, timeout time.Duration) error

UninterruptedSyscallTimeout runs a function in a loop. It acts like UninterruptedSyscall, however, before every run it recalculates timeout value according to the passed time.

Types

type Key

type Key uint64

Key is an unsigned integer value considered to be unique for a unique name.

func KeyForName

func KeyForName(name string) (Key, error)

KeyForName generates a key for given path.

Jump to

Keyboard shortcuts

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