Read data from a message
int MsgRead( int rcvid,
int offset );
int MsgRead_r( int rcvid,
int offset );
- The value returned by MsgReceive*() when you received the
- A pointer to a buffer where the function can store the data.
- The number of bytes that you want to read.
These functions don't let you read past the end of the thread's message;
they return the number of bytes actually read.
- An offset into the thread's send message that indicates where you want
to start reading the data.
Use the -l c option to
to link against this library.
This library is usually included automatically.
The MsgRead() and MsgRead_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. 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.
The data transfer occurs
immediately and the thread doesn't block. The state of the sending
thread doesn't change.
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 call MsgRead() one or more times to
read data directly into the required buffer(s).
- 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 MsgRead()
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 MsgRead() to read the message in small pieces,
and use MsgWrite*() to write the messages in small pieces.
When you're finished using MsgRead(), you must use
MsgReply*() to ready the
REPLY-blocked process and complete the message exchange.
None. In the network case, lower priority threads may run.
The MsgRead() function has increased latency when
it's used to communicate across a network
— a message pass is involved from the server
to the network manager (at least). Depending on the size of
the data transfer, the server's lsm-qnet.so and the
client's lsm-qnet.so may need to communicate over
the link to read more data bytes from the client.
The only difference between the MsgRead() and MsgRead_r() functions
is the way they indicate errors:
- The number of bytes read. If an error occurs, -1 is returned and
- 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.
If you try to read past the end of the thread's message, the functions
return the number of bytes they were actually able to read.
- A fault occurred in a server's address space when it
tried to access the caller's message buffers.
- The thread indicated by rcvid doesn't exist or has had its
- A fault occurred when the kernel tried to access the buffers
chapter of Getting Started with QNX Neutrino