1MQ_SEND(3) Linux Programmer's Manual MQ_SEND(3)
2
3
4
6 mq_send, mq_timedsend - send a message to a message queue
7
9 #include <mqueue.h>
10
11 mqd_t mq_send(mqd_t mqdes, const char *msg_ptr,
12 size_t msg_len, unsigned msg_prio);
13
14 #define _XOPEN_SOURCE 600
15 #include <time.h>
16 #include <mqueue.h>
17
18 mqd_t mq_timedsend(mqd_t mqdes, const char *msg_ptr,
19 size_t msg_len, unsigned msg_prio,
20 const struct timespec *abs_timeout);
21
23 mq_send() adds the message pointed to by msg_ptr to the message queue
24 referred to by the descriptor mqdes. The msg_len argument specifies
25 the length of the message pointed to by msg_ptr; this length must be
26 less than or equal to the queue's mq_msgsize attribute. Zero-length
27 messages are allowed.
28
29 The msg_prio argument is a non-negative integer that specifies the pri‐
30 ority of this message. Messages are placed on the queue in decreasing
31 order of priority, with newer messages of the same priority being
32 placed after older messages with the same priority.
33
34 If the message queue is already full (i.e., the number of messages on
35 the queue equals the queue's mq_maxmsg attribute), then, by default,
36 mq_send() blocks until sufficient space becomes available to allow the
37 message to be queued, or until the call is interrupted by a signal han‐
38 dler. If the O_NONBLOCK flag is enabled for the message queue descrip‐
39 tion, then the call instead fails immediately with the error EAGAIN.
40
41 mq_timedsend() behaves just like mq_send(), except that if the queue is
42 full and the O_NONBLOCK flag is not enabled for the message queue
43 description, then abs_timeout points to a structure which specifies a
44 ceiling on the time for which the call will block. This ceiling is an
45 absolute timeout in seconds and nanoseconds since the Epoch (midnight
46 on the morning of 1 January 1970), specified in the following struc‐
47 ture:
48
49 struct timespec {
50 time_t tv_sec; /* seconds */
51 long tv_nsec; /* nanoseconds */
52 };
53
54 If the message queue is full, and the timeout has already expired by
55 the time of the call, mq_timedsend() returns immediately.
56
58 On success, mq_send() and mq_timedsend() return zero; on error, -1 is
59 returned, with errno set to indicate the error.
60
62 EAGAIN The queue was empty, and the O_NONBLOCK flag was set for the
63 message queue description referred to by mqdes.
64
65 EBADF The descriptor specified in mqdes was invalid.
66
67 EMSGSIZE
68 msg_len was greater than the mq_msgsize attribute of the message
69 queue.
70
71 EINTR The call was interrupted by a signal handler.
72
73 EINVAL The call would have blocked, and abs_timeout was invalid, either
74 because tv_sec was less than zero, or because tv_nsec was less
75 than zero or greater than 1000 million.
76
77 ETIMEDOUT
78 The call timed out before a message could be transferred.
79
81 POSIX.1-2001.
82
84 mq_close(3), mq_getattr(3), mq_notify(3), mq_open(3), mq_receive(3),
85 mq_unlink(3), feature_test_macros(7), mq_overview(7)
86
87
88
89Linux 2.6.16 2006-02-25 MQ_SEND(3)