msg

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2021 License: MIT Imports: 3 Imported by: 1

README

msg

PkgGoDev Build Status Go Report Card LICENSE

Package msg provides a way to use System V message queues.

Get started

Install
go get github.com/hslam/msg
Import
import "github.com/hslam/msg"
Usage
Example

msgsnd

package main

import (
	"github.com/hslam/ftok"
	"github.com/hslam/msg"
	"time"
)

func main() {
	key, err := ftok.Ftok("/tmp", 0x22)
	if err != nil {
		panic(err)
	}
	msgid, err := msg.Get(key, msg.IPC_CREAT|0600)
	if err != nil {
		panic(err)
	}
	defer msg.Remove(msgid)
	err = msg.Send(msgid, 1, []byte("Hello World"), 0600)
	if err != nil {
		panic(err)
	}
	time.Sleep(time.Second * 10)
}

msgrcv

package main

import (
	"fmt"
	"github.com/hslam/ftok"
	"github.com/hslam/msg"
)

func main() {
	key, err := ftok.Ftok("/tmp", 0x22)
	if err != nil {
		panic(err)
	}
	msgid, err := msg.Get(key, 0600)
	if err != nil {
		panic(err)
	}
	text, err := msg.Receive(msgid, 1, 0600)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(text))
}
Output
Hello World
License

This package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)

Author

msg was written by Meng Huang.

Documentation

Overview

Package msg provides a way to use System V message queues.

Index

Constants

View Source
const (
	// IPC_CREAT creates if key is nonexistent
	IPC_CREAT = 01000

	// IPC_EXCL fails if key exists.
	IPC_EXCL = 02000

	// IPC_NOWAIT returns error no wait.
	IPC_NOWAIT = 04000

	// IPC_PRIVATE is private key
	IPC_PRIVATE = 00000

	// SEM_UNDO sets up adjust on exit entry
	SEM_UNDO = 010000

	// IPC_RMID removes identifier
	IPC_RMID = 0
	// IPC_SET sets ipc_perm options.
	IPC_SET = 1
	// IPC_STAT gets ipc_perm options.
	IPC_STAT = 2
)

Variables

View Source
var ErrTooLong = errors.New("Text length is too long")

ErrTooLong is returned when the Text length is bigger than maxText.

Functions

func Get

func Get(key int, msgflg int) (int, error)

Get calls the msgget system call.

func Rcv

func Rcv(msgid int, msgp uintptr, msgsz int, msgtyp uint, msgflg int) (int, error)

Rcv calls the msgrcv system call.

func Receive

func Receive(msgid int, msgType uint, flags int) ([]byte, error)

Receive calls the msgrcv system call.

func Remove

func Remove(msgid int) error

Remove removes the message queue with the given id.

func Send

func Send(msgid int, msgType uint, msgText []byte, flags int) error

Send calls the msgsnd system call.

func Snd

func Snd(msgid int, msgp uintptr, msgsz int, msgflg int) error

Snd calls the msgsnd system call.

The msgsnd() and msgrcv() system calls are used to send messages to, and receive messages from, a System V message queue. The calling process must have write permission on the message queue in order to send a message, and read permission to receive a message. The msgp argument is a pointer to a caller-defined structure of the following general form:

struct msgbuf {
	long mtype;       /* message type, must be > 0 */
	char mtext[1];    /* message data */
};

The mtext field is an array (or other structure) whose size is speci‐ fied by msgsz, a nonnegative integer value. Messages of zero length (i.e., no mtext field) are permitted. The mtype field must have a strictly positive integer value. This value can be used by the re‐ ceiving process for message selection (see the description of ms‐ grcv() below).

Types

This section is empty.

Jump to

Keyboard shortcuts

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