Platform SDK: Interprocess Communications |
A mailslot is a pseudofile; it resides in memory, and you use standard Win32 file functions to access it. The data in a mailslot message can be in any form, but it should be less than 64K. Unlike disk files, however, mailslots are temporary. When all handles to a mailslot are closed, the mailslot and all the data it contains are deleted.
A mailslot server is a process that creates and owns a mailslot. When the server creates a mailslot, it receives a mailslot handle. This handle must be used when a process reads messages from the mailslot. Only the process that creates a mailslot or has obtained the handle by some other mechanism (such as inheritance) can read from the mailslot. All mailslots are local to the process that creates them; a process cannot create a remote mailslot.
A mailslot client is a process that writes a message to a mailslot. Any process that has the name of a mailslot can put a message there. New messages follow any existing messages in the mailslot.
Mailslots can broadcast messages within a domain. If several processes in 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 the participating processes. Because one process can control both a server mailslot handle and the client handle retrieved when the mailslot is opened for a write operation, applications can easily implement a simple message-passing facility within a domain.
Messages smaller than 425 bytes are sent using datagrams. Messages larger than 426 bytes are sent using a connection-oriented transfer over an SMB session. Connection-oriented transfers are limited to one-to-one communication from one client to one server. Therefore, you lose the ability to broadcast a message from one client to many servers. Note that Windows NT does not support messages that are 425 or 426 bytes.