Get started with the API to understand QNX-message passing http://www.openqnx.com/chinese/viewtopic.php?f=5&t=2161
1. Channels and connections
Channel, Connect
Server
Channelid = Channelcreate (Flags);
Client
ConnectionID = Connectattach (Node, Pid, Chid, Index, Flag);
Node: Machine number; PID is the service process number; Chid is the channel number that was obtained after channelcreate.
The termination of the connection is Connectdetach (), and the end of the channel is Channeldestroy (). However, the general server is a long-term existence, not much need Channeldestroy () time.
2. Send, Receive and answer
Send, Receive, Reply
Server
Recieveid = Msgreceive (Channelid, Receivebuffer, Receivebuflength,&msginfo);
... Deal recvd Msg ....
Msgreply (Receiveid, Replybuf, Replylen);
Client
Msgsend (ConnectionID, SendBuf, Sendlen, Replybuf, Replylen);
.... This thread is then suspended by the OS ...
.... When the server msgreply (), the OS is unblocked and the client can check its own receivebuf to see how the response works ...
3. Data area and Iov
Although the client header with DATABUF is two non-contiguous memory, but passed to the server side of the Receivebuffer, is continuous.
Client: "Header" and "Databuf" are discontinuous two blocks of data.
Setiov (&iov[0], &header, sizeof (header));
Setiov (&iov[1], databuf, datalen);
Msgsendvs (ConnectionID, Iov, 2, REPLYBF, Replylen);
Server: After receiving, "header" and "databuf" are continuously present in Receivebuffer.
Receiveid = Msgreceive (Channelid, Receivebuffer, Receivebuflength, &msginfo);
Header = (struct header *) Receivebuffer;
DATABUF = (char *) ((char *) header + sizeof (*header));
When the specified receivebuflength is less than the number of bytes actually received, that is, msgreceive does not necessarily read all the data from the client, so you also need to see Msginfo and use Msgread (Receiveid,
Receivebuffer+receivebuflength,//Specify buffer start address for data storage
Receivebuflength,//offset to buffer read data
Msginfo->srcmsglen-msginfo->msglen//Data length not read
));
QNX: Starting with the API to understand QNX-message delivery