Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

copyb(9F)

msgb(9S)

dupb(9F)

NAME

dupb − duplicate a message block descriptor

SYNOPSIS

#include <sys/stream.h>
mblk_t ∗dupb(mblk_t ∗bp);

ARGUMENTS

bp Pointer to the message block to be duplicated.  mblk_t is an instance of the msgb(9S) structure. 

INTERFACE LEVEL

Architecture independent level 1 (DDI/DKI). 

DESCRIPTION

dupb() creates a new mblk_t structure to reference the message block pointed to by bp. Unlike copyb(9F), dupb does not copy the information in the data block, but creates a new structure to point to it. 

The following figure shows how the db_ref field of the dblk_t structure has been changed from 1 to 2, reflecting the increase in the number of references to the data block.  The new mblk_t contains the same information as the first.  Note that b_rptr and b_wptr are copied from bp, and that db_ref is incremented. 

scale=100
define m0 |
[ box invis ht 24 wid 1 with .sw at 0,0
line -> from 0,0 to 0,24
] |
 define m1 |
[ box invis ht 62 wid 56 with .sw at 0,0
line  from 0,42 to 56,42 dotted
line  from 0,22 to 56,22 dotted
box ht 62 wid 56 with .nw at 0,62
] |
 define m2 |
[ box invis ht 62 wid 86 with .sw at 0,0
box ht 62 wid 86 with .nw at 0,62
] |
 define m3 |
[ box invis ht 62 wid 64 with .sw at 0,0
box ht 62 wid 64 with .nw at 0,62
"b_datap" at 28,47
"" at 8,43 ljust
"" at 8,33 ljust
"b_rptr" at 26,21
"b_wptr" at 26,9
] |
 box invis ht 242 wid 442 with .sw at 0,0
line  from 64,154 to 120,154
line -> from 120,154 to 120,178
line -> from 136,204 to 136,122
line  from 64,116 to 68,116
line  from 68,116 to 68,82
line -> from 68,82 to 94,82
line  from 64,126 to 80,126
line  from 80,126 to 80,102
line -> from 80,102 to 94,102
m1 with .nw at 296,98
m1 with .nw at 94,122
m0 with .nw at 306,178
line -> from 326,206 to 326,98
line  from 292,154 to 306,154
"nbp=dupb(bp);" at 150,-7 ljust
line  from 180,242 to 180,16
line  from 180,16 to 440,16
line  from 180,16 to 0,16
"Before" at 78,23
"After" at 326,23
"db_base" at 312,211
"db_ref (2)" at 320,227
m2 with .nw at 280,240
box ht 62 wid 86 with .nw at 82,240
"db_base" at 114,211
"db_ref (1)" at 122,227
"bp" at 228,181 ljust
"" at 236,137 ljust
"" at 236,147 ljust
m3 with .nw at 364,168
m3 with .nw at 228,168
m3 with .nw at 0,168
line -> from 208,58 to 296,58
line  from 208,126 to 208,58
"nbp" at 416,181
line  from 228,126 to 208,126
line -> from 216,78 to 296,78
line  from 216,118 to 216,78
line  from 228,118 to 216,118
line  from 428,118 to 434,118
line -> from 442,58 to 354,58
line  from 442,126 to 442,58
line  from 428,126 to 442,126
line -> from 434,78 to 354,78
line  from 434,118 to 434,78
"" at 374,137 ljust
"" at 374,147 ljust
line -> from 346,154 to 346,178
line  from 364,154 to 346,154
"bp" at 0,181 ljust

RETURN VALUES

If successful, dupb returns a pointer to the new message block.  Otherwise, it returns a NULL pointer. 

CONTEXT

dupb() can be called from user or interrupt context. 

EXAMPLE

This srv(9E) (service) routine adds a header to all M_DATA messages before passing them along.  The message block for the header was allocated elsewhere.  For each message on the queue, if it is a priority message, pass it along immediately (lines 9−10).  Otherwise, if it is anything other than an M_DATA message (line 11), and if it can be sent along (line 12), then do so (line 13).  Otherwise, put the message back on the queue and return (lines 15−16).  For all M_DATA messages, first check to see if the stream is flow-controlled (line 19).  If it is, put the message back on the queue and return (line 22); if it is not, the header block is duplicated (line 20).  If dupb fails, the service routine is rescheduled in one tenth of a second with timeout and then we return (lines 23−24).  If dupb succeeds, link the M_DATA message to it (line 26) and pass it along (line 27).  dupb can be used here instead of copyb(9F) because the contents of the header block are not changed. 

Note that this example ignores issues related to cancelling outstanding timeouts at close time. 

 1  xxxsrv(q)
 2      queue_t ∗q;
 3  {
 4mblk_t ∗mp;
 5 mblk_t ∗bp;
 6extern mblk_t ∗hdr;
 7
 8while ((mp = getq(q)) != NULL) {
 9if (mp->b_datap->db_type >= QPCTL) {
10putnext(q, mp);
11} else if (mp->b_datap->db_type != M_DATA) {
12if (canputnext(q))
13putnext(q, mp);
14else {
15putbq(q, mp);
16return;
17}
18} else {/∗ M_DATA ∗/
19if (canputnext(q)) {
20bp = dupb(hdr);
21if (bp == NULL) {
22putbq(q, mp);
23timeout(qenable, (long)q, drv_usectohz(100000));
24return;
25}
26linkb(bp, mp);
27putnext(q, bp);
28} else {
29putbq(q, mp);
30return;
31}
32}
33}
34  }

SEE ALSO

copyb(9F), msgb(9S)

SunOS 5.3 Writing Device Drivers
SunOS 5.3 STREAMS Programmer’s Guide

Sun Microsystems  —  Last change: 11 Apr 1991

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026