NAME
mqreceive, mqtimedreceive - receive a message from a message queue SYNOPSIS
#include
ssizet mqreceive(mqdt mqdes, char *msgptr, sizet msglen, unsigned *msgprio); #include
#include
ssizet mqtimedreceive(mqdt mqdes, char *msgptr, sizet msglen, unsigned *msgprio, const struct timespec *abstimeout); Link with -lrt. Feature Test Macro Requirements for glibc (see featuretestmacros(7)): mqtimedreceive(): XOPENSOURCE >= 600 || POSIXCSOURCE >= 200112L DESCRIPTION mqreceive() removes the oldest message with the highest priority from the message queue referred to by the descriptor mqdes, and places it in the buffer pointed to by msgptr. The msglen argument specifies the size of the buffer pointed to by msgptr; this must be greater than the mqmsgsize attribute of the queue (see mqgetattr(3)). If msgprio is not NULL, then the buffer to which it points is used to return the pri‐ ority associated with the received message. If the queue is empty, then, by default, mqreceive() blocks until a message becomes available, or the call is interrupted by a signal han‐ dler. If the ONONBLOCK flag is enabled for the message queue descrip‐ tion, then the call instead fails immediately with the error EAGAIN. mqtimedreceive() behaves just like mqreceive(), except that if the queue is empty and the ONONBLOCK flag is not enabled for the message queue description, then abstimeout points to a structure which speci‐ fies a ceiling on the time for which the call will block. This ceiling is an absolute timeout in seconds and nanoseconds since the Epoch,
1970-01-01 00:00:00 +0000 (UTC), and it is specified in the following structure: struct timespec { timet tvsec; /* seconds */ long tvnsec; /* nanoseconds */ }; If no message is available, and the timeout has already expired by the time of the call, mqtimedreceive() returns immediately. RETURN VALUE On success, mqreceive() and mqtimedreceive() return the number of
bytes in the received message; on error, -1 is returned, with errno set to indicate the error. ERRORS EAGAIN The queue was empty, and the ONONBLOCK flag was set for the message queue description referred to by mqdes. EBADF The descriptor specified in mqdes was invalid. EINTR The call was interrupted by a signal handler; see signal(7). EINVAL The call would have blocked, and abstimeout was invalid, either because tvsec was less than zero, or because tvnsec was less than zero or greater than 1000 million. EMSGSIZE msglen was less than the mqmsgsize attribute of the message queue. ETIMEDOUT The call timed out before a message could be transferred. ATTRIBUTES For an explanation of the terms used in this section, see attributes(7). ┌────────────────────────────────┬───────────────┬─────────┐ │Interface │ Attribute │ Value │ ├────────────────────────────────┼───────────────┼─────────┤
│mqreceive(), mqtimedreceive() │ Thread safety │ MT-Safe │ └────────────────────────────────┴───────────────┴─────────┘ CONFORMING TO
POSIX.1-2001. NOTES On Linux, mqtimedreceive() is a system call, and mqreceive() is a library function layered on top of that system call. SEE ALSO mqclose(3), mqgetattr(3), mqnotify(3), mqopen(3), mqsend(3), mqunlink(3), mqoverview(7), time(7) COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2010-09-20 MQRECEIVE(3)