Question

This snapshot is from Windows System Programming (4th Edition).

I have few queries regarding mailslots,

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

enter image description here

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top