Sending and Receiving Messages
This section describes the STREAMS-related system call that sends and receive messages.
The putmsg system call is a STREAMS-related system call that sends messages. It is similar to the write subroutine. The putmsg system call provides a data buffer that is converted into an M_DATA message. The system call can also provide a separate control buffer to be placed into an M_PROTO or M_PCPROTO block. The write subroutine provides byte-stream data to be converted into M_DATA messages.
The getmsg system call is a STREAM-related system call that accepts messages. It is similar to the read subroutine. One difference between the two calls is that the read subroutine accepts only data (messages sent upstream to the stream head as message type M_DATA), such as the characters entered from the terminal. The getmsg system call can simultaneously accept both data and control information (that is, a message sent upstream as type M_PROTO or M_PCPROTO). The getmsg system call also differs from the read subroutine in that it preserves message boundaries so that the same boundaries exist above and below the stream head (that is, between a user process and a stream). The read subroutine generally ignores message boundaries, processing data as a byte stream.
Certain streamio operations, such as the I_STR operation, also cause messages to be sent or received on the stream. The I_STR operation provides the general ioctl capability of the character input/output subsystem. A user process above the stream head can issue the putmsg system call, the getmsg system call, the I_STR operation, and certain other STREAMS-related functions. Other streamio operations perform functions that include changing the state of the stream head, pushing and popping modules, or returning special information.
In addition to message types that explicitly transfer data to a process, some messages sent upstream result in information transfer. When these messages reach the stream head, they are transformed into various forms and sent to the user process. The forms include signals, error codes, and call return values.