mount_setattr.2: Rename 'path' to 'pathname'
[man-pages.git] / man3 / mq_send.3
blob54999f4407735432596aea71be18fc8c06c302ba
1 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH MQ_SEND 3 2021-03-22 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 mq_send, mq_timedsend \- send a message to a message queue
28 .SH SYNOPSIS
29 .nf
30 .B #include <mqueue.h>
31 .PP
32 .BI "int mq_send(mqd_t " mqdes ", const char *" msg_ptr ,
33 .BI "              size_t " msg_len ", unsigned int " msg_prio );
34 .PP
35 .B #include <time.h>
36 .B #include <mqueue.h>
37 .PP
38 .BI "int mq_timedsend(mqd_t " mqdes ", const char *" msg_ptr ,
39 .BI "              size_t " msg_len ", unsigned int " msg_prio ,
40 .BI "              const struct timespec *" abs_timeout );
41 .fi
42 .PP
43 Link with \fI\-lrt\fP.
44 .PP
45 .ad l
46 .RS -4
47 Feature Test Macro Requirements for glibc (see
48 .BR feature_test_macros (7)):
49 .RE
50 .PP
51 .BR mq_timedsend ():
52 .nf
53     _POSIX_C_SOURCE >= 200112L
54 .fi
55 .SH DESCRIPTION
56 .BR mq_send ()
57 adds the message pointed to by
58 .I msg_ptr
59 to the message queue referred to by the message queue descriptor
60 .IR mqdes .
61 The
62 .I msg_len
63 argument specifies the length of the message pointed to by
64 .IR msg_ptr ;
65 this length must be less than or equal to the queue's
66 .I mq_msgsize
67 attribute.
68 Zero-length messages are allowed.
69 .PP
70 The
71 .I msg_prio
72 argument is a nonnegative integer that specifies the priority
73 of this message.
74 Messages are placed on the queue in decreasing order of priority,
75 with newer messages of the same priority being placed after
76 older messages with the same priority.
77 See
78 .BR mq_overview (7)
79 for details on the range for the message priority.
80 .PP
81 If the message queue is already full
82 (i.e., the number of messages on the queue equals the queue's
83 .I mq_maxmsg
84 attribute), then, by default,
85 .BR mq_send ()
86 blocks until sufficient space becomes available to allow the message
87 to be queued, or until the call is interrupted by a signal handler.
88 If the
89 .B O_NONBLOCK
90 flag is enabled for the message queue description,
91 then the call instead fails immediately with the error
92 .BR EAGAIN .
93 .PP
94 .BR mq_timedsend ()
95 behaves just like
96 .BR mq_send (),
97 except that if the queue is full and the
98 .B O_NONBLOCK
99 flag is not enabled for the message queue description, then
100 .I abs_timeout
101 points to a structure which specifies how long the call will block.
102 This value is an absolute timeout in seconds and nanoseconds
103 since the Epoch, 1970-01-01 00:00:00 +0000 (UTC),
104 specified in the following structure:
106 .in +4n
108 struct timespec {
109     time_t tv_sec;        /* seconds */
110     long   tv_nsec;       /* nanoseconds */
115 If the message queue is full,
116 and the timeout has already expired by the time of the call,
117 .BR mq_timedsend ()
118 returns immediately.
119 .SH RETURN VALUE
120 On success,
121 .BR mq_send ()
123 .BR mq_timedsend ()
124 return zero; on error, \-1 is returned, with
125 .I errno
126 set to indicate the error.
127 .SH ERRORS
129 .B EAGAIN
130 The queue was full, and the
131 .B O_NONBLOCK
132 flag was set for the message queue description referred to by
133 .IR mqdes .
135 .B EBADF
136 The descriptor specified in
137 .I mqdes
138 was invalid or not opened for writing.
140 .B EINTR
141 The call was interrupted by a signal handler; see
142 .BR signal (7).
144 .B EINVAL
145 The call would have blocked, and
146 .I abs_timeout
147 was invalid, either because
148 .I tv_sec
149 was less than zero, or because
150 .I tv_nsec
151 was less than zero or greater than 1000 million.
153 .B EMSGSIZE
154 .I msg_len
155 was greater than the
156 .I mq_msgsize
157 attribute of the message queue.
159 .B ETIMEDOUT
160 The call timed out before a message could be transferred.
161 .SH ATTRIBUTES
162 For an explanation of the terms used in this section, see
163 .BR attributes (7).
164 .ad l
167 allbox;
168 lbx lb lb
169 l l l.
170 Interface       Attribute       Value
172 .BR mq_send (),
173 .BR mq_timedsend ()
174 T}      Thread safety   MT-Safe
178 .sp 1
179 .SH CONFORMING TO
180 POSIX.1-2001, POSIX.1-2008.
181 .SH NOTES
182 On Linux,
183 .BR mq_timedsend ()
184 is a system call, and
185 .BR mq_send ()
186 is a library function layered on top of that system call.
187 .SH SEE ALSO
188 .BR mq_close (3),
189 .BR mq_getattr (3),
190 .BR mq_notify (3),
191 .BR mq_open (3),
192 .BR mq_receive (3),
193 .BR mq_unlink (3),
194 .BR mq_overview (7),
195 .BR time (7)