Sun Microsystems, Inc.
spacerspacer
spacer   www.sun.com docs.sun.com | | |  
spacer
black dot
   
A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z
    
 
Realtime Library Functionsmq_receive(3RT)


NAME

 mq_receive - receive a message from a message queue

SYNOPSIS

 
cc [ flag... ] file... -lrt [ library... ]
#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 msg_len, is less than the mq_msgsize member 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 msg_ptr.

If 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, (see mq_open(3RT) and mq_setattr(3RT)), mq_receive() blocks, waiting until a message is enqueued on the message queue, or until mq_receive() is interrupted by a signal. If more than one process (or thread) is waiting to receive a message when a message arrives at an empty queue, then the process of highest priority that has been waiting the longest is selected to receive 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 VALUES

 

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 condition.

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 member of the message queue.
EINTR
The mq_receive() function operation was interrupted by a signal.
ENOSYS
The mq_receive() function is not supported by the system.

The mq_receive() function may fail if:

EBADMSG
A data corruption problem with the message has been detected.

ATTRIBUTES

 

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPEATTRIBUTE VALUE
MT-LevelMT-Safe

SEE ALSO

 

mq_open(3RT), mq_send(3RT), mq_setattr(3RT), attributes(5), mqueue(3HEAD)

NOTES

 

Solaris 2.6 was the first release to support the Asynchronous Input and Output option. Prior to this release, this function always returned -1 and set errno to ENOSYS.


SunOS 5.9Go To TopLast Changed 22 Jun 1998

 
      
      
Copyright 2002 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.