OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man3 / mq_send.3
1 '\" t
2 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
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.
13 .\"
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
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.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .TH MQ_SEND 3 2014-06-03 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 mq_send, mq_timedsend \- send a message to a message queue
29 .SH SYNOPSIS
30 .nf
31 .B #include <mqueue.h>
32 .sp
33 .BI "int mq_send(mqd_t " mqdes ", const char *" msg_ptr ,
34 .BI "              size_t " msg_len ", unsigned int " msg_prio );
35 .sp
36 .B #include <time.h>
37 .B #include <mqueue.h>
38 .sp
39 .BI "int mq_timedsend(mqd_t " mqdes ", const char *" msg_ptr ,
40 .BI "              size_t " msg_len ", unsigned int " msg_prio ,
41 .BI "              const struct timespec *" abs_timeout );
42 .fi
43 .sp
44 Link with \fI\-lrt\fP.
45 .sp
46 .ad l
47 .in -4n
48 Feature Test Macro Requirements for glibc (see
49 .BR feature_test_macros (7)):
50 .in
51 .sp
52 .BR mq_timedsend ():
53 .RS 4
54 _XOPEN_SOURCE\ >=\ 600 || _POSIX_C_SOURCE\ >=\ 200112L
55 .RE
56 .ad
57 .SH DESCRIPTION
58 .BR mq_send ()
59 adds the message pointed to by
60 .I msg_ptr
61 to the message queue referred to by the descriptor
62 .IR mqdes .
63 The
64 .I msg_len
65 argument specifies the length of the message pointed to by
66 .IR msg_ptr ;
67 this length must be less than or equal to the queue's
68 .I mq_msgsize
69 attribute.
70 Zero-length messages are allowed.
71
72 The
73 .I msg_prio
74 argument is a nonnegative integer that specifies the priority
75 of this message.
76 Messages are placed on the queue in decreasing order of priority,
77 with newer messages of the same priority being placed after
78 older messages with the same priority.
79
80 If the message queue is already full
81 (i.e., the number of messages on the queue equals the queue's
82 .I mq_maxmsg
83 attribute), then, by default,
84 .BR mq_send ()
85 blocks until sufficient space becomes available to allow the message
86 to be queued, or until the call is interrupted by a signal handler.
87 If the
88 .B O_NONBLOCK
89 flag is enabled for the message queue description,
90 then the call instead fails immediately with the error
91 .BR EAGAIN .
92
93 .BR mq_timedsend ()
94 behaves just like
95 .BR mq_send (),
96 except that if the queue is full and the
97 .B O_NONBLOCK
98 flag is not enabled for the message queue description, then
99 .I abs_timeout
100 points to a structure which specifies a ceiling on the time for which
101 the call will block.
102 This ceiling is an absolute timeout in seconds and nanoseconds
103 since the Epoch, 1970-01-01 00:00:00 +0000 (UTC), and it is
104 specified in the following structure:
105 .sp
106 .in +4n
107 .nf
108 struct timespec {
109     time_t tv_sec;        /* seconds */
110     long   tv_nsec;       /* nanoseconds */
111 };
112
113 .fi
114 .in
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 ()
122 and
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
128 .TP
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 .
134 .TP
135 .B EBADF
136 The descriptor specified in
137 .I mqdes
138 was invalid.
139 .TP
140 .B EINTR
141 The call was interrupted by a signal handler; see
142 .BR signal (7).
143 .TP
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.
152 .TP
153 .B EMSGSIZE
154 .I msg_len
155 was greater than the
156 .I mq_msgsize
157 attribute of the message queue.
158 .TP
159 .B ETIMEDOUT
160 The call timed out before a message could be transferred.
161 .SH ATTRIBUTES
162 .SS Multithreading (see pthreads(7))
163 The
164 .BR mq_send ()
165 and
166 .BR mq_timedsend ()
167 functions are thread-safe.
168 .SH CONFORMING TO
169 POSIX.1-2001.
170 .SH NOTES
171 On Linux,
172 .BR mq_timedsend ()
173 is a system call, and
174 .BR mq_send ()
175 is a library function layered on top of that system call.
176 .SH SEE ALSO
177 .BR mq_close (3),
178 .BR mq_getattr (3),
179 .BR mq_notify (3),
180 .BR mq_open (3),
181 .BR mq_receive (3),
182 .BR mq_unlink (3),
183 .BR mq_overview (7),
184 .BR time (7)
185 .SH COLOPHON
186 This page is part of release 3.79 of the Linux
187 .I man-pages
188 project.
189 A description of the project,
190 information about reporting bugs,
191 and the latest version of this page,
192 can be found at
193 \%http://www.kernel.org/doc/man\-pages/.