1

此快照来自Windows 系统编程(第 4 版)

我对邮槽有几个疑问,

  1. 为什么邮槽称为单向?虽然可以有多个客户端/服务器
  2. 为什么邮槽的作者被称为客户端,而读者是服务器
  3. 如果没有读者,为什么打开会失败?是不是有可能我会写,没有服务器会读,或者它可能会在一段时间后读?

我努力在谷歌上搜索,但没有得到确切的答案。

在此处输入图像描述

4

1 回答 1

4

1.Why mailslot is called one directional? 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.

2.Why writer of mailslot is known as client while reader is server

Most IPC mechanisms have a client/server model. 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? 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.

于 2014-04-26T05:43:40.717 回答