The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

mq_receive - receive a message from a message queue (REALTIME)

 SYNOPSIS



#include <mqueue.h>

ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
    unsigned int *msg_prio);

 DESCRIPTION

The mq_receive() function is used to receive the oldest of the highest priority message(s) from the message queue specified by mqdes. If the size of the buffer in bytes, specified by the msg_len argument, is less than the mq_msgsize attribute of the message queue, the function fails and returns an error. Otherwise, the selected message is removed from the queue and copied to the buffer pointed to by the msg_ptr argument.

If the value of msg_len is greater than {SSIZE_MAX}, the result is implementation-dependent.

If the argument msg_prio is not NULL, the priority of the selected message is stored in the location referenced by msg_prio.

If the specified message queue is empty and O_NONBLOCK is not set in the message queue description associated with mqdes, mq_receive() blocks until a message is enqueued on the message queue or until mq_receive() is interrupted by a signal. If more than one thread is waiting to receive a message when a message arrives at an empty queue and the Priority Scheduling option is supported, then the thread of highest priority that has been waiting the longest will be selected to receive the message. Otherwise, it is unspecified which waiting thread receives the message. If the specified message queue is empty and O_NONBLOCK is set in the message queue description associated with mqdes, no message is removed from the queue, and mq_receive() returns an error.

 RETURN VALUE

Upon successful completion, mq_receive() returns the length of the selected message in bytes and the message is removed from the queue. Otherwise, no message is removed from the queue, the function returns a value of -1, and sets errno to indicate the error.

 ERRORS

The mq_receive() function will fail if:
[EAGAIN]
O_NONBLOCK was set in the message description associated with mqdes, and the specified message queue is empty.
[EBADF]
The mqdes argument is not a valid message queue descriptor open for reading.
[EMSGSIZE]
The specified message buffer size, msg_len, is less than the message size attribute of the message queue.
[EINTR]
The mq_receive() operation was interrupted by a signal.
[ENOSYS]
The mq_receive() function is not supported by this implementation.

The mq_receive() function may fail if:

[EBADMSG]
The implementation has detected a data corruption problem with the message.

 EXAMPLES

None.

 APPLICATION USAGE

None.

 SEE ALSO

mq_send(), <mqueue.h>, msgctl(), msgget(), msgrcv(), msgsnd().

DERIVATION

Derived from the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995)

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]