Read data from a message
Synopsis:
#include <sys/neutrino.h>
ssize_t MsgReadv( int rcvid,
const iov_t* riov,
size_t rparts,
size_t offset );
ssize_t MsgReadv_r( int rcvid,
const iov_t* riov,
size_t rparts,
size_t offset );
Arguments:
- rcvid
- The value returned by MsgReceive*() when you received the message.
- riov
- An array of buffers where the functions can store the data.
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 read past the end of the thread's message;
they return the number of bytes actually read.
- rparts
- The number of elements in the riov 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 thread's send message that indicates where you want
to start reading the data.
Library:
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
Description:
The MsgReadv() and MsgReadv_r()
kernel calls read data from a
message sent by a thread identified by rcvid.
The thread being read from must not have been
replied to and will be in the REPLY-blocked state.
The state of the sending thread doesn't change.
Any thread in the receiving process is free to read the message.
These functions are identical
except in the way they indicate errors. See the Returns section for details.
If the sending and calling threads are on the same node,
the data transfer occurs immediately and the calling thread doesn't block (see Blocking states, below).
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.
You'll use these functions in these situations:
- 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() reads
only the header, and you can build a custom iov_t list to
let MsgReadv() read data directly into the required buffers.
- A message is received but can't be handled at the present time. At
some point in the future, an event will occur that will allow the
message to be processed. Rather than saving the message until it can be
processed (thus using memory resources), you can use MsgReadv()
to reread the message, during which time the sending
thread is still blocked.
- Messages that are larger than available buffer space are received. Perhaps
the process is an agent between two processes and simply filters
the data and passes it on.
You can use MsgReadv() to read the message in small pieces,
and use MsgWrite*() to write the messages in small pieces.
When you're finished using MsgReadv(), you must use
MsgReply*() to ready the
REPLY-blocked process and complete the message exchange.
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:
If successful, MsgReadv() and MsgReadv_r() return the number of bytes read.
This may differ from the total number of requested bytes, which is the sum of the lengths of the
iov_t entries of the riov array.
If this sum is larger than the thread's message (and hence, the caller requested to read past the
end of the message), the functions return the message size.
If this sum is not larger than the message, the functions return the requested number of bytes.
The only difference between these functions is the way they indicate errors:
- MsgReadv()
- If an error occurs, this function returns -1 and sets
errno.
- MsgReadv_r()
- 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 a server's address space when the kernel tried to access the server's message buffers.
- 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 |