posixmq

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AttributeNonBlocking = AttributeFlag(OpenNonBlocking)
	AttributeBlocking    = AttributeFlag(0)
)

Variables

View Source
var (
	NotifyNone   int // Registers a handler but sends no signal
	NotifySignal int
)

Functions

func DefaultMessageSize

func DefaultMessageSize() (int, error)

func DefaultQueueSize

func DefaultQueueSize() (int, error)

func MaxMessageSize

func MaxMessageSize() (int, error)

func MaxQueueSize

func MaxQueueSize() (int, error)

func MaxQueues

func MaxQueues() (int, error)

func RawClose

func RawClose(mqd int) error

RawClose closes a message queue descriptor.

func RawNotify

func RawNotify(mq int, notify *Notify) error

RawNotify sets up a notification mechanism for a message queue.

func RawOpen

func RawOpen(name string, oflag OpenFlag, mode int, attr *Attributes) (int, error)

RawOpen validates the name and opens a message queue. One of OpenReadOnly, OpenWriteOnly, or OpenReadWrite must be set. If opening with OpenCreate mode and attr must be set.

func RawSendReceive

func RawSendReceive[P uint | *uint](mqd int, dl deadline.Deadline, buf []byte, priority P) (int, error)

RawSendReceive sends or receives a message depending on the type of P.

  • uint: Sends buf with the priority to mpd. On success (0, nil) is returned.
  • *uint: Receives into buf from mqd and stores the priority in the provided pointer. The int returned is the size of the message.

If dl does not return a Deadline, the operation will block unless OpenNonBlocking was specified.

func RawUnlink(name string) error

RawUnlink removes the message queue with the specified name from the system. The system will free the queue once all instances are closed.

func ValidateName

func ValidateName(name string) (string, error)

ValidateName checks if a name is valid and returns it without the initial slash. The name must start with '/', be non-empty, and contain no other '/' characters.

Types

type AttributeFlag

type AttributeFlag OpenFlag

func (AttributeFlag) String

func (af AttributeFlag) String() string

String converts the AttributeFlag to a human-readable string.

type Attributes

type Attributes struct {
	// Flags can only be 0 or [OpenNonBlocking].
	Flags AttributeFlag `json:"mq_flags"`
	// MaxQueueSize is the max size of the queue.
	MaxQueueSize int `json:"mq_maxmsg"`
	// MaxMessageSize is the max size of a message.
	MaxMessageSize int `json:"mq_msgsize"`
	// NumCurrMessages is the number of messages in the queue.
	NumCurrMessages int `json:"mq_curmsgs"`
}

func RawGetSetAttributes

func RawGetSetAttributes(mqd int, newAttr *Attributes) (attr Attributes, err error)

RawGetSetAttributes retrieves or modifies the attributes of a message queue. - If newAttr is nil, it retrieves the current attributes of the queue. - If newAttr is provided, it updates the blocking flag and returns the attributes before the change.

type ErrBadFileDescriptor

type ErrBadFileDescriptor struct {
	sys.Err[ErrBadFileDescriptor]
}

func (ErrBadFileDescriptor) Errno

func (e ErrBadFileDescriptor) Errno() unix.Errno

func (ErrBadFileDescriptor) Error

func (e ErrBadFileDescriptor) Error() string

type ErrGetSetAttrInvalidFlags

type ErrGetSetAttrInvalidFlags struct {
	sys.Err[ErrGetSetAttrInvalidFlags]
}

func (ErrGetSetAttrInvalidFlags) Errno

func (ErrGetSetAttrInvalidFlags) Error

type ErrNameContainedMultipleSlash

type ErrNameContainedMultipleSlash struct {
	sys.Err[ErrNameContainedMultipleSlash]
}

func (ErrNameContainedMultipleSlash) Errno

func (ErrNameContainedMultipleSlash) Error

type ErrNameEmpty

type ErrNameEmpty struct {
	sys.Err[ErrNameEmpty]
}

func (ErrNameEmpty) Errno

func (ErrNameEmpty) Errno() unix.Errno

func (ErrNameEmpty) Error

func (ErrNameEmpty) Error() string

type ErrNameInvalid

type ErrNameInvalid struct {
	sys.Err[ErrNameInvalid]
}

func (ErrNameInvalid) Errno

func (ErrNameInvalid) Errno() unix.Errno

func (ErrNameInvalid) Error

func (ErrNameInvalid) Error() string

type ErrNameTooLong

type ErrNameTooLong struct {
	sys.Err[ErrNameTooLong]
}

func (ErrNameTooLong) Errno

func (err ErrNameTooLong) Errno() unix.Errno

func (ErrNameTooLong) Error

func (err ErrNameTooLong) Error() string

type ErrNoMemory

type ErrNoMemory struct {
	sys.Err[ErrNoMemory]
}

