A mailslot is a mechanism for one-way interprocess communication. As the name suggests, messages can be stored in a mailslot and the owner of a mailslot can retrieve any messages that are stored there. Mailslot messages can be sent locally to a single mailslot or over a network to either a specified computer or to every computer on a specified domain. A domain is a group of workstations and servers that share a single group name.
The process that creates a mailslot is a mailslot server. When the server creates a mailslot it receives a handle to the mailslot. This handle must be used when a process reads messages from the mailslot. Therefore, only the process that creates a mailslot (or a child of the process that has inherited the handle) can read from the mailslot. A mailslot exists until all server handles to it have been closed or all server processes have exited.
A process that writes a message to a mailslot is a mailslot client. Any process that knows the name of a mailslot can put a message there. Each message is appended to preexisting messages in the mailslot.
Mailslots can be used to broadcast messages within a domain. If several processes within a domain each create a mailslot using the same name, every message that is addressed to that mailslot and sent to the domain is received by each participating process. Because one process can control both a server and a client handle to a mailslot, this mechanism makes it easy to implement a simple message-passing facility within a domain.
Some developers choose to use named pipes instead of mailslots for interprocess communication. Named pipes offer a simple method for two processes to exchange messages, but mailslots are more convenient for persistent messaging systems and for broadcasting messages to a number of processes. For more information about named pipes, see Chapter 14, “Pipes.”