]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/mq_send.3
a9266a99a17ee4ca785b6a88f7e40785249b7b75
[thirdparty/man-pages.git] / man3 / mq_send.3
1 '\" t
2 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\"
4 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .TH MQ_SEND 3 2006-02-25 "Linux" "Linux Programmer's Manual"
24 .SH NAME
25 mq_send, mq_timedsend \- send a message to a message queue
26 .SH SYNOPSIS
27 .nf
28 .B #include <mqueue.h>
29 .sp
30 .BI "mqd_t mq_send(mqd_t " mqdes ", const char *" msg_ptr ,
31 .BI " size_t " msg_len ", unsigned " msg_prio );
32 .sp
33 .B #define _XOPEN_SOURCE 600
34 .B #include <time.h>
35 .B #include <mqueue.h>
36 .sp
37 .BI "mqd_t mq_timedsend(mqd_t " mqdes ", const char *" msg_ptr ,
38 .BI " size_t " msg_len ", unsigned " msg_prio ,
39 .BI " const struct timespec *" abs_timeout );
40 .fi
41 .sp
42 Link with \fI\-lrt\fP.
43 .SH DESCRIPTION
44 .BR mq_send ()
45 adds the message pointed to by
46 .IR msg_ptr
47 to the message queue referred to by the descriptor
48 .IR mqdes .
49 The
50 .I msg_len
51 argument specifies the length of the message pointed to by
52 .IR msg_ptr ;
53 this length must be less than or equal to the queue's
54 .I mq_msgsize
55 attribute.
56 Zero-length messages are allowed.
57
58 The
59 .I msg_prio
60 argument is a non-negative integer that specifies the priority
61 of this message.
62 Messages are placed on the queue in decreasing order of priority,
63 with newer messages of the same priority being placed after
64 older messages with the same priority.
65
66 If the message queue is already full
67 (i.e., the number of messages on the queue equals the queue's
68 .I mq_maxmsg
69 attribute), then, by default,
70 .BR mq_send ()
71 blocks until sufficient space becomes available to allow the message
72 to be queued, or until the call is interrupted by a signal handler.
73 If the
74 .B O_NONBLOCK
75 flag is enabled for the message queue description,
76 then the call instead fails immediately with the error
77 .BR EAGAIN .
78
79 .BR mq_timedsend ()
80 behaves just like
81 .BR mq_send (),
82 except that if the queue is full and the
83 .B O_NONBLOCK
84 flag is not enabled for the message queue description, then
85 .I abs_timeout
86 points to a structure which specifies a ceiling on the time for which
87 the call will block.
88 This ceiling is an absolute timeout in seconds and nanoseconds
89 since the Epoch (midnight on the morning of 1 January 1970),
90 specified in the following structure:
91 .sp
92 .RS
93 .nf
94 struct timespec {
95 time_t tv_sec; /* seconds */
96 long tv_nsec; /* nanoseconds */
97 };
98
99 .fi
100 .RE
101 If the message queue is full,
102 and the timeout has already expired by the time of the call,
103 .BR mq_timedsend ()
104 returns immediately.
105 .SH RETURN VALUE
106 On success,
107 .BR mq_send ()
108 and
109 .BR mq_timedsend ()
110 return zero; on error, \-1 is returned, with
111 .I errno
112 set to indicate the error.
113 .SH ERRORS
114 .TP
115 .B EAGAIN
116 The queue was empty, and the
117 .B O_NONBLOCK
118 flag was set for the message queue description referred to by
119 .IR mqdes .
120 .TP
121 .B EBADF
122 The descriptor specified in
123 .I mqdes
124 was invalid.
125 .TP
126 .B EINTR
127 The call was interrupted by a signal handler.
128 .TP
129 .B EINVAL
130 The call would have blocked, and
131 .I abs_timeout
132 was invalid, either because
133 .I tv_sec
134 was less than zero, or because
135 .I tv_nsec
136 was less than zero or greater than 1000 million.
137 .TP
138 .B EMSGSIZE
139 .IR msg_len
140 was greater than the
141 .I mq_msgsize
142 attribute of the message queue.
143 .TP
144 .B ETIMEDOUT
145 The call timed out before a message could be transferred.
146 .SH CONFORMING TO
147 POSIX.1-2001.
148 .SH "SEE ALSO"
149 .BR mq_close (3),
150 .BR mq_getattr (3),
151 .BR mq_notify (3),
152 .BR mq_open (3),
153 .BR mq_receive (3),
154 .BR mq_unlink (3),
155 .BR feature_test_macros (7),
156 .BR mq_overview (7)