MsgRead(), MsgRead_r()

Read data from a message


#include <sys/neutrino.h>

int MsgRead( int rcvid, 
             void* msg, 
             int bytes, 
             int offset );

int MsgRead_r( int rcvid, 
               void* msg, 
               int bytes, 
               int offset );


The value returned by MsgReceive*() when you received the message.
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 qcc 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. 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).

You'll use these functions in these situations:

When you're finished using MsgRead(), 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:

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).

Native networking

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 and the client's may need to communicate over the link to read more data bytes from the client.


The number of bytes read. If an error occurs:

If you try to read past the end of the thread's message, the functions return the message size. If you don't try to read past the message's end, the functions return the requested number of bytes.


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().
A fault occurred in a server's address space when the kernel tried to access the server's message buffers.
The thread indicated by rcvid doesn't exist, is no longer REPLY-blocked on the channel, or the connection was detached.
A fault occurred when the kernel tried to access the buffers provided.
A kernel timeout unblocked the call. See TimerTimeout().


QNX Neutrino

Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes