STREAMS-UX Programmer's Guide (February 2007)

Modules and Drivers
Entry Points
Chapter 4
80
}
} else {
/* M_IOCDATA not for us , so pass to next component */
putnext(q, bp);
}
break;
default:
/* Unknown message, so pass to next component */
putnext(q, bp);
break;
}
}
Put Procedure
Modules and drivers need to use the put or service procedure entry points for providing all the message
processing logic. The put procedure is used for immediate processing of the message and is required for all
queues in a stream, with a possible exception of driver read-queue.
The put procedure takes as input a queue pointer and a message pointer and has following interface:
int drv_put (queue_t *q, mblk_t *mp);
The return value from the put procedure is ignored.
A put procedure processes one message at a time. It cannot call sleep or any routines that block since it may
not have user context. The put procedure at a minimum should handle high-priority messages and flush
messages to avoid delayed processing of these messages. For all other messages it can either do deferred
processing by enqueuing the message using putq() utility or immediately process it.
When a message is passed to a driver it must do one of the following three things in its put procedure as an
action on the message; free the message, send the message back upstream or enqueue the message on its
queue for deferred processing by the driver service procedure.
When a module receives the message, it should pass the message to the next component on the stream or send
it back upstream as one of the action on the message for immediate processing of the message. It can also
enqueue the message if it wants to defer the processing of the message.
A driver must always free an unrecognized message with an exception of M_IOCTL messages which must be
replied with an M_IOCNAK message. A module should pass an unrecognized message to the next component in
the stream.
Service Procedure
The service procedure entry point is mainly used for deferred processing of the message apart from its use for
recovering from buffer allocation failures and implementing flow control. The use of service procedure for a
processing message allows minimum processing of the message on Interrupt Context Stack (ICS) and
avoids stack overflow caused due to multiple put procedure calls on the STREAMS stack.
The service procedure is optional for a queue but is required for modules and drivers that place their message
on their queue and/or implement flow control.
The service procedure takes as input a queue pointer and has following interface:
int drv_srv (queue_t *q);