Wait for a message or pulse on a channel
#include <sys/neutrino.h> int MsgReceivev( int chid, const iov_t * riov, int rparts, struct _msg_info * info ); int MsgReceivev_r( int chid, const iov_t * riov, int rparts, struct _msg_info * info );
- The ID of a channel that you established by calling ChannelCreate().
- An array of buffers where the function can store the received data.
- The number of elements in the array.
- NULL, or a pointer to a _msg_info structure where the function can store additional information about the message.
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The MsgReceivev() and MsgReceivev_r() kernel calls wait for a message or pulse to arrive on the channel identified by chid and place the received data in the array of buffers pointed to by riov.
These functions are identical, except in the way they indicate errors; see the Returns section for details.
The number of bytes transferred is the minimum of that specified by both the sender and the receiver. The received data isn't allowed to overflow the receive buffer area provided.
|The first buffer of the IOV (input/output vector) must be big enough to contain a pulse. If it isn't, the functions indicate an error of EFAULT.|
If a message is waiting on the channel when you call MsgReceivev(), the calling thread won't block, and the message is immediately copied. If a message isn't waiting, the calling thread enters the RECEIVE-blocked state until a message arrives.
If multiple messages are sent to a channel without a thread waiting to receive them, the messages are queued in priority order.
|The thread's effective priority might change when it receives a message. For more information, see "Priority inheritance and messages" in the QNX Neutrino Microkernel chapter of the System Architecture guide.|
If you pass a non-NULL pointer for info, the functions store additional information about the message and the thread that sent it in the _msg_info structure that info points to. You can get this information later by calling MsgInfo().
On success, MsgReceivev() and MsgReceivev_r() return:
- A message was received; the value returned is a rcvid (receive identifier). You'll use the rcvid with other Msg*() kernel calls to interact with and reply to the sending thread. MsgReceivev() changes the state of the sending thread to REPLY-blocked when the message is received. When you use MsgReply*() to reply to the received message, the sending thread is made ready again. The rcvid encodes the sending thread's ID and a local connection ID.
- A pulse was received;
the IOV's first buffer contains a pulse message of type
When a pulse
is received, the kernel space allocated to hold it is immediately
The _msg_info structure isn't updated.
Don't reply to a pulse.
|STATE_RECEIVE||There's no message waiting.|
The only difference between MsgReceivev() and MsgReceivev_r() is the way they indicate errors. On success, both functions return a positive rcvid if they received a message, or 0 if they received a pulse.
If an error occurs:
- MsgReceivev() returns -1 and sets errno.
- MsgReceivev_r() returns the negative of a value from the Errors section. This function doesn't set errno.
- A fault occurred when the kernel tried to access the buffers provided. Because the OS accesses the sender's buffers only when MsgReceivev() is called, a fault could occur in the sender if the sender's buffers are invalid. If a fault occurs when accessing the sender buffers (only) they'll receive an EFAULT and MsgReceivev() won't unblock.
- The call was interrupted by a signal.
- The channel indicated by chid doesn't exist.
- A kernel timeout unblocked the call. See TimerTimeout().