QNX Developer Support
|This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.|
Write a reply
#include <sys/neutrino.h> int MsgWrite( int rcvid, const void* msg, int size, int offset ); int MsgWrite_r( int rcvid, const void* msg, int size, int offset );
- The value returned by MsgReceive*() when you received the message.
- A pointer to a buffer that contains the data you want to write.
- The number of bytes that you want to write. These functions don't let you write past the end of the sender's buffer; they return the number of bytes actually written.
- An offset into the sender's buffer that indicates where you want to start writing the data.
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The MsgWrite() and MsgWrite_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.
You use this function in one of these situations:
- The data arrives over time and is quite large. Rather than buffer all the data, you can use MsgWrite() to write it into the destination thread's reply message buffer, as it arrives.
- Messages are received that are larger than available buffer space. Perhaps the process is an agent between two processes and simply filters the data and passes it on. You can use MsgRead*() to read messages in small pieces, and use MsgWrite() to write messages in small pieces.
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 MsgWrite() followed by a call to MsgReply*().
None. In the network case, lower priority threads may run.
The MsgWrite() function has increased latency when you use it to communicate across a network -- the server is now writing data to its local npm-qnet, which may need to communicate with the client's npm-qnet to actually transfer the data. The server's MsgWrite() call effectively sends a message to the server's npm-qnet to initiate this data transfer.
But since the server's npm-qnet has no way to determine the size of the client's receive data area, the number of bytes reported as having been transferred by the server during its MsgWrite() call might not be accurate -- the reported number will instead reflect the number of bytes transferred by the server to its npm-qnet.
The message is buffered in the server side's npm-qnet until the client replies, in order to reduce the number of network transactions.
If you want to determine the size of the sender's reply buffer, set the _NTO_CHF_REPLY_LEN when you call ChannelCreate().
The only difference between the MsgWrite() and MsgWrite_r() functions is the way they indicate errors:
- The number of bytes written. If an error occurs, -1 is returned and errno is set.
- The number of bytes written. This function does NOT set errno. If an error occurs, the negative of a value from the Errors section is returned.
- A fault occurred in the sender's address space when a server tried to access the sender's return message buffer.
- The thread indicated by rcvid doesn't exist or its connection was detached.
- A fault occurred when the kernel tried to access the buffers provided.