func (ErrNoMemory) Errno

func (err ErrNoMemory) Errno() unix.Errno

func (ErrNoMemory) Error

func (err ErrNoMemory) Error() string

type ErrNotifyBusy

type ErrNotifyBusy struct {
	sys.Err[ErrNotifyBusy]
}

func (ErrNotifyBusy) Errno

func (ErrNotifyBusy) Errno() unix.Errno

func (ErrNotifyBusy) Error

func (ErrNotifyBusy) Error() string

type ErrNotifyInvalid

type ErrNotifyInvalid struct {
	sys.Err[ErrNotifyInvalid]
}

func (ErrNotifyInvalid) Errno

func (ErrNotifyInvalid) Errno() unix.Errno

func (ErrNotifyInvalid) Error

func (ErrNotifyInvalid) Error() string

type ErrOpenBadAccess

type ErrOpenBadAccess struct {
	sys.Err[ErrOpenBadAccess]
}

func (ErrOpenBadAccess) Errno

func (ErrOpenBadAccess) Errno() unix.Errno

func (ErrOpenBadAccess) Error

func (ErrOpenBadAccess) Error() string

type ErrOpenExists

type ErrOpenExists struct {
	sys.Err[ErrOpenExists]
}

func (ErrOpenExists) Errno

func (ErrOpenExists) Errno() unix.Errno

func (ErrOpenExists) Error

func (ErrOpenExists) Error() string

type ErrOpenInvalid

type ErrOpenInvalid struct {
	sys.Err[ErrOpenInvalid]
}

func (ErrOpenInvalid) Errno

func (ErrOpenInvalid) Errno() unix.Errno

func (ErrOpenInvalid) Error

func (ErrOpenInvalid) Error() string

type ErrOpenNoEntry

type ErrOpenNoEntry struct {
	sys.Err[ErrOpenNoEntry]
}

func (ErrOpenNoEntry) Errno

func (ErrOpenNoEntry) Errno() unix.Errno

func (ErrOpenNoEntry) Error

func (ErrOpenNoEntry) Error() string

type ErrOpenNoSpace

type ErrOpenNoSpace struct {
	sys.Err[ErrOpenNoSpace]
}

func (ErrOpenNoSpace) Errno

func (ErrOpenNoSpace) Errno() unix.Errno

func (ErrOpenNoSpace) Error

func (ErrOpenNoSpace) Error() string

type ErrOpenProcessLimitReached

type ErrOpenProcessLimitReached struct {
	sys.Err[ErrOpenProcessLimitReached]
}

func (ErrOpenProcessLimitReached) Errno

func (ErrOpenProcessLimitReached) Error

type ErrOpenSystemLimitReached

type ErrOpenSystemLimitReached struct {
	sys.Err[ErrOpenSystemLimitReached]
}

func (ErrOpenSystemLimitReached) Errno

func (ErrOpenSystemLimitReached) Error

type ErrReceiveInvalidFileDescriptor

type ErrReceiveInvalidFileDescriptor struct {
	sys.Err[ErrReceiveInvalidFileDescriptor]
}

func (ErrReceiveInvalidFileDescriptor) Errno

func (ErrReceiveInvalidFileDescriptor) Error

type ErrRecvEmptyQueue

type ErrRecvEmptyQueue struct {
	sys.Err[ErrRecvEmptyQueue]
}

func (ErrRecvEmptyQueue) Errno

func (ErrRecvEmptyQueue) Errno() unix.Errno

func (ErrRecvEmptyQueue) Error

func (ErrRecvEmptyQueue) Error() string

type ErrRecvInvalidMessageSize

type ErrRecvInvalidMessageSize struct {
	sys.Err[ErrRecvInvalidMessageSize]
}

func (ErrRecvInvalidMessageSize) Errno

func (ErrRecvInvalidMessageSize) Error

type ErrSendFullQueue

type ErrSendFullQueue struct {
	sys.Err[ErrSendFullQueue]
}

func (ErrSendFullQueue) Errno

func (ErrSendFullQueue) Errno() unix.Errno

func (ErrSendFullQueue) Error

func (ErrSendFullQueue) Error() string

type ErrSendInvalidFileDescriptor

type ErrSendInvalidFileDescriptor struct {
	sys.Err[ErrSendInvalidFileDescriptor]
}

func (ErrSendInvalidFileDescriptor) Errno

func (ErrSendInvalidFileDescriptor) Error

type ErrSendInvalidMessageSize

type ErrSendInvalidMessageSize struct {
	sys.Err[ErrSendInvalidMessageSize]
}

func (ErrSendInvalidMessageSize) Errno

func (ErrSendInvalidMessageSize) Error

type ErrSendRecvInterrupted

type ErrSendRecvInterrupted struct {
	sys.Err[ErrSendRecvInterrupted]
}

