insq(D3)insq(D3)NAMEinsq - insert a message into a queue
SYNOPSIS
#include <sys/stream.h>
#include <sys/ddi.h>
int insq(queue_t *q, mblk_t *emp, mblk_t *nmp);
Arguments
q Pointer to the queue containing message emp.
emp Pointer to the existing message before which the new message is
to be inserted.
nmp Pointer to the new message to be inserted.
DESCRIPTIONinsq inserts a message into a queue. The message to be inserted, nmp, is
placed in the queue pointed to by q, immediately before the message, emp.
If emp is NULL, the new message is placed at the end of the queue. All
flow control parameters are updated. The service procedure is scheduled
to run unless disabled by a previous call to noenable(D3).
Return Values
If nmp was successfully enqueued, insq returns 1. Otherwise, insq
returns 0.
USAGE
Messages are ordered in the queue based on their priority, as described
in srv(D2). If an attempt is made to insert a message out of order in
the queue, then nmp is not enqueued.
The insertion can fail if there is not enough memory to allocate the
accounting data structures used with messages whose priority bands are
greater than zero.
If emp is non-NULL, it must point to a message in the queue pointed to by
q, or a system panic could result.
Level
Base or Interrupt.
Synchronization Constraints
Does not sleep.
Driver-defined basic locks, read/write locks, and sleep locks may be held
across calls to this function.
Example
This routine illustrates the use of insq to insert a message into the
middle of a queue. This routine can be used to strip all the M_PROTO
headers off all messages on a queue. We traverse the list of messages on
Page 1
insq(D3)insq(D3)
the queue, looking for M_PROTO messages (line 9). When one is found, we
remove it from the queue using rmvq(D3) (line 10). If there is no data
portion to the message (line 11), we free the entire message using
freemsg(D3). Otherwise, for every M_PROTO message block in the message,
we strip the M_PROTO block off using unlinkb(D3) (line 15) and free the
message block using freeb(D3). When the header has been stripped, the
data portion of the message is inserted back into the queue where it was
originally found (line 19).
1 void
2 striproto(q)
3 queue_t *q;
4 {
5 mblk_t *emp, *nmp, *mp;
6 mp = q->q_first;
7 while (mp) {
8 emp = mp->b_next;
9 if (mp->b_datap->db_type == M_PROTO) {
10 rmvq(q, mp);
11 if (msgdsize(mp) == 0) {
12 freemsg(mp);
13 } else {
14 while (mp->b_datap->db_type == M_PROTO) {
15 nmp = unlinkb(mp);
16 freeb(mp);
17 mp = nmp;
18 }
19 insq(q, emp, mp);
20 }
21 }
22 mp = emp;
23 }
24 }
REFERENCESgetq(D3), putbq(D3), putq(D3), rmvq(D3), srv(D2)
Page 2