NAME | SYNOPSIS | FEATURES | DESCRIPTION | RETURN VALUE | ERRORS | ATTRIBUTES | SEE ALSO
#include <mqueue.h>mqd_t mq_open(const char *name, int oflag [, mode_t mode, mq_attr *attr]);
POSIX_MQ
The mq_open system call establishes the connection between a c_actor and a message queue with a message queue descriptor. It creates a message queue descriptor that refers to that message queue. The message queue descriptor is used by other functions to refer to that message queue. The name argument points to a string naming a message queue. The name does not appear in the file system. The name argument points to a Posix object name. The message queue name cannot exceed MQ_PATHMAX characters as returned by sysconf(3POSIX).
The oflag argument requests the desired receive and/or send access to the message queue. The requested access permission to receive messages or send messages is granted if the calling c_actor would be granted read or write access, respectively, to an equivalently protected file.
The value of oflag is the bitwise inclusive OR of values from the following list. Applications must specify precisely one of the first three values (access modes) below:
Open the message queue for receiving messages. The c_actor can use the returned message queue descriptor with mq_receive, but not mq_send. A message queue may be opened multiple times in the same or different c_actors for receiving messages.
Open the queue for sending messages. The c_actor can use the returned message queue descriptor with mq_send but not mq_receive. A message queue may be opened multiple times in the same or different c_actors for sending messages.
Open the queue for both receiving and sending messages. The c_actor can use any of the functions allowed for O_RDONLY and O_WRONLY. A message queue may be opened multiple times in the same or different c_actors for sending and receiving messages.
Any combination of the remaining flags may be specified in the value of oflag:
This option is used to create a message queue, and it requires two additional arguments: mode which is of type mode_t, and attr, which is a pointer to a mq_attr structure defined in mq_getattr(2POSIX). If the posix object name, name, has already been used to create a message queue that still exists, this flag has no effect, except as noted under O_EXCL below. Otherwise, a message queue is created without any messages in it. The owner ID of the message queue is set to the user ID of the c_actor, the group ID of the message queue is set to the group ID of the c_actor. If attr in non-NULL, and the calling c_actor has the appropriate privilege on name, the message queue mq_maxmsg and mq_msgsize attributes are set to the values of the corresponding members in the mq_attr structure referred to by attr. If attr is NULL, the message queue is created with default message queue attributes as returned by sysconf(3POSIX). If attr is non-NULL, but the calling c_actors does not have the appropriate privilege on name, mq_open will fail and return an error without creating the message queue.
If O_EXCL and O_CREAT are set, mq_open will fail if the message queue name exists. The check for the existence of the message queue and the creation of the message queue if it does not exist is atomic with respect to other c_actors executing mq_open naming the same name with O_EXCL and O_CREAT set. If O_EXCL is set and O_CREAT is not set this flag is ignored.
The setting of this flag is associated with the open message queue descriptor, and determines whether a mq_send or mq_receive will wait for resources or messages that are not currently available, or fail with errno set to [EAGAIN].
Note that mq_open does not add or remove messages from the queue.
Upon successful completion, mq_open returns a message queue descriptor. Otherwise, it returns (mqd_t) -1 and sets errno to indicate the error condition.
The function mq_open is not supported.
The MQ feature [_POSIX_MESSAGE_PASSING] option (see sysconf(3POSIX)) is not configured.
The message queue exists and the permissions specified by oflag are denied, or the message queue does not exist and permission to create the message queue is denied.
O_CREAT and O_EXCL are set and the named message queue already exists.
The name string exceeds MQ_PATHMX.
The access modes specified by oflag are incompatible.
attr is non-NULL and the mq_maxmsg and mq_msgsize members in the mq_attr structure are invalid.
Too many message queue descriptors are currently in use by this c_actor.
There is insufficient space for the creation of the new message queue.
O_CREAT is not set and the named message queue does not exist.
name or attr points outside the allocated address space of the c_actor.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
Interface Stability | Evolving |
mq_close(2POSIX), mq_receive(2POSIX), mq_send(2POSIX), mq_setattr(2POSIX), mq_getattr(2POSIX), mq_unlink(2POSIX), sysconf(3POSIX)
NAME | SYNOPSIS | FEATURES | DESCRIPTION | RETURN VALUE | ERRORS | ATTRIBUTES | SEE ALSO