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).

Figure 1. Stream Setup
This diagram shows minimal stream setup on the left. The stream head is transmitting and receiving communication from the queue pair which sits on top of the raw tty device driver. The expanded stream on the right has a CANONPROC module between the queue pair and stream head. There is two-way communication between CANONPROC and the stream head and the queue pair.

The first step in building a stream has three parts:

  1. Allocate and initialize head and driver structures.
  2. Link the modules in the head and end to each other to form a stream.
  3. 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.