STREAMS-UX Programmer's Guide (February 2007)
Overview
Messages and Queues
Chapter 1
14
Messages and Queues
This section introduces the queues and messages associated with STREAMS.
Queues
Each stream component is associated with a read queue and write queue pair. The read queue and write
queue are the data structures used to record the status of the stream component. These queues record the
messages to be processed later.
STREAMS allocates the read queue and write queue to the stream component. The allocation is performed
when the component becomes part of a stream. For example, a module’s read queue and write queue are
allocated when the module is pushed on the stream.
When a stream component is removed from the stream, STREAMS frees its corresponding read queue and
write queue. For example, a module’s read queue and write queue are freed when the module is popped out of
a stream.
Messages
Communication in STREAMS is based on messages. STREAMS modules and drivers communicate with each
other by passing pointers to these messages. Every message consists of the following data structures:
msgb
Describes the message type.
datab
Contains a pointer to the message data and other message details.
Messages in a stream are passed from one module or driver to another by invoking the
put
procedure of the
next module or driver. For details on the
put
procedure, see Chapter 3, “Messages,” and Chapter 4, “Modules
and Drivers,”
Messages that are not being processed are queued in a linked list of messages called the message queue. The
head and tail of the message queue are included in the queue itself.
Message Types
Each message is assigned a message type upon creation. The two message types are Normal (ordinary) and
High Priority. The message type is used by modules and drivers to determine the type of message processing
required. Although a module or driver usually assigns the message type to a message that it generates, a
module can also change the message type while processing the message.
Message Priority
The priority of a message determines the order in which it is placed or processed in a queue.
To control the processing priority of normal messages on a queue, STREAMS supports the concept of the
priority band. Priority bands are used to determine the order in which normal messages in a queue will be
stored and processed. A priority band value ranging from 1 to 255 can be assigned to these messages.