QNX Interprocess Communication
Definition
Definition | Description | 描述 |
---|---|---|
node | The node descriptor of the node (e.g., ND_LOCAL_NODE for the local node) on which the process that owns the channel is running | 拥有channel的进程正在运行的节点的节点描述符(例如,本地节点的 ND_LOCAL_NODE) |
coid | The ID of the connection to the channel to send the message on, which you’ve established by calling ConnectAttach() | 连接到channel的connection的ID |
pid | The process ID of the owner of the channel. | 拥有channel的进程的ID |
chid | The channel ID, returned by ChannelCreate(), of the channel to connect to the process. | 要连接到进程的channel的channel ID, 由ChannelCreate()返回 |
rcvid | The receive ID that MsgReceive*() returned when you received the message. | MsgReceive*() 返回的接收 ID |
Client->node->pid->chid
Message-passing API
Function | Description | 描述 |
---|---|---|
MsgSend() | Send a message and block until reply. | 发送一个消息,在reply之前一直block |
MsgReceive() | Wait for a message. | 等待一个消息 |
MsgReceivePulse() | Wait for a tiny, nonblocking message (pulse). | 等待一个微小的、非阻塞的消息(脉冲) |
MsgReply() | Reply to a message. | 应答一个消息 |
MsgError() | Reply only with an error status. No message bytes are transferred. | 只回复错误状态,不传输消息字节 |
MsgRead() | Read additional data from a received message. | 从收到的消息中读取附加数据 |
MsgWrite() | Write additional data to a reply message. | 将附加数据写入应答消息 |
MsgInfo() | Obtain info on a received message. | 获取收到的消息的信息 |
MsgSendPulse() | Send a tiny, nonblocking message (pulse). | 发送一个微小的、非阻塞的消息(脉冲) |
MsgDeliverEvent() | Deliver an event to a client. | 将一个事件传递给一个客户端 |
MsgKeyData() | Key a message to allow security checks. | 键入消息以允许安全检查 |
Channels and Connections
在 QNX Neutrino RTOS 中,消息传递是针对channel和connection的,而不是直接从线程到线程。
Server: 服务端使用channel来发送 MsgReceive() 消息。
Client: 客户端线程创建connection以“连接”到服务端提供的channel。
channel和connection在进程中由一个小的整数标识符命名。 客户端连接直接映射到文件描述符(FD)。
Send, Receive and Reply
客户端
ConnectionId = ConnectAttach(Node, Pid, Chid, Index, Flag);
MsgSend(ConnectionId, SendBuf, SendLen, ReplyBuf, ReplyLen);
(... 由OS将这个线程挂起 ...)
(... 当服务器MsgReply()后,OS解除线程的阻塞状态, 客户端可以检查自己的ReceiveBuf 看看应答结果 ...)
服务端
ChannelId = ChannelCreate(Flags);
ReceiveId = MsgReceive(ChannelId, ReceiveBuffer, ReceiveBufLength, &MsgInfo);
header = (struct header *)ReceiveBUffer;
databuf = (char *)((char *)header + sizeof(*header));
(... 检查Buffer里的消息进行处理 ...)
MsgReply(ReceiveId, ReplyStatus, ReplyBuf, ReplyLen);
Note: 在QNX中可以使用pidin查看线程、进程状态。