DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
SVR5 and SCO OpenServer

srv(D2str)


srv -- service queued messages

Syntax

   #include <sys/types.h>
   #include <sys/stream.h>
   #include <sys/stropts.h>
   #include <sys/ddi.h>
   

int prefixrsrv(queue_t *q); /* read side */

int prefixwsrv(queue_t *q); /* write side */

Description

The service routine, srv, routine may be included in a STREAMS module or driver for a number of reasons. It provides greater control over the flow of messages in a stream by allowing the module or driver to reorder messages, defer the processing of some messages, or fragment and reassemble messages. The service routine also provides a way to recover from resource allocation failures.

Arguments


q
Pointer to the queue.

Return values

Ignored

Usage

This entry point is optional, and is valid for STREAMS drivers and modules only.

A message is first passed to a module's or driver's put(D2str) routine, which may or may not process it. The put routine can place the message on the queue for processing by the service routine.

Once a message has been enqueued, the STREAMS scheduler calls the service routine at some later time. Drivers and modules should not depend on the order in which service procedures are run. This is an implementation-dependent characteristic. In particular, applications should not rely on service procedures running before returning to user-level processing.

Every STREAMS queue(D4str) has limit values it uses to implement flow control. High and low water marks are checked to stop and restart the flow of message processing. Flow control limits apply only between two adjacent queues with service routines. Flow control occurs by service routines following certain rules before passing messages along. By convention, high priority messages are not affected by flow control.

STREAMS messages can be defined to have up to 256 different priorities to support some networking protocol requirements for multiple bands of data flow. At a minimum, a stream must distinguish between normal (priority band zero) messages and high priority messages (such as M_IOCACK). High priority messages are always placed at the head of the queue, after any other high priority messages already enqueued. Next are messages from all included priority bands, which are enqueued in decreasing order of priority. Each priority band has its own flow control limits. By convention, if a band is flow-controlled, all lower priority bands are also stopped.

Once a service routine is called by the STREAMS scheduler, it must provide for processing all messages on its queue, restarting itself if necessary. Message processing must continue until either the queue is empty, the stream is flow-controlled, or an allocation error occurs. Typically, the service routine will switch on the message type, which is contained in mp->b_datap->db_type, taking different actions depending on the message type.

For singlethreaded modules and drivers, the framework for the canonical service procedure algorithm is as follows:

   	queue_t *q;
   	mblk_t *mp;
   

while ((mp = getq(q)) != NULL) { if (mp->b_datap->db_type > QPCTL || canput(q->q_next)) { /* process the message */ putnext(q, mp); } else { putbq(q, mp); return; } }

If the singlethreaded module or driver cares about priority bands, the algorithm becomes:
   	queue_t *q;
   	mblk_t *mp;
   

while ((mp = getq(q)) != NULL) { if (mp->b_datap->db_type > QPCTL || bcanput(q->q_next, mp->b_band)) { /* process the message */ putnext(q, mp); } else { putbq(q, mp); return; } }

For multithreaded modules and drivers, the framework for the canonical service procedure algorithm is as follows:
   	queue_t *q;
   	mblk_t *mp;
   

while ((mp = getq(q)) != NULL) { if (pcmsg(mp->b_datap->db_type) || canputnext(q) { /* process the message */ putnext(q, mp); } else { putbq(q, mp); return; } }

If the multithreaded module or driver cares about priority bands, the algorithm becomes:

   	queue_t *q;
   	mblk_t *mp;
   

while ((mp = getq(q)) != NULL) { if (pcmsg(mp->b_datap->db_type) || bcanputnext(q, mp->b_band)) { /* process the message */ putnext(q, mp); } else { putbq(q, mp); return; } }

Each STREAMS module and driver can have a read and write service routine. If a service routine is not needed (because the put routine processes all messages), a NULL pointer should be placed in the module's qinit(D4str) structure.

If the service routine finishes running because of any reason other than flow control or an empty queue, then it must explicitly arrange for its rescheduling. For example, if an allocation error occurs during the processing of a message, the service routine can put the message back on the queue with the putbq(D3str) routine and, before returning, arrange to have itself rescheduled (see qenable(D3str)) at some later time (see bufcall(D3str) and timeout(D3)).

Service routines can be interrupted by put routines, unless the processor interrupt level is raised.

put routines can interrupt and run concurrently with service routines.

Only one copy of a queue's service routine will run at a time.

Drivers and modules should not call service routines directly. Use the qenable(D3str) function to schedule service routines to run.

Drivers (other than multiplexors) should free any messages they do not recognize.

Modules should pass on any messages they do not recognize.

Drivers should fail any unrecognized M_IOCTL messages by converting them into M_IOCNAK messages and sending them upstream.

Modules should pass on any unrecognized M_IOCTL messages.

Service routines should never put high priority messages back on their queues.

Context and synchronization

Interrupt context

Hardware applicability

All

Version applicability

ddi: 1, 2, 3, 4, 5, 5mp, 6, 6mp, 7, 7mp, 7.1, 7.1mp, 8, 8mp

oddi: 1, 2, 2mp, 3, 3mp, 4, 4mp, 5, 5mp

References

bcanput(D3str), bcanputnext(D3str), bufcall(D3str), canput(D3str), canputnext(D3str), datab(D4str), getq(D3str), itimeout(D3), msgb(D4str), pcmsg(D3str), put(D2str), putbq(D3str), putnext(D3str), putq(D3str), qenable(D3str), qinit(D4str), queue(D4str), timeout(D3oddi)
19 June 2005
© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 6 and UnixWare (SVR5) HDK - June 2005