[Previous] [Contents] [Next]

MsgReadv(), MsgReadv_r()

Read data from a message

Synopsis:

#include <sys/neutrino.h>

int MsgReadv( int rcvid,
              const iov_t* riov,
              int rparts,
              int offset );

int MsgReadv_r( int rcvid,
                const iov_t* riov,
                int rparts,
                int offset );

Library:

libc

Description:

The MsgReadv() and MsgReadv_r() functions are identical except in the way they indicate errors. See the Returns section for details.

These kernel calls read data from a message sent by a thread identified by rcvid. The rcvid is returned from MsgReceive*() when you receive the message. The thread being read from must not have been replied to and will be in the REPLY-blocked state. Any thread in the receiving process is free to read the message.

The data is placed in the array of buffers pointed to by riov. The number of elements in the array is given by rparts.

The offset allows data to be read from the thread's send message starting at any point. The data transfer occurs immediately and the thread doesn't block. The state of the sending thread doesn't change.

An attempt to read past the end of the thread's message results in fewer bytes returned than requested.

This function is used in one of three situations:

  1. A message is sent consisting of a fixed header and a variable amount of data. The header contains the byte count of the data. If the data is large and has to be inserted into one or more buffers (like a filesystem cache), rather than read the data into one large buffer and then copy it into several other buffers, MsgReceive() only reads the header and a custom iov_t list is built to allow MsgReadv() to read data directly into the required buffers.
  2. A message is received which cannot be handled at the present time. At some point in the future an event will occur which will allow the message to be processed. Rather than saving the message until it can be processed (thus using memory resources), the message can be reread using MsgReadv() during which time the sending thread is still blocked.
  3. Messages are received which are larger than available buffer space. Perhaps the process is an agent between two processes and simply filters the data and passes it on. MsgReadv() can be used to read the message in small amounts and MsgWrite*() can be used to write the messages in small amounts.

When you are through using MsgReadv() you must use MsgReply*() to ready the REPLY-blocked process and complete the message exchange.

Blocking states

None. In the network case, lower priority threads may run.

Returns:

The only difference between the MsgReadv() and MsgReadv_r() functions is the way they indicate errors:

MsgReadv()
The number of bytes read. If an error occurs, -1 is returned and errno is set.
MsgReadv_r()
The number of bytes read. This function does NOT set errno. If an error occurs, the negative of a value from the Errors section is returned.

Errors:

EFAULT
A fault occurred in a server's address space when it tried to access the caller's message buffers.
ESRCH
The thread indicated by rcvid doesn't exist or has had its connection detached.
ESRVRFAULT
A fault occurred when the kernel tried to access the buffers provided.

Classification:

QNX 6

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

See also:

MsgRead(), MsgReceive(), MsgReceivev(), MsgReply(), MsgReplyv(), MsgWrite(), MsgWritev()


[Previous] [Contents] [Next]