1MQ_SEND(3)                 Linux Programmer's Manual                MQ_SEND(3)
2
3
4

NAME

6       mq_send, mq_timedsend - send a message to a message queue
7

SYNOPSIS

9       #include <mqueue.h>
10
11       int mq_send(mqd_t mqdes, const char *msg_ptr,
12                     size_t msg_len, unsigned int msg_prio);
13
14       #include <time.h>
15       #include <mqueue.h>
16
17       int mq_timedsend(mqd_t mqdes, const char *msg_ptr,
18                     size_t msg_len, unsigned int msg_prio,
19                     const struct timespec *abs_timeout);
20
21       Link with -lrt.
22
23   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
24
25       mq_timedsend():
26           _POSIX_C_SOURCE >= 200112L
27

DESCRIPTION

29       mq_send() adds the message pointed to by msg_ptr to the message queue
30       referred to by the message queue descriptor mqdes.  The msg_len argu‐
31       ment specifies the length of the message pointed to by msg_ptr; this
32       length must be less than or equal to the queue's mq_msgsize attribute.
33       Zero-length messages are allowed.
34
35       The msg_prio argument is a nonnegative integer that specifies the pri‐
36       ority of this message.  Messages are placed on the queue in decreasing
37       order of priority, with newer messages of the same priority being
38       placed after older messages with the same priority.  See mq_overview(7)
39       for details on the range for the message priority.
40
41       If the message queue is already full (i.e., the number of messages on
42       the queue equals the queue's mq_maxmsg attribute), then, by default,
43       mq_send() blocks until sufficient space becomes available to allow the
44       message to be queued, or until the call is interrupted by a signal han‐
45       dler.  If the O_NONBLOCK flag is enabled for the message queue descrip‐
46       tion, then the call instead fails immediately with the error EAGAIN.
47
48       mq_timedsend() behaves just like mq_send(), except that if the queue is
49       full and the O_NONBLOCK flag is not enabled for the message queue de‐
50       scription, then abs_timeout points to a structure which specifies how
51       long the call will block.  This value is an absolute timeout in seconds
52       and nanoseconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC), spec‐
53       ified in the following structure:
54
55           struct timespec {
56               time_t tv_sec;        /* seconds */
57               long   tv_nsec;       /* nanoseconds */
58           };
59
60       If the message queue is full, and the timeout has already expired by
61       the time of the call, mq_timedsend() returns immediately.
62

RETURN VALUE

64       On success, mq_send() and mq_timedsend() return zero; on error, -1 is
65       returned, with errno set to indicate the error.
66

ERRORS

68       EAGAIN The queue was full, and the O_NONBLOCK flag was set for the mes‐
69              sage queue description referred to by mqdes.
70
71       EBADF  The descriptor specified in mqdes was invalid or not opened for
72              writing.
73
74       EINTR  The call was interrupted by a signal handler; see signal(7).
75
76       EINVAL The call would have blocked, and abs_timeout was invalid, either
77              because tv_sec was less than zero, or because tv_nsec was less
78              than zero or greater than 1000 million.
79
80       EMSGSIZE
81              msg_len was greater than the mq_msgsize attribute of the message
82              queue.
83
84       ETIMEDOUT
85              The call timed out before a message could be transferred.
86

ATTRIBUTES

88       For an explanation of the terms used in this section, see at‐
89       tributes(7).
90
91       ┌────────────────────────────────────────────┬───────────────┬─────────┐
92Interface                                   Attribute     Value   
93       ├────────────────────────────────────────────┼───────────────┼─────────┤
94mq_send(), mq_timedsend()                   │ Thread safety │ MT-Safe │
95       └────────────────────────────────────────────┴───────────────┴─────────┘
96

CONFORMING TO

98       POSIX.1-2001, POSIX.1-2008.
99

NOTES

101       On  Linux,  mq_timedsend() is a system call, and mq_send() is a library
102       function layered on top of that system call.
103

SEE ALSO

105       mq_close(3), mq_getattr(3),  mq_notify(3),  mq_open(3),  mq_receive(3),
106       mq_unlink(3), mq_overview(7), time(7)
107

COLOPHON

109       This  page  is  part of release 5.13 of the Linux man-pages project.  A
110       description of the project, information about reporting bugs,  and  the
111       latest     version     of     this    page,    can    be    found    at
112       https://www.kernel.org/doc/man-pages/.
113
114
115
116Linux                             2021-03-22                        MQ_SEND(3)
Impressum