MsgWritev(), MsgWritev_r()

Updated: October 26, 2022

Write a reply

Synopsis:

#include <sys/neutrino.h>

ssize_t MsgWritev( int rcvid,
                   const iov_t* iov,
                   size_t parts,
                   size_t offset );

ssize_t MsgWritev_r( int rcvid,
                     const iov_t* iov,
                     size_t parts,
                     size_t offset );

Arguments:

rcvid
The value returned by MsgReceive*() when you received the message.
iov
An array of buffers that contains the data you want to write. 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.

These functions don't let you write past the end of the sender's buffer; they return the number of bytes actually written.

parts
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.
offset
An offset into the sender's buffer that indicates where you want to start writing the data.

Library:

libc

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

Description:

The MsgWritev() and MsgWritev_r() kernel calls write data to the reply buffer of a thread identified by rcvid. The thread being written to must be in the REPLY-blocked state. Any thread in the receiving process is free to write to the reply message.

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

In the local case, the data transfer occurs immediately and your thread doesn't block (see “Blocking states,” below). The state of the sending thread doesn't change.

You'll use this function in one of these situations:

To complete a message exchange, you must call MsgReply*(). The reply doesn't need to contain any data. If it does contain data, then the data is always written at offset zero in the destination thread's reply message buffer. This is a convenient way of writing the header once all of the information has been gathered.

A single call to MsgReply*() is always more efficient than calls to MsgWritev() followed by a call to MsgReply*().

Note: As a client may have overlapping send and reply buffers, you must complete all MsgRead*() operations from a particular send (i.e. particular rcvid) before initiating any MsgWrite*() operations to that client.

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 MsgWritev() and MsgWritev_r() is the way they indicate errors:

MsgWrite()
If succesful, this function returns the number of bytes written. If an error occurs, it returns -1 and sets errno.
MsgWrite_r()
If successful, this function returns the number of bytes written. If an error occurs, it 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 the kernel tried to access the sender's return message buffer.
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, 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