STREAMS-UX Programmer's Guide (February 2007)

Messages
Message Processing and Flow Control
Chapter 3
53
Figure 3-3 Flow Control
When queue A uses canput () to check for available space, canput () searches through the stream. canput ()
starts searching from queue B, until it finds queue C that contains a service procedure. Then, canput ()
checks if QFULL is set on queue C. If QFULL is not set, canput () returns 1. Else, canput () marks QWANTW on
queue C, and returns 0.
Back-Enabling Mechanism
STREAMS provides a back-enabling mechanism to schedule the service procedure to processing the
messages in the message queue. This mechanism works as follows:
When the message queue reaches the high water mark, STREAMS marks the message queue as QFULL. Once
canput () detects the QFULL condition, canput () sets the QWANTW flag.
When the accumulated data drops from the high water mark to the low watermark, STREAMS clears the
QFULL flag, and checks if QWANTW is set. If QWANTW is set, STREAMS schedules the service procedure of the
nearest preceding queue to process the messages.
For example, in Figure 3-3, “Flow Control,” queue C is in the QFULL state. A canput () from queue A sets
QWANTW on queue C, and returns 0. Upon return from canput (), queue A may place the message onto the
message queue for processing when queue C becomes available at a later time.
When queue C’s state changes from QFULL to non QFULL, STREAMS checks if QWANTW is set on queue C by any
previous canput (). If QWANTW is set, STREAMS schedules the service procedure of queue A to process the
messages blocked due to the queue full condition encountered by previous canput ().
The details of how STREAMS implements the back-enabling mechanism is transparent to the stream module
and drivers. As long as the module or driver meets the three requirements listed in the “Flow Control
section, STREAMS ensures the module or driver’s service procedure is scheduled when the QFULL state is
unset.
queue A
with service
procedure
queue B
no service
procedure
queue C
with service
procedure
QFULL
back enable queue As
service procedure
when QFULL on queue
C in not set
canput()