func (ErrSendRecvInterrupted) Errno

func (ErrSendRecvInterrupted) Error

type ErrSendRecvInvalidTimeout

type ErrSendRecvInvalidTimeout struct {
	sys.Err[ErrSendRecvInvalidTimeout]
}

func (ErrSendRecvInvalidTimeout) Errno

func (ErrSendRecvInvalidTimeout) Error

type ErrSendRecvTimeout

type ErrSendRecvTimeout struct {
	sys.Err[ErrSendRecvTimeout]
}

func (ErrSendRecvTimeout) Errno

func (ErrSendRecvTimeout) Errno() unix.Errno

func (ErrSendRecvTimeout) Error

func (ErrSendRecvTimeout) Error() string

type ErrUnlinkNoMessageQueue

type ErrUnlinkNoMessageQueue struct {
	sys.Err[ErrUnlinkNoMessageQueue]
}

func (ErrUnlinkNoMessageQueue) Errno

func (ErrUnlinkNoMessageQueue) Error

type ErrUnlinkNoPermission

type ErrUnlinkNoPermission struct {
	sys.Err[ErrUnlinkNoPermission]
}

func (ErrUnlinkNoPermission) Errno

func (ErrUnlinkNoPermission) Error

func (ErrUnlinkNoPermission) Error() string

type MQ

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

MQ allows for structured usage of POSIX message queues.

func New

func New(name string, opts ...MQOption) (mq *MQ, err error)

New opens a message queue.

func (*MQ) ClearNotify added in v0.0.2

func (mq *MQ) ClearNotify() error

ClearNotify clears any registered notifications.

func (*MQ) Close

func (mq *MQ) Close() error

Close closes the message queue.

func (*MQ) GetAttr

func (mq *MQ) GetAttr() (oldValue Attributes, _ error)

GetAttr gets the message queue's attributes.

func (*MQ) Mode

func (mq *MQ) Mode() int

Mode returns the mode used to create the queue. Returns 0 if OpenCreate was not used.

func (*MQ) Mqd

func (mq *MQ) Mqd() int

Mqd returns the message queue descriptor for advanced usage.

func (*MQ) Name

func (mq *MQ) Name() string

Name returns the name of the queue.

func (*MQ) Notify

func (mq *MQ) Notify(sig unix.Signal) error

Notify sets up notifications for the queue using a signal.

func (*MQ) Oflag

func (mq *MQ) Oflag() OpenFlag

Oflag returns the flags used to open the queue.

func (*MQ) Receive

func (mq *MQ) Receive(dl deadline.Deadline) (data []byte, priority uint, _ error)

Receive retrieves a message from the queue. The returned data is invalid after the next call to Receive.

func (*MQ) Send

func (mq *MQ) Send(dl deadline.Deadline, data []byte, priority uint) error

Send sends a message to the queue.

func (*MQ) SetBlocking

func (mq *MQ) SetBlocking(blocking bool) (Attributes, error)

SetBlocking sets or clears the blocking flag on the message queue.

func (mq *MQ) Unlink() error

Unlink closes and unlinks the queue. The system will free it once all processes close it.

type MQOption

type MQOption interface {
	// contains filtered or unexported methods
}

MQOption represents options that can be applied when creating or opening a message queue.

func OptionCreateArgs

func OptionCreateArgs(mode, maxMessageSize, maxQueueSize int) MQOption

OptionCreateArgs supplies arguments for creating a queue with OpenCreate.

func OptionOflag

func OptionOflag(oflag OpenFlag) MQOption

OptionOflag sets the oflag parameter for opening the queue.

type Notify

type Notify struct {
	Notify int         `json:"sigev_notify"` // Notification type (e.g., NotifyNone, NotifySignal).
	Signo  unix.Signal `json:"sigev_signo"`  // Signal number to use for signal-based notifications.
}

Notify defines the structure for queue notification settings.

type OpenFlag

type OpenFlag int

OpenFlag represents the flags used for opening a message queue.

const (
	OpenReadOnly  OpenFlag = unix.O_RDONLY
	OpenWriteOnly OpenFlag = unix.O_WRONLY
	OpenReadWrite OpenFlag = unix.O_RDWR

	OpenCloseOnExec OpenFlag = unix.O_CLOEXEC
	OpenCreate      OpenFlag = unix.O_CREAT
	OpenExclusive   OpenFlag = unix.O_EXCL
	OpenNonBlocking OpenFlag = unix.O_NONBLOCK

	DefaultOpenFlags   = OpenReadOnly | OpenCloseOnExec
	DefaultCreateFlags = OpenWriteOnly | OpenCloseOnExec | OpenCreate | OpenExclusive
)

func (OpenFlag) String

func (f OpenFlag) String() string

String identifies the set flags and combines them into a readable format. Only valid flags will be in the output.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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