Building STREAMS
This section describes the procedure for building STREAMS.
A stream is created on the first open subroutine to a character special file corresponding to a STREAMS driver.
A stream is usually built in two steps. Step one creates a minimal stream consisting of just the stream head (see Stream Head) and device driver, and step two adds modules to produce an expanded stream (see Expanded Streams) as shown in the Stream Setup diagram (Figure 1). Modules which can be added to a stream are known as pushable modules (see Pushable Modules).
The first step in building a stream has three parts:
- Allocate and initialize head and driver structures.
- Link the modules in the head and end to each other to form a stream.
- Call the driver open routine.
If the driver performs all character and device processing required, no modules need to be added to a stream. Examples of STREAMS drivers include a raw tty driver (one that passes along input characters without change) and a driver with multiple streams open to it (corresponding to multiple minor devices opened to a character device driver).
When the driver receives characters from the device, it places them into messages. The messages are then transferred to the next stream component, the stream head, which extracts the contents of the message and copies them to user space. Similar processing occurs for downstream character output; the stream head copies data from user space into messages and sends them to the driver.