Wait for a message or pulse on a channel
#include <sys/neutrino.h>
int MsgReceive( int chid,
void * msg,
int bytes,
struct _msg_info * info );
int MsgReceive_r( int chid,
void * msg,
int bytes,
struct _msg_info * info );
BlackBerry 10.0.0
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The MsgReceive() and MsgReceive_r() kernel calls wait for a message or pulse to arrive on the channel identified by chid, and store the received data in the buffer pointed to by msg.
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.
If a message is waiting on the channel when you call MsgReceive(), the calling thread doesn'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.
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 sucess, MsgReceive() and MsgReceive_r() return:
Blocking states
| State | Meaning |
|---|---|
| STATE_RECEIVE | There's no message waiting |
The only difference between MsgReceive() and MsgReceive_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:
This error also occurs if the kernel tries to deliver a pulse to the server, but the size of the receive buffer is less than the size of a struct _pulse. The pulse is lost in this case.
| Safety: | |
|---|---|
| Cancellation point | No |
| Interrupt handler | No |
| Signal handler | Yes |
| Thread | Yes |
The maximum size for a one-part message-pass is 231 − 1 (SSIZE_MAX).