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

insq(D3str)


insq -- 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);

Description

insq 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(D3str).

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.

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(D2str). 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.

Context

Base or Interrupt.

Synchronization constraints

Does not block.

Driver-defined basic locks, read/write locks, and sleep locks may be held across calls to this function.

In DDI drivers, the caller must have the stream frozen (see freezestr(D3str)) when calling this function.

Singlethreaded 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 the queue, looking for M_PROTO messages (line 9). When one is found, we remove it from the queue using rmvq(D3str) (line 10). If there is no data portion to the message (line 11), we free the entire message using freemsg(D3str). Otherwise, for every M_PROTO message block in the message, we strip the M_PROTO block off using unlinkb(D3str) (line 15) and free the message block using freeb(D3str). 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 }

Multithreaded 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. First, we freeze the stream (line 7) so the state of the queue does not change while we are searching it. Then we traverse the list of messages on the queue, looking for M_PROTO messages (line 11). When one is found, we remove it from the queue using rmvq(D3str) (line 12). If there is no data portion of the message (line 13), we free the entire message using freemsg(D3str). Otherwise, for every M_PROTO message block in the message, we strip the M_PROTO block off using unlinkb(D3str) (line 17) and free the message block using freeb(D3str). When the header has been stripped, the data portion of the message is inserted back into the queue where it was originally found (line 21). Finally, when we are done searching the queue, we unfreeze the stream (line 26).
    1  void
    2  striproto(q)
    3	queue_t *q;
    4  {
    5	mblk_t *emp, *nmp, *mp;
    6	pl_t pl;

7 pl = freezestr(q); 8 strqget(q, QFIRST, 0, &mp); 9 while (mp) { 10 emp = mp->b_next; 11 if (mp->b_datap->db_type == M_PROTO) { 12 rmvq(q, mp); 13 if (msgdsize(mp) == 0) { 14 freemsg(mp); 15 } else { 16 while (mp->b_datap->db_type == M_PROTO) { 17 nmp = unlinkb(mp); 18 freeb(mp); 19 mp = nmp; 20 } 21 insq(q, emp, mp); 22 } 23 } 24 mp = emp; 25 } 26 unfreezestr(q, pl); 27 }

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, 6, 6mp

References

freezestr(D3str), getq(D3str), putbq(D3str), putq(D3str), rmvq(D3str), srv(D2str) unfreezestr(D3str),
19 June 2005
© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 6 and UnixWare (SVR5) HDK - June 2005