Read vs Receive

After reading the help and documentations, I’m not too clear the differences between read and receive? Are there anyone who can help me?

Do you mean MsgReceive() and MsgRead()? If so, It may easier to look at these calls in terms of their effects on the states of the sender and receiver.

The MsgReceive() call blocks waiting for some other program to call MsgSend() and send a message. If your program calls MsgReceive(), it changes to a blocked state (RECEIVE) waiting for another program to MsgSend() to it.

After you have called MsgReceive(), you can call MsgRead() if for some reason you didn’t read all the message the first time (with MsgReceive()) or if you want to read it again.

An example of why you would do this is if the server (the program calling MsgReceive()) doesn’t know which message it will get and the messages are of different sizes. The server would then only call MsgReceive() with a buffer sized to only contain the header. Once the header is received and the server knows the size it needs, it can call MsgRead() and read the rest of the message into the appropriate buffer.

In a lot of situations, you will never use MsgRead(). Basic QNX inter process communication can be handled the MsgSend(), MsgReceive() and MsgReply() calls. All the other related calls are just variations and special cases.

Of couse if you meant some other call instead of MsgRead and MsgReceive, just ignore this. :slight_smile: