Now, the third API that we will going to discuss is is the API using which a process can actually enqueue
a message in the message queue.
So ascending process can place a message in the message queue using the API, mq underscore send.
So this is the API.
The first argument to this API is a file descriptor to the message queue.
The second argument is the pointer to the message which you want to send.
And the third argument is actually the length of the message in bytes.
And the fourth argument is actually a certain priority, which you can always attach to the message
that you are trying to send.
The return value of this API is actually zero on success.
That is, if the message queue send API is successfully able to send a message to the receiving process,
then this API returns zero on success.
And if for some reason this API fails, then it returns failure.
All right, so message you send is an API used for sending a message to the queue referred to by the
file descriptor message queue.
So this is the message queue file descriptor and of course the message pointer is a pointer to the message
buffer which you want to send.
And message length is the size of the message which you are trying to send and of course the size of
this message which you are trying to send should be less than or equal to the size of the message which
you set in the attributes of this message queue.
Now the third argument that is message priority.
You can always attach some non-negative priority to the message that you are trying to send using message
queue.
So message priority is actually a non-negative number specifying the priority of the message.
Messages are placed in the queue in the decreasing order of message priority and with the older messages
for a priority coming before the newer messages.
So suppose you have a message queue and at any point of time suppose you have a message M1, M2, M3
And let us say the priority of this message is 211.
And now suppose the sending process enqueue the message in the message queue with the priority say four.
So this message will be added to the message queue right in the front because it has the priority four.
So it is this message that will be delivered to the receiving process before the older messages which
were already there in the message queue.
Because the priority of the message that is placed in the message queue takes a precedence.
But anyways, it is some advanced feature.
Probably we will not be going to use the priority of the message queue in our assignments.
Now, the next point is that if the message queue is full and if the process is trying to place an additional
message to the message queue using message queue, send API, then by default this API will get blocked
because there is no room for an additional message to the message queue.
Right.
And it will stay blocked till there is a space on the message queue.
Right.
So this is the default behavior of the message queue.
However, during the creation of a message queue, if the flag specified is non-block flag, that is,
if this flag was specified in the message queue open system call.
It would mean that in the scenario when the message queue was full and message queue send API was invoked
on the message queue to place an additional message in the message queue, then this function call will
immediately return.
It will not block right.
So message queue send function will return immediately if the message queue is full and the global variable
that is error number will be set to E again.
So this is the purpose of this flag.
That is whether you want the message queue send function to get block or not in a scenario when the
message queue was full.
So this API that is message queue send is simply is very simple and straightforward API.
So the next we will going to discuss the API to a message from a message queue.