STREAMS-UX Programmer's Guide (February 2007)

Messages
Message Processing and Flow Control
Chapter 3
51
Message Processing and Flow Control
Message Processing
Each queue in a stream is associated with a put procedure and an optional service procedure. The only
exception is the driver’s read-queue, which may not have a put procedure. The put procedure and the
service procedure are the two routines to process the messages.
The put procedure is used to process messages immediately. It processes the message as required when it
receives the message from the previous queue. Depending on the nature of the message and the availability of
the next queue in the stream, the put procedure can consume this message, pass it to the next component’s
queue for further processing, or place the messages on its message queue for deferred processing.
The service procedure is for deferred processing of the messages in the message queue. The service
procedure must use the getq () utility to remove the message from the message queue and process the
message accordingly. STREAMS guarantees that only one instance of the service procedure for a specific
queue may run at a time. Details of the rules for put and service procedures are described in Chapter 4,
“Modules and Drivers.”
The service procedure is usually scheduled to run when a message is first placed into the message queue.
The service procedure can also be scheduled by STREAMS as described in the See “Flow Control” on page 51
section in this chapter. In addition, STREAMS provides the qenable () utility to enable the module or driver to
schedule the service procedure directly.
STREAMS provides a set of service schedulers, defined by the NSTRSCHED tunable, to run the scheduled
service procedures. By default, the number of service schedulers is equal to the number of CPUs.
Flow Control
STREAMS provides a flow control mechanism that enables module and driver developers to manage the
maximum amount of data-flow in the stream. Implementing flow control is optional, but highly
recommended.
To implement the flow control, the module or driver must meet the following requirements:
•Provide service procedure
•Set high and low water marks
•Use the canput () family calls to check for flow control condition
Service Procedure
A queue must contain a service procedure to implement the flow control. The service procedure is pointed
to by the qi_srv pointer in the qinit structure. A NULL qi_srv pointer indicates that this queue does not
implement flow control.