Modules
A module performs intermediate transformations on messages passing between the stream head and the driver.
Zero or more modules can exist in a stream (zero when the driver performs all the required character and device processing).
Each module is constructed from a pair of QUEUE structures (see the Au/Ad QUEUE pair and the Bu/Bd QUEUE pair in the Stream Detail diagram shown previously). A pair of such structures is required to implement the bidirectional and symmetrical attributes of a stream. One QUEUE (such as the Au or Bu QUEUE) performs functions on messages passing upstream through the module. The other QUEUE (the Ad or Bd QUEUE) performs another set of functions on downstream messages. (A QUEUE, which is part of a module, is different from a message queue, which is described in STREAMS Flow Control.)
Each of the two QUEUEs in a module generally have distinct functions; that is, unrelated processing procedures and data. The QUEUEs operate independently so that the Au QUEUE does not know if a message passes though the Ad QUEUE unless the Ad QUEUE is programmed to inform it. Messages and data can be shared only if the developer specifically programs the module functions to perform the sharing.
Each QUEUE can directly access the adjacent QUEUE in the direction of message flow (for example, Au to Bu or stream head to Bd). In addition, within a module, a QUEUE can readily locate its mate and access its messages (for example, for echoing) and data.
- Messages — These are dynamically attached to the QUEUE on a linked list, or message queue (see Ad and Bu in the Figure 1), as they pass through the module.
- Processing procedures — A put procedure must be incorporated in
each QUEUE to process messages. An optional service procedure for
sharing the message processing with the put procedure can also be
incorporated. According to their function, the procedures can send
messages upstream or downstream, and they can also modify the private
data in their module.
For more information about processing procedures, see Put and Service Procedures.
- Data — Developers can provide private data if required by the QUEUE to perform message processing (for example, state information and translation tables).
In general, each of the two QUEUEs in a module has a distinct set of all these elements. Additional module elements are described later. Although depicted as distinct from modules, a stream head and a stream end also contain a pair of QUEUEs.