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