## NAME

mq_timedreceive() - receive a message from a message queue with timeout

## SYNOPSIS

#include <mqueue.h>

ssize_t mq_timedreceive(mqd_t mqdes , char *msg_ptr,
  size_t msg_len,
  unsigned int *msg_prio,
  const struct timespec *timeout );

## DESCRIPTION

mq_timedreceive() receives the oldest of the highest priority messages from the message queue named by the descriptor mqdes.

If the size of the buffer specified by msg_len is less than the mq_msgsize attribute of the message queue, mq_timedreceive() fails and returns an error. Otherwise, the message from the message queue named by mqdes is copied to the buffer pointed to by msg_ptr and removed from the queue.

If the argument msg_prio is not NULL, the priority of the selected message will be stored in the field pointed to by msg_prio.

If the message queue named by mqdes is empty and O_NONBLOCK is not set in the message queue description associated with mqdes, mq_timedreceive() blocks until a message is queued on the message queue or until the time interval specified in timeout has elapsed. If more than one thread is waiting to receive a message when a message arrives at an empty queue, the thread of highest priority that has waited the longest 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_timedreceive() returns an error with errno set to [EAGAIN].

## RETURN VALUES

Upon successful completion, mq_timedreceive() returns the length of the selected message in bytes and the message will have been 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

EAGAIN
  O_NONBLOCK was set in the message description associated with mqdes , and the specified message queue is empty.
ETIMEDOUT
  The time interval specified by timeout elapsed.
EBADF
  mqdes is not a valid message queue descriptor open for reading.
EMSGSIZE
  msg_len is less than the message size attribute of the message queue.

## SEE ALSO

mq_open(), mq_send(), mq_setattr(), mq_receive()

#### Home page (Kernel)

## < Copyright Rowebots Research Inc. and Multiprocessor Toolsmiths Inc. 1987-2018 >