msg_receive - receive messages on a server port
Synopsis
Description
#include <sys/msg.h>
int msg_receive(port_t port, struct msg *msg);
msg_receive() is used by a server to receive messages on a servers port. The received message may be either a regular data message from one of the servers current clients, or a system-generated notification of certain exceptional events. Messages with an m_type field below M_RESVD are guaranteed to be kernel-generated; they can not be spoofed.Each message may contain one or more segments of data in a scatter/gather format. The field m_nseg indicates how many such segments were received; the actual segments are described by the m_seg[] array of pointer/length structures.
The field m_sender indicates which client sent this message; in the case of an M_CONNECT message, it indicates the handle of the would-be connecter. This handle will be valid if the server msg_accept() the connection.
The fields m_arg and m_arg1 are specified by the sender. By convention, m_arg holds the number of bytes requested or sent in normal data messages.
In the case of normal data messages, the request is completed and a reply sent back by using msg_reply().
Special messages ( m_op less than M_RESVD ) are:
M_CONNECT
A client has attempted connection with msg_connect(). m_arg holds the requested mode(s), m_nseg is always set to 1, and the segment holds an array of struct perm elements, describing the abilities of the client. Because this is a kernel-generated message, the client may not spoof it, and the permissions so described may be trusted by the server. This message must be completed by either a msg_accept() call (to accept the client) or a msg_err() call to reject the connection.M_DISCONNECT
This message indicates that a client has terminated, either explicitly or due to an unhandled event. The m_sender field identifies the client, who is no longer connected to the server.M_DUP
This message is something of a misnomer. A POSIX dup() causes two file descriptors to refer to the same connection; in contrast, the M_DUP message causes the server to allocate a new distinct session, whose state (i.e., file position, etc.) starts as a copy of the original connections, but is distinct. It is caused by the clone() system call, as well as a part of the fork() operation.M_ABORT
When a pending operation is interrupted (i.e., a message has been sent via msg_send() but a response has not yet been received, and the requesting process receives an event), the kernel causes this message to appear at the server. It is expected that the server will clear any state, and use a msg_reply() to indicate that it has reset the per-client state to a point where the client may send a new request.M_ISR
This message is generated by the kernel for servers which have registered for hardware interrupts. The kernel clears the hardware interrupt, and then queues this message for the server. No reply is needed for this message, which will never contain any segments of data. The m_arg field holds a count of the number of interrupts which have been received since the message was queued, but before it was received.
MSG_RECEIVE (2) |