MsgReplyv(), MsgReplyv_r()

Updated: April 19, 2023

Reply with a message

Synopsis:

#include <sys/neutrino.h>

int MsgReplyv( int rcvid,
               long status,
               const iov_t* riov,
               size_t rparts );

int MsgReplyv_r( int rcvid,
                 long status,
                 const iov_t* riov,
                 size_t rparts );

Arguments:

rcvid
The receive ID that MsgReceive*() returned when you received the message.
status
The status to use when unblocking the client's MsgSend*() call in the rcvid thread.
Note: The MsgSend*_r() functions return negative errno values to indicate failure, so you shouldn't pass a negative value for the status to MsgReply*(), because the MsgSend*_r() functions could interpret it as an error code. If you wish to indicate an error, call MsgError().
riov
An array of buffers that contains the message that you want to reply with. The sum of the IOV buffer lengths must not exceed SSIZE_MAX, or the function will behave unpredictably; for instance, it may fail with EOVERFLOW.
rparts
The number of elements in the array. This number must not exceed 524288, or the function will fail with EOVERFLOW. If the number exceeds SSIZE_MAX, the function will behave unpredictably; for instance, it may fail with EOVERFLOW.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The MsgReplyv() and MsgReplyv_r() kernel calls reply with a message to the thread identified by rcvid. The thread being replied to must be in the REPLY-blocked state. Any thread in the receiving process is free to reply to the message, however, it may be replied to only once for each receive.

These functions are identical except in the way they indicate errors. See the Returns section for details.

The MsgSend*() in the rcvid thread unblocks with a return value of status.

The data is taken from the array of message buffers pointed to by riov. The number of elements in this array is given by rparts. The size of the message is the sum of the sizes of each buffer.

The number of bytes transferred is the minimum of that specified by both the replier and the sender. The reply data isn't allowed to overflow the reply buffer area provided by the sender.

In the local case, the data transfer occurs immediately, and the replying task doesn't block (see “Blocking states,” below). There's no need to reply to received messages in any particular order, but you must eventually reply to each message to allow the sending thread(s) to continue execution.

It's quite common to reply with two-part messages consisting of a fixed header and a buffer of data. The MsgReplyv() function gathers the data from the buffer list into a logical contiguous message and transfers it to the sender's reply buffer(s). The sender doesn't need to specify the same number or size of buffers. The data is laid down filling each buffer as required. The filesystem, for example, builds a reply list pointing into its cache in order to reply with what appears to be one contiguous piece of data.

Blocking states

None for the local case. In the network case:

STATE_REPLY
The calling thread is waiting for a network operation to complete. The calling thread is marked as REPLY-blocked on itself (the same process ID as the thread making the call).

Returns:

The only difference between the MsgReplyv() and MsgReplyv_r() functions is the way they indicate errors:

MsgReplyv()
If successful, this function returns EOK. If an error occurs, it returns -1 and sets errno.
MsgReplyv_r()
If successful, this function returns EOK. If an error occurs, this function may return the negative of any value from the Errors section. This function does NOT set errno, even on success.

Errors:

EDEADLK
A deadlock occurred. You can avoid a deadlock by setting the _NTO_CHF_MSG_PAUSING flag when you create a channel; for more information, see ChannelCreate() and MsgPause().
EFAULT
A fault occurred in the sender's address space when a server tried to access the sender's return message buffers.
ENOREMOTE
The reply has to go across the network, and Qnet isn't running.
EOVERFLOW
The sum of the IOV lengths exceeds SSIZE_MAX, or the number of parts exceeds 524288.
ESRCH
The thread indicated by rcvid doesn't exist, or is no longer REPLY-blocked on the channel, or the connection was detached.
ESRVRFAULT
A fault occurred when the kernel tried to access the buffers provided.
ETIMEDOUT
A kernel timeout unblocked the call. See TimerTimeout().

Classification:

QNX Neutrino

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes