MQ_SEND(3POSIX)
π MQ_SEND(3POSIX) π β okay bestie, we're sending messages to a queue and we're gonna slay
So like, this whole page is part of the POSIX Programmer's Manual β¨ β iconic. But heads up: the Linux implementation of this interface may differ, so consult the corresponding Linux manual page for the deets on Linux behavior. Orrrr the interface may not even be implemented on Linux. It's giving "read the room, check your platform" π
β¨ NAME β¨
mq_send, mq_timedsend β send a message to a message queue (REALTIME)
π SYNOPSIS π
#include <mqueue.h>
int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
unsigned msg_prio);
#include <mqueue.h>
#include <time.h>
int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
unsigned msg_prio, const struct timespec *abstime);
π DESCRIPTION π
So mq_send() shall add the message that msg_ptr is pointing at into the message queue that mqdes specifies. The msg_len argument is the length of that message, in bytes, the one msg_ptr points to. And msg_len shall be less than or equal to the mq_msgsize attribute of the message queue β otherwise mq_send() shall fail. No cap. π«Ά
If the specified message queue is not full, mq_send() shall behave as if the message gets inserted into the message queue at the position that the msg_prio argument indicates. A message with a larger numeric value of msg_prio shall be inserted before messages with lower values of msg_prio. And a message shall be inserted after other messages already in the queue, if any, with equal msg_prio. The value of msg_prio shall be less than {MQ_PRIO_MAX}. π
If the specified message queue is full and O_NONBLOCK is not set in the message queue description associated with mqdes, mq_send() shall block until space becomes available to enqueue the message, or until mq_send() is interrupted by a signal π. If more than one thread is waiting to send when space becomes available in the message queue, and the Priority Scheduling option is supported, then the thread of the highest priority that has been waiting the longest shall be unblocked to send its message. Otherwise? It's unspecified which waiting thread is unblocked β literally a mystery, we don't know π. If the specified message queue is full and O_NONBLOCK is set in the message queue description associated with mqdes, the message shall not be queued and mq_send() shall return an error.
Now, mq_timedsend() shall add a message to the message queue specified by mqdes in the manner defined for the mq_send() function. BUT β plot twist β if the specified message queue is full and O_NONBLOCK is not set in the message queue description associated with mqdes, the wait for sufficient room in the queue shall be terminated when the specified timeout expires β°. And if O_NONBLOCK is set in the message queue description, this function shall be equivalent to mq_send(). Same vibe, different signature.
The timeout shall expire when the absolute time specified by abstime passes, as measured by the clock on which timeouts are based β that is, when the value of that clock equals or exceeds abstime β or if the absolute time specified by abstime has already been passed at the time of the call. Time's up, bestie β³
The timeout shall be based on the CLOCK_REALTIME clock. The resolution of the timeout shall be the resolution of the clock on which it is based. And the timespec argument is defined in the <time.h> header. π
Under no circumstance shall the operation fail with a timeout if there is sufficient room in the queue to add the message immediately. And the validity of the abstime parameter need not be checked when there is sufficient room in the queue. So like... if there's room, we go. Periodt. π₯
β RETURN VALUE β
Upon successful completion, the mq_send() and mq_timedsend() functions shall return a value of zero β the cleanest, most satisfying zero ever, we love to see it π. Otherwise, no message shall be enqueued, the functions shall return -1, and errno shall be set to indicate the error. Sad girl hours π
π ERRORS π
The mq_send() and mq_timedsend() functions shall fail if:
EAGAINβ TheO_NONBLOCKflag is set in the message queue description associated withmqdes, and the specified message queue is full.EBADFβ Themqdesargument is not a valid message queue descriptor open for writing.EINTRβ A signal interrupted the call tomq_send()ormq_timedsend().EINVALβ The value ofmsg_priowas outside the valid range.EINVALβ The process or thread would have blocked, and theabstimeparameter specified a nanoseconds field value less than zero or greater than or equal to1000 million.EMSGSIZEβ The specified message length,msg_len, exceeds the message size attribute of the message queue.ETIMEDOUTβ TheO_NONBLOCKflag was not set when the message queue was opened, but the timeout expired before the message could be added to the queue.
The following sections are informative. (iykyk π)
πΈ EXAMPLES πΈ
None. Bestie said "figure it out yourself" ππ
π¦ APPLICATION USAGE π¦
The value of the symbol {MQ_PRIO_MAX} limits the number of priority levels supported by the application. Message priorities range from 0 to {MQ_PRIO_MAX}-1. So that's your range, don't go outside it π
π RATIONALE π
None.
π§ FUTURE DIRECTIONS π§
None. Nothing to see here, we're not going anywhere β¨
π SEE ALSO π
mq_open()mq_receive()mq_setattr()time()
And from the Base Definitions volume of POSIX.1β2017: <mqueue.h>, <time.h> π
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
okay that's the whole page bestie, love that for us πβ¨ mwah, go enqueue something iconic π«Ά
This one's brought to you by IEEE/The Open Group, dated 2017, and the man page answers to the name MQ_SEND(3POSIX). That's the vibe check, complete. Byeee ππ
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms