Write a reply
#include <sys/neutrino.h> ssize_t MsgWrite( int rcvid, const void* msg, size_t size, size_t offset ); ssize_t MsgWrite_r( int rcvid, const void* msg, size_t size, size_t offset );
These functions don't let you write past the end of the sender's buffer; they return the number of bytes actually written.
libc
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.
In the local case, the data transfer occurs immediately and your thread doesn't block (see Blocking states, below). The state of the sending thread doesn't change.
You use this function in one of these situations:
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*().
Blocking states
None for the local case. In the network case:
Native networking
The MsgWrite() function has increased latency when you use it to communicate across a network because the server is now writing data to its local lsm-qnet.so, which may need to communicate with the client's lsm-qnet.so to actually transfer the data. The server's MsgWrite() call effectively sends a message to the server's lsm-qnet.so to initiate this data transfer.
But since the server's lsm-qnet.so 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 lsm-qnet.so.
The message is buffered in the server side's lsm-qnet.so until the client replies, in order to reduce the number of network transactions.
The only difference between MsgWrite() and MsgWrite_r() is the way they indicate errors:
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |