2 .\" Copyright 1989 AT&T
3 .\" Copyright (C) 2002, Sun Microsystems, Inc.
4 .\" All Rights Reserved
5 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
7 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
8 .TH DUPB 9F "Mar 22, 2002"
10 dupb \- duplicate a message block descriptor
14 #include <sys/stream.h>
18 \fBmblk_t *\fR\fBdupb\fR(\fBmblk_t *\fR\fIbp\fR);
24 Architecture independent level 1 (DDI/DKI).
28 \fBdupb()\fR creates a new \fBmblk_t\fR structure (see \fBmsgb\fR(9S)) to
29 reference the message block pointed to by \fIbp\fR.
32 Unlike \fBcopyb\fR(9F), \fBdupb()\fR does not copy the information in the
33 \fBdblk_t\fR structure (see \fBdatab\fR(9S)), but creates a new \fBmblk_t\fR
34 structure to point to it. The reference count in the \fBdblk_t\fR structure
35 (\fBdb_ref\fR) is incremented. The new \fBmblk_t\fR structure contains the
36 same information as the original. Note that \fBb_rptr\fRand \fBb_wptr\fR are
37 copied from the \fIbp\fR.
39 Printed copy or docs.sun.com shows a figure that shows a new mblk_t structure
40 created, with the original and new bp both pointing to the dblk_t structure,
41 and db_ref incremented by one
49 Pointer to the message block to be duplicated. \fBmblk_t\fR is an instance of
50 the \fBmsgb\fR(9S) structure.
56 If successful, \fBdupb()\fR returns a pointer to the new message block. A
57 \fINULL\fR pointer is returned if \fBdupb()\fR cannot allocate a new message
58 block descriptor or if the \fBdb_ref\fR field of the data block structure (see
59 \fBdatab\fR(9S)) has reached a maximum value (\fB255\fR).
63 \fBdupb()\fR can be called from user, kernel, or interrupt context.
66 \fBExample 1 \fRUsing \fBdupb()\fR
69 This \fBsrv\fR(9E) (service) routine adds a header to all \fBM_DATA\fR
70 messages before passing them along. \fBdupb\fR is used instead of
71 \fBcopyb\fR(9F) because the contents of the header block are not changed.
75 For each message on the queue, if it is a priority message, pass it along
76 immediately (lines 10-11). Otherwise, if it is anything other than an
77 \fBM_DATA\fR message (line 12), and if it can be sent along (line 13), then do
78 so (line 14). Otherwise, put the message back on the queue and return (lines
79 16-17). For all \fBM_DATA\fR messages, first check to see if the stream is
80 flow-controlled (line 20). If it is, put the message back on the queue and
81 return (lines 37-38). If it is not, the header block is duplicated (line 21).
85 \fBdupb()\fR can fail either due to lack of resources or because the message
86 block has already been duplicated 255 times. In order to handle the latter
87 case, the example calls \fBcopyb\fR(9F) (line 22). If \fBcopyb\fR(9F) fails,
88 it is due to buffer allocation failure. In this case, \fBqbufcall\fR(9F) is
89 used to initiate a callback (lines 30-31) if one is not already pending (lines
94 The callback function, \fBxxxcallback()\fR, clears the recorded
95 \fBqbufcall\fR(9F) callback id and schedules the service procedure (lines
96 49-50). Note that the close routine, \fBxxxclose()\fR, must cancel any
97 outstanding \fBqbufcall\fR(9F) callback requests (lines 58-59).
101 If \fBdupb()\fR or \fBcopyb\fR(9F) succeed, link the \fBM_DATA\fR message to
102 the new message block (line 34) and pass it along (line 35).
110 4 struct xx *xx = (struct xx *)q->q_ptr;
113 7 extern mblk_t *hdr;
115 9 while ((mp = getq(q)) != NULL) {
116 10 if (mp->b_datap->db_type >= QPCTL) {
118 12 } else if (mp->b_datap->db_type != M_DATA) {
119 13 if (canputnext(q))
125 19 } else { /* M_DATA */
126 20 if (canputnext(q)) {
127 21 if ((bp = dupb(hdr)) == NULL)
130 24 size_t size = msgdsize(mp);
132 26 if (xx->xx_qbufcall_id) {
133 27 /* qbufcall pending */
136 30 xx->xx_qbufcall_id = qbufcall(q, size,
137 31 BPRI_MED, xxxcallback, (intptr_t)q);
153 47 struct xx *xx = (struct xx *)q->q_ptr;
155 49 xx->xx_qbufcall_id = 0;
159 52 xxxclose(q, cflag, crp)
164 57 struct xx *xx = (struct xx *)q->q_ptr;
166 58 if (xx->xx_qbufcall_id)
167 59 qunbufcall(q, xx->xx_qbufcall_id);
176 \fBsrv\fR(9E), \fBcopyb\fR(9F), \fBqbufcall\fR(9F), \fBdatab\fR(9S),
180 \fIWriting Device Drivers\fR \fISTREAMS Programming Guide\fR