QNX: Starting with the API to understand QNX-message delivery

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.