mq

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2016 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package mq implements interprocess queues logic.

Index

Constants

View Source
const (
	// DefaultLinuxMqMaxSize is the default linux mq queue size
	DefaultLinuxMqMaxSize = 8
	// DefaultLinuxMqMessageSize is the linux mq message size
	DefaultLinuxMqMessageSize = 8192
)
View Source
const (
	// O_NONBLOCK flag makes mq read/write operations nonblocking.
	O_NONBLOCK = common.O_NONBLOCK
)

Variables

This section is empty.

Functions

func Destroy

func Destroy(name string) error

Destroy permanently removes mq object.

func DestroyLinuxMessageQueue

func DestroyLinuxMessageQueue(name string) error

DestroyLinuxMessageQueue removes the queue permanently.

func DestroySystemVMessageQueue

func DestroySystemVMessageQueue(name string) error

DestroySystemVMessageQueue permanently removes queue with a given name.

func SetLinuxMqBlocking

func SetLinuxMqBlocking(name string, block bool) error

SetLinuxMqBlocking sets whether the operations on a linux mq block. This will apply for all send/receive operations on any instance of the linux mq with the given name.

Types

type LinuxMessageQueue

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

LinuxMessageQueue is a linux-specific ipc mechanism based on message passing.

func CreateLinuxMessageQueue

func CreateLinuxMessageQueue(name string, perm os.FileMode, maxQueueSize, maxMsgSize int) (*LinuxMessageQueue, error)

CreateLinuxMessageQueue creates new queue with the given name and permissions. 'execute' permission cannot be used.

func OpenLinuxMessageQueue

func OpenLinuxMessageQueue(name string, flags int) (*LinuxMessageQueue, error)

OpenLinuxMessageQueue opens an existing message queue. Returns an error, if it does not exist.

func (*LinuxMessageQueue) Cap

func (mq *LinuxMessageQueue) Cap() (int, error)

Cap returns size of the mq buffer.

func (*LinuxMessageQueue) Close

func (mq *LinuxMessageQueue) Close() error

Close closes the queue.

func (*LinuxMessageQueue) Destroy

func (mq *LinuxMessageQueue) Destroy() error

Destroy closes the queue and removes it permanently.

func (*LinuxMessageQueue) ID

func (mq *LinuxMessageQueue) ID() int

ID returns unique id of the queue.

func (*LinuxMessageQueue) Notify

func (mq *LinuxMessageQueue) Notify(ch chan<- int) error

Notify notifies about new messages in the queue by sending id of the queue to the channel. If there are messages in the queue, no notification will be sent unless all of them are read.

func (*LinuxMessageQueue) NotifyCancel

func (mq *LinuxMessageQueue) NotifyCancel() error

NotifyCancel cancels notification subscribtion.

func (*LinuxMessageQueue) Receive

func (mq *LinuxMessageQueue) Receive(data []byte) error

Receive receives a message. It blocks if the queue is empty.

func (*LinuxMessageQueue) ReceivePriority

func (mq *LinuxMessageQueue) ReceivePriority(data []byte) (int, error)

ReceivePriority receives a message, returning its priority. It blocks if the queue is empty.

func (*LinuxMessageQueue) ReceiveTimeout

func (mq *LinuxMessageQueue) ReceiveTimeout(data []byte, timeout time.Duration) error

ReceiveTimeout receives a message. It blocks if the queue is empty, waiting for a message unless timeout is passed.

func (*LinuxMessageQueue) ReceiveTimeoutPriority

func (mq *LinuxMessageQueue) ReceiveTimeoutPriority(data []byte, timeout time.Duration) (int, error)

ReceiveTimeoutPriority receives a message, returning its priority. It blocks if the queue is empty, waiting for a message unless timeout is passed.

func (*LinuxMessageQueue) Send

func (mq *LinuxMessageQueue) Send(data []byte) error

Send sends a message with a default (0) priority. It blocks if the queue is full.

func (*LinuxMessageQueue) SendPriority

func (mq *LinuxMessageQueue) SendPriority(data []byte, prio int) error

SendPriority sends a message with a given priority. It blocks if the queue is full.

func (*LinuxMessageQueue) SendTimeout

func (mq *LinuxMessageQueue) SendTimeout(data []byte, timeout time.Duration) error

SendTimeout sends a message with a default (0) priority. It blocks if the queue is full, waiting for a message unless timeout is passed.

func (*LinuxMessageQueue) SendTimeoutPriority

func (mq *LinuxMessageQueue) SendTimeoutPriority(data []byte, prio int, timeout time.Duration) error

SendTimeoutPriority sends a message with a given priority. It blocks if the queue is full, waiting for a message unless timeout is passed.

func (*LinuxMessageQueue) SetBlocking

func (mq *LinuxMessageQueue) SetBlocking(block bool) error

SetBlocking sets whether the send/receive operations on the queue block. This applies to the current instance only.

type Messenger

type Messenger interface {
	// Send sends the data. It blocks if there are no readers and the queue if full
	Send(data []byte) error
	// Receive reads data from the queue. It blocks if the queue is empty
	Receive(data []byte) error
	io.Closer
}

Messenger is an interface which must be satisfied by any message queue implementation on any platform.

func New

func New(name string, perm os.FileMode) (Messenger, error)

New creates a mq with a given name and permissions. It uses the default implementation. If there are several implementations on a platform, you can use explicit create functions.

name - unique queue name.
perm - permissions for the new queue. this may not be supported by all implementations.

func Open

func Open(name string, flags int) (Messenger, error)

Open opens a mq with a given name and flags. It uses the default implementation. If there are several implementations on a platform, you can use explicit create functions.

name  - unique queue name.
flags - a set of flags can be used to specify r/w options. this may not be supported by all implementations.

type SystemVMessageQueue

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

SystemVMessageQueue is a System V ipc mechanism based on message passing.

func CreateSystemVMessageQueue

func CreateSystemVMessageQueue(name string, perm os.FileMode) (*SystemVMessageQueue, error)

CreateSystemVMessageQueue creates new queue with the given name and permissions. 'execute' permission cannot be used.

func OpenSystemVMessageQueue

func OpenSystemVMessageQueue(name string, flags int) (*SystemVMessageQueue, error)

OpenSystemVMessageQueue opens existing message queue.

func (*SystemVMessageQueue) Close

func (mq *SystemVMessageQueue) Close() error

Close closes the queue. As there is no need to close SystemV mq, this function returns nil. It was added to satisfy io.Closer

func (*SystemVMessageQueue) Destroy

func (mq *SystemVMessageQueue) Destroy() error

Destroy closes the queue and removes it permanently.

func (*SystemVMessageQueue) Receive

func (mq *SystemVMessageQueue) Receive(data []byte) error

Receive receives a message. It blocks if the queue is empty.

func (*SystemVMessageQueue) Send

func (mq *SystemVMessageQueue) Send(data []byte) error

Send sends a message. It blocks if the queue is full.

func (*SystemVMessageQueue) SetBlocking

func (mq *SystemVMessageQueue) SetBlocking(block bool) error

SetBlocking sets whether the send/receive operations on the queue block.

type TimedMessenger

type TimedMessenger interface {
	Messenger
	// SendTimeout sends the data. It blocks if there are no readers and the queue if full.
	// It wait for not more, than timeout.
	SendTimeout(data []byte, timeout time.Duration) error
	// ReceiveTimeout reads data from the queue. It blocks if the queue is empty.
	// It wait for not more, than timeout.
	ReceiveTimeout(data []byte, timeout time.Duration) error
}

TimedMessenger is a Messenger, which supports send/receive timeouts.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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