'\"macro stdmacro
.if n .pH ddi_dki.qreply @(#)qreply	40.7 of 10/10/89
.\" Copyright 1989 AT&T
.de IX
.ie '\\n(.z'' .tm .Index: \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9	\\n%
.el \\!.IX \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
..
.nr X
.if \nX=0 .ds x} qreply D3DK "STREAMS" "DDI/DKI" "\&"
.if \nX=1 .ds x} qreply D3DK "STREAMS" "DDI/DKI"
.if \nX=2 .ds x} qreply D3DK "" "\&"
.if \nX=3 .ds x} qreply "" "" "\&"
.TH \*(x}
.IX "\f4qreply\fP(D3DK)"
.SH NAME
\f4qreply\f1 \- send a message on a stream in the reverse direction
.SH SYNOPSIS
.nf
.na
\f4#include <sys/stream.h>
.sp 0.5
void qreply(queue_t *\f2q\f4, mblk_t *\f2bp\f4);\f1
.ad
.fi
.SH ARGUMENTS
.RS 0n 10
.IP "\f2q\f1" 10n
Pointer to the queue.
.IP "\f2bp\f1" 10n
Pointer to the message to be sent in the opposite direction.
.RE
.SH DESCRIPTION
\f4qreply\f1 sends a message on a stream in the opposite direction
from \f2q\f1.
It calls the \f4OTHERQ\f1(D3DK)
function to find \f2q\f1's module partner, and passes the message
by calling the \f4put\f1(D2DK)
routine of the next queue in the stream after \f2q\f1's partner.
.SH RETURN VALUE
None
.SH LEVEL
Base or Interrupt
.SH SEE ALSO
\f2BCI Driver Development Guide\f1, Chapter 7, ``STREAMS''
.P
\f2STREAMS Programmer's Guide\f1
.P
.na
\f4OTHERQ\f1(D3DK),
\f4putnext\f1(D3DK)
.ad
.SH EXAMPLE
.IX "\f4msgb\fP(D4DK), example"
.IX "\f4flushq\fP(D3DK), example"
.IX "\f4queue\fP(D4DK), example"
.IX "\f4RD\fP(D3DK), example"
This example depicts the canonical flushing code for
STREAMS drivers.  The driver has a write \f4srv\f1(D2DK) (service) routine
that may have messages on the queue.
If it receives
an \f4M_FLUSH\f1 message (line 6), and if the \f4FLUSHW\f1 bit 
is on in the
first byte of the message (line 7), then the write queue is flushed (line 8)
and the \f4FLUSHW\f1 bit is turned off (line 9).
If the \f4FLUSHR\f1 bit is on,
then the read queue is flushed (line 12) and the message is sent back
up the read side of the stream with the \f4qreply\f1(D3DK) function (line 13).
If the \f4FLUSHR\f1 bit is off,
then the message is freed (line 15).
See the example for \f4flushq\f1(D3DK)
for the canonical flushing code for modules.
.P
\f4qreply\f1 does two things.  First, 
it calls the \f4OTHERQ\f1 function to
change pointer \f4q\f1 to the module's 
other \f4queue\f1(D4DK) structure,
reversing the direction of the flow.
Then it uses that \f4queue\f1's
\f4q_next\f1 pointer to call 
the next module's \f4put\f1(D2DK) routine with
the \f4M_IOCNAK\f1 message.
.ne 4
.P
.nf
.ft 4
.ps 7
 1  xxxwput(q, mp)
 2      queue_t *q;
 3      mblk_t *mp;
 4  {
 5	switch(mp->b_datap->db_type) {
 6	case M_FLUSH:
 7		if (*mp->b_rptr & FLUSHW) {
 8			flushq(q, FLUSHALL);
 9			*mp->b_rptr &= ~FLUSHW;
10		}
11		if (*mp->b_rptr & FLUSHR) {
12			flushq(RD(q), FLUSHALL);
13			qreply(q, mp);
14		} else {
15			freemsg(mp);
16		}
17		break;
	. . .
18	}
19  }
.ps
.ft 1
.fi
.P
.FG "qreply \- canonical flushing"
