简体   繁体   English

在理解邮筒方面的困惑

[英]Confusion in understanding mailslot

This snapshot is from Windows System Programming (4th Edition) . 该快照来自Windows System Programming(第4版)

I have few queries regarding mailslots, 我对邮筒的查询很少,

  1. Why mailslot is called one directional? 为什么mailslot被称为单向? While there can be multiple client/servers 虽然可以有多个客户端/服务器
  2. Why writer of mailslot is known as client while reader is server 为什么邮筒的作者被称为客户端,而读者是服务器
  3. Why open will fail if there are no readers? 如果没有读者,为什么开放会失败? Isn't it possible I will write, and no server will read or it may read after some time? 是不是我会写,没有服务器会读,或者一段时间后它会读?

I tried hard to search on Google, but didn't get exact answers. 我尝试在Google上进行搜索,但未获得确切答案。

在此处输入图片说明

1.Why mailslot is called one directional? 1.为什么邮槽被称为单向? While there can be multiple client/servers 虽然可以有多个客户端/服务器

It really is one-directional. 这确实是单向的。 The process who creates a mailslot can only read from it, not to write to it. 创建邮筒的进程只能从中读取,而不能写入。 The process that opens the mailslot can only write to it, not read from it. 打开邮槽的过程只能对其进行写入,而不能对其进行读取。 A mailslot is not like a named pipe or a socket, where data can flow in both directions over a single connection. 邮槽与命名管道或套接字不同,在那里,数据可以通过单个连接在两个方向上流动。 If the process that creates the mailslot wants to send a reply, it has to write to a different mailslot or other IPC mechanism. 如果创建邮槽的进程要发送答复,则必须写入其他邮槽或其他IPC机制。

2.Why writer of mailslot is known as client while reader is server 2.为什么邮筒的作者被称为客户端而读者是服务器

Most IPC mechanisms have a client/server model. 大多数IPC机制都有客户端/服务器模型。 A "server" creates the resource that "clients" then access. “服务器”创建“客户端”然后访问的资源。 A mailslot fits that description, since a reader has to create the mailslot before writers can then write to it. 邮槽适合该描述,因为读者必须先创建邮槽,然后作者才能对其进行写入。

3.Why open will fail if there are no readers? 3.如果没有读者,为什么打开会失败? Isn't it possible I will write, and no server will read or it may read after some time? 是不是我会写,没有服务器会读,或者一段时间后它会读?

If there are no readers, the mailslot does not exist. 如果没有读者,邮筒将不存在。 A reader has to create the mailslot first, then writers can write to it. 读者必须先创建邮槽,然后作者才能对其进行写入。 When all readers have closed their handle to the mailslot (or are otherwise terminated), the mailslot no longer exists and cannot be written to anymore. 当所有阅读器都关闭了对邮槽的句柄(或被终止)时,邮槽不再存在,无法再写入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM