Allows a STREAMS message to bypass a STREAMS module if the module is not interested in the message.
int wantmsg(q, f)
queue_t * q;
int (*f)();
The wantmsg utility allows a STREAMS message to bypass a STREAMS module if the module is not interested in the message, resulting in performance improvements.
The module registers filter functions with the read and write queues of the module with the wantmsg utility. A filter function takes as input a message pointer and returns 1 if the respective queue is interested in receiving the message. Otherwise it returns 0. The putnext and qreply subroutines call a queue's filter function before putting a message on that queue. If the filter function returns 1, then putnext or qreply put the message on that queue. Otherwise, putnext or qreply bypass the module by putting the message on the next module's queue.
The filter functions must be defined so that a message bypasses a module only when the module does not need to see the message.
The wantmsg utility cannot be used if the module has a service routine associated with the queue specified by the q parameter. If wantmsg is called for a module that has a service routine associated with q, wantmsg returns a value of 0 without registering the filter function with q.
This utility is part of STREAMS Kernel Extensions.
Item | Description |
---|---|
q | Specifies the read or write queue to which the filter function is to be registered. |
f | Specifies the module's filter function that is called at the putnext or qreply time. |
Upon successful completion, the wantmsg utility returns a 1, indicating that the filter function specified by the f parameter has been registered for the queue specified by the q parameter. In this case, the filter function is called from putnext or qreply. The wantmsg utility returns a value of 0 if the module has a service routine associated with the queue q, indicating that the filter function is not registered with q.
wantmsg(q, tioc_is_r_interesting);
wantmsg(WR(q), tioc_is_w_interesting);
/*
* read queue filter function.
* queue is only interested in IOCNAK, IOCACK, and
* CTL messages.
*/
static int
tioc_is_r_interesting(mblk_t *mp)
{
if (mp->b_datap->db_type == M_DATA)
/* fast path for data messages */
return 0;
else if (mp->b_datap->db_type == M_IOCNAK ||
mp->b_datap->db_type == M_IOCACK ||
mp->b_datap->db_type == M_CTL)
return 1;
else
return 0;
}
/*
* write queue filter function.
* queue is only interested in IOCTL and IOCDATA
* messages.
*/
static int
tioc_is_w_interesting(mblk_t *mp)
{
if (mp->b_datap->db_type == M_DATA)
/* fast path for data messages */
return 0;
else if (mp->b_datap->db_type == M_IOCTL ||
mp->b_datap->db_type == M_IOCDATA)
return 1;
else
return 0;
}