Merge commit '9276b3991ba20d5a5660887ba81b0bc7bed25a0c'
[unleashed.git] / share / man / man9f / copyb.9f
blob591aa8a4776fb3e3d9d92cab49ac21eab3174bcf
1 '\" te
2 .\"  Copyright 1989 AT&T  Copyright (c) 2006, Sun Microsystems, Inc.
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH COPYB 9F "Jan 16, 2006"
7 .SH NAME
8 copyb \- copy a message block
9 .SH SYNOPSIS
10 .LP
11 .nf
12 #include <sys/stream.h>
16 \fBmblk_t *\fR\fBcopyb\fR(\fBmblk_t *\fR\fIbp\fR);
17 .fi
19 .SH INTERFACE LEVEL
20 .sp
21 .LP
22 Architecture independent level 1 (DDI/DKI).
23 .SH PARAMETERS
24 .sp
25 .ne 2
26 .na
27 \fB\fIbp\fR\fR
28 .ad
29 .RS 6n
30 Pointer to the message block from which data is copied.
31 .RE
33 .SH DESCRIPTION
34 .sp
35 .LP
36 The \fBcopyb()\fR function allocates a new message block, and copies into it
37 the data from the block that \fIbp\fR denotes. The new block will be at least
38 as large as the block being copied. \fBcopyb()\fR uses the \fBb_rptr\fR and
39 \fBb_wptr\fR members of \fIbp\fR to determine how many bytes to copy.
40 .SH RETURN VALUES
41 .sp
42 .LP
43 If successful, \fBcopyb()\fR returns a pointer to the newly allocated message
44 block containing the copied data. Otherwise, it returns a \fINULL\fR pointer.
45 .SH CONTEXT
46 .sp
47 .LP
48 The \fBcopyb()\fR function can be called from user, interrupt, or kernel
49 context.
50 .SH EXAMPLES
51 .LP
52 \fBExample 1 \fRUsing copyb
53 .sp
54 .LP
55 For each message in the list, test to see if the downstream queue is full with
56 the \fBcanputnext\fR(9F) function (line 21). If it is not full, use \fBcopyb\fR
57 to copy a header message block, and \fBdupmsg\fR(9F) to duplicate the data to
58 be retransmitted. If either operation fails, reschedule a timeout at the next
59 valid interval.
61 .sp
62 .LP
63 Update the new header block with the correct destination address (line 34),
64 link the message to it (line 35), and send it downstream (line 36). At the end
65 of the list, reschedule this routine.
67 .sp
68 .in +2
69 .nf
70  1  struct retrans {
71  2        mblk_t             *r_mp;
72  3        int                r_address;
73  4        queue_t            *r_outq;
74  5        struct retrans     *r_next;
75  6  };
76  7
77  8  struct protoheader {
78        \&.\|.\|.
79  9     int                    h_address;
80        \&.\|.\|.
81 10  };
83 12  mblk_t *header;
85 14  void
86 15  retransmit(struct retrans *ret)
87 16  {
88 17       mblk_t *bp, *mp;
89 18       struct protoheader *php;
91 20       while (ret) {
92 21         if (!canputnext(ret->r_outq)) {   /* no room */
93 22                ret = ret->r_next;
94 23                continue;
95 24         }
96 25         bp = copyb(header);               /* copy header msg. block */
97 26         if (bp == NULL)
98 27               break;
99 28         mp = dupmsg(ret->r_mp);           /* duplicate data */
100 29         if (mp == NULL) {                 /* if unsuccessful */
101 30              freeb(bp);                   /* free the block */
102 31              break;
103 32         }
104 33         php = (struct protoheader *)bp->b_rptr;
105 34         php->h_address = ret->r_address;   /* new header */
106 35         bp->bp_cont = mp;                  /* link the message */
107 36         putnext(ret->r_outq, bp);          /* send downstream */
108 37         ret = ret->r_next;
109 38       }
110 39       /* reschedule */
111 40       (void) timeout(retransmit, (caddr_t)ret, RETRANS_TIME);
112 41  }
114 .in -2
116 .SH SEE ALSO
119 \fBallocb\fR(9F), \fBcanputnext\fR(9F), \fBdupmsg\fR(9F)
122 \fIWriting Device Drivers\fR
125 \fISTREAMS Programming Guide\